Here is the step to reproduce the bug :
- Install qtranslate
- Setup the language you want
- Create a new post
- Put content in the main language (or other), and leave other language empty
BUG : On the website, no message like : Sorry, this entry is only available in... will appear even if you put nothing in the content field for the current language.
WHY ?
You probably noticed that wordpress (or qtranslate) added an empty p tag in content when saving the post, even if you put nothing.
The thing is that qtranslate do not make the difference between full words (real) characters and html tags since tags are made of characters.
FIX
We need to make qtranslate skip html tags when checking for translated version of a post. Here is how :
In qtranslate_core.php (near line 685) in qtrans_split function, change :
$result[$lang] = preg_replace("#(<!--more-->|!--nextpage-->)+$#ism","",$lang_content);
For
$old = preg_replace('/(<[^>]*>|\s+)/','',$lang_content);
if($old == '') {
$lang_content = $old;
}
$result[$lang] = preg_replace("#(<!--more-->|<!--nextpage-->)+$#ism","",$lang_content);
In fact, preg_replace strip all html tags (and white spaces) from the content. Then we check if any characters (word) left. If not, make content equal to nothing.
If you want to filter empty content directly on saving (publishing) :
In qtranslate_wphacks.php, add this function
function qtrans_save($content){
$old = preg_replace('/<[^>]*>/','',$content);
if(empty($old)){
return '';
}
return $content;
}
Then, in qtranslate_hooks.php, add this filter
add_filter('content_save_pre','qtrans_save');
Enjoy