muh
Forum Replies Created
-
Forum: Plugins
In reply to: [xili-language] SQL Error after custom pre_get_posts hookSorry for the delay. Let put my 2nd issue aside and go back to the first.
I wrote a little update to handle post type that aren’t authorized so they will be displayed on the page. Otherwise only authorized types with the correct language are displayed.
$notAuthorizedTypes = array(); if ( empty( $query_object->query_vars['post_type'] ) ) { // string or array $insertWhere = true; } else if ( is_string($query_object->query_vars['post_type']) && in_array ( $query_object->query_vars['post_type'], array_keys ( $this->authorized_custom_post_type () ) ) ){ $insertWhere = true; } else if (is_array($query_object->query_vars['post_type'])){ $insertWhere = true; $authorized = $this->authorized_custom_post_type(); foreach($query_object->query_vars['post_type'] as $postType){ if (!isset($authorized[$postType]) || $authorized[$postType]['multilingual'] != 'enable'){ $notAuthorizedTypes[] = $postType; } } } else { $insertWhere = false; } if ( $insertWhere ){ $query_object->query_vars[QUETAG] = $curlang; // in query.php posts_join filter is called after posts_where filter - for home page without lang_quetag $need_join = true; $wherereqtag = $this->langs_ids_array[$curlang]; $where .= ' AND ('; $where .= "(xtt.taxonomy = '" . TAXONAME . "' "; //" $where .= " AND xtt.term_id = $wherereqtag )"; if (count($notAuthorizedTypes)){ $where .= ' OR '; $where .= 'post_type IN (\''.implode('\', \'', $notAuthorizedTypes).'\')'; } $where .= ')'; }Edit: Besides you couldn’t deauthorize post types. Once they were authorized they always were. The same problem occures if the post_type index is a string:
} else if ( is_string($query_object->query_vars['post_type']) && in_array ( $query_object->query_vars['post_type'], array_keys ( $this->authorized_custom_post_type () ) ) ){You’re just checking if the authorized array contains the post_type but you aren’t checking if it’s enabled or not. I think you can fix this yourself. π
– Simon
Forum: Plugins
In reply to: [xili-language] SQL Error after custom pre_get_posts hookI think that will be the problem. My plugin translations are not located in the local-xx_YY file but in the wp-content/languages/plugins/pluginname-xx_YY.mo files.
I’m sorry but I can’t contact you from the support tab. What infos do you need?
Forum: Plugins
In reply to: [xili-language] SQL Error after custom pre_get_posts hookI just solved my next issue with the translation of the page. You’re plugin works as intended, but.. π
I don’t know if I broke it or if xili-language just don’t support the translation of plugins. That’s why I created a little extension as a separate plugin for xili-language.
I’m not very experienced in the internal l10n functions of wp, so I hope you don’t blame me if I did something wrong.
Maybe you want to merge it to xili-language or release it as a separate plugin or so. I won’t do anything with the code as long as it works. You may change the copyright, I don’t really care. So do as you please, even if you ignore it. I just wanted to share this with you:
class xili_language_plugins { protected $oldlang; protected $curlang; public function __construct( ) { if (is_admin()) return; $this->domains = array(); add_action('init', array($this,'loaded')); add_filter('load_textdomain_mofile', array($this,'load_textdomain'),10,2); } public function loaded(){ if (!isset($GLOBALS['xili_language'])) return; $this->xili_lang = $GLOBALS['xili_language']; $this->curlang = get_locale(); add_filter('locale', array($this,'locale')); } public function load_textdomain($moFile, $domain){ $this->domains[$domain] = $moFile; return $moFile; } protected function replace_text_domains(){ foreach ($this->domains as $domain => $moFile){ unload_textdomain($domain); load_textdomain($domain, str_replace($this->oldlang, $this->correct_case($this->curlang),$moFile)); } } protected function correct_case($lang){ list($lang,$country) = explode('_',$lang); return strtolower($lang).'_'.strtoupper($country); } public function locale($current){ if (!isset($this->xili_lang)) return $current; if ($this->xili_lang->curlang != $this->curlang){ $this->oldlang = $this->curlang; $this->curlang = $this->xili_lang->curlang; $this->replace_text_domains(); } return $current; } } /* **************** end of xili-language-plugin class ******************* */ /****************** instantiation Class *****************/ /** * instantiation of xili_language_plugins class */ function xili_language_plugins_start () { global $xili_language_plugin; $xili_language_plugin = new xili_language_plugins( false , false ); } xili_language_plugins_start();and yes, I copied a bit of your code. And sorry for using the name prefix ‘xili’.
Forum: Plugins
In reply to: [xili-language] SQL Error after custom pre_get_posts hookThanks for the update. I just installed it. Seems to work fine.
Forum: Plugins
In reply to: [xili-language] SQL Error after custom pre_get_posts hookYou’re welcome. Thanks for your fast and good feedback.
I’m looking forward for the new version.
Thanks
SimonForum: Plugins
In reply to: [xili-language] SQL Error after custom pre_get_posts hookI also modified the posts_where_lang-Function because of the same problem. xlil-language.php:~1564 (the 2.9.2 section):
$insertWhere = false; if ($query_object->query_vars['post_type'] == ''){ $insertWhere = true; }else if (is_string($query_object->query_vars['post_type']) && in_array ( $query_object->query_vars['post_type'], array_keys ($this->authorized_custom_post_type () ) )){ $insertWhere = true; }else if (is_array($query_object->query_vars['post_type']) && !count(array_diff($query_object->query_vars['post_type'],array_keys($this->authorized_custom_post_type())))){ $insertWhere = true; } if ($insertWhere){ $query_object->query_vars['lang'] = $curlang; $wherereqtag = $this->langs_ids_array[$curlang]; $where .= " AND xtt.taxonomy = '" . TAXONAME . "' "; //" $where .= " AND xtt.term_id = $wherereqtag "; }Forum: Plugins
In reply to: [xili-language] SQL Error after custom pre_get_posts hookOk, you were right. To modify $this->sublang wasn’t that good as I thought.
But now im sure I’ve found the bug.
xili-language.php:1274
if ( is_admin () || in_array ( $query_object->query_vars['post_type'], array_keys ($this->authorized_custom_post_type () ) ) ) $insert_join = true;You’re assuming that query_vars[‘post_type’] is just a string. But in my case it’s an array of strings.
Possible solution:
if (is_admin()){ $insert_join = true; }else if (is_string($query_object->query_vars['post_type']) && in_array ( $query_object->query_vars['post_type'], array_keys ($this->authorized_custom_post_type () ) )){ $insert_join = true; }else if (is_array($query_object->query_vars['post_type']) && !count(array_diff($query_object->query_vars['post_type'],array_keys($this->authorized_custom_post_type())))){ $insert_join = true; }But careful: This will only work if all selected custom post types are authorized. As soon as one of them isn’t authorized there will be the same SQL Error.
Maybe you want to filter the post types or modify the query to select all of the non authorized posts and only the subset of the authorized.
Forum: Plugins
In reply to: [xili-language] SQL Error after custom pre_get_posts hookBecause I want to display more than just ‘posts’ on my index page. I’ve added multiple different post types that have to be shown.