load and init qtranslate before other plugins

Any suggestions on how to improve qTranslate? Post here!

load and init qtranslate before other plugins

Postby tmuikku » Thu May 20, 2010 5:10 pm

Hi,

(Sorry if this is already discussed. I didn't find solution with search)
I noticed qTranslate sets locale too late for other plugins to load text domain / locale correctly.

This is how you get it fixed and I hope Qian Qin makes fix to qtranslate sometime so I don't have to do this everytime updating WP:

The problem is q_config["language"] is set too late (it is set in qtrans_init() function) if qtrans_init is called with action "plugins_loaded".

Fix 1: Comment out add_action('plugins_loaded', 'qtrans_init'); from qtranslate_hooks.php and add qtrans_init(); function call to the end of qtranslate.php file.
Now q_config["language"] is set before add_filter('locale', qtrans_localeForCurrentLanguage',99); gets fired.

But wait a minute, now I can't get to wp-admin since it shows error something like "current_user_can is not defined...". The qtrans_init() function has the line
Code: Select all
// update definitions if neccesary
if(defined('WP_ADMIN') && current_user_can('manage_categories')) qtrans_updateTermLibrary();


This is bad code i think. Why not call the qtrans_updateTermLibrary with some hook for example admin_init?
Fix 1.1:
Comment out above line from qtrans_init function and add new hook to qtranslate_hooks.php
Code: Select all
add_action('admin_init',                'qtrans_updateTermLibrary');

You can add that capability check to qtrans_updateTermLibrary function
Code: Select all
// change this
if(!isset($_POST['action'])) return;
// to
if(!isset($_POST['action']) || !current_user_can('manage_categories')) return;


Whow, too many fixes already but thats not all!

Fix 1 is not enough if WP loads any plugins before qtranslate. So, what you need to do is rearrange WP option "active_plugins" array which is iterated in wp-setting.php to initiate plugins so that qtranslate gets loaded first. Add this short code to your plugin:

Fix 2:
Code: Select all
function init_qtranslate_first() {
   $active_plugins = get_option('active_plugins');
    // Check if qtranslate is active and not first to load     
   $key = array_search('qtranslate/qtranslate.php', $active_plugins);
   if ($key) {
        // Move to the begining of active_plugins array
      $q = $active_plugins[$key];
      unset($active_plugins[$key]);
      array_unshift($active_plugins, $q);
        // Update option
      update_option('active_plugins', $active_plugins);
   }
}
add_action ('your_favorite_hook_that_executes_sometimes', 'init_qtranslate_first');


Now all your other plugins get right mofile from the start!

Hope this helps!
tmuikku
 
Posts: 9
Joined: Thu May 20, 2010 4:42 pm

Re: load and init qtranslate before other plugins

Postby digitaldonkey » Wed Aug 25, 2010 1:34 pm

Are there 2 fixes? Or one two-part fix?
Can you maybe clearify your Post?

Working hard to get a guestbook running.
Didn't work for me.
digitaldonkey
 
Posts: 6
Joined: Mon Feb 22, 2010 12:54 pm

Re: load and init qtranslate before other plugins

Postby Qian Qin » Fri Sep 10, 2010 7:34 am

as i can remember, some plugin was required to load before qT, so I didn't made qT load first as it has been originally. But with priority 10, it is definitely getting loaded a bit late for some other plugins, so i changed the priority to 2. I hope this fixes your issues.
Qian Qin
Site Admin
 
Posts: 964
Joined: Thu Jun 19, 2008 12:14 pm
Location: Germany

Re: load and init qtranslate before other plugins

Postby tmuikku » Wed Sep 29, 2010 12:13 pm

digitaldonkey:
One issue, two part fix.

First part makes qtranslate catch on WP locale, second part makes qtranslate plugin to load before other plugins so that the other plugins get correct gettext files loaded.

Qian Qin:
That makes sense :) Great plugin btw., so thanks!
tmuikku
 
Posts: 9
Joined: Thu May 20, 2010 4:42 pm

Re: load and init qtranslate before other plugins

Postby Rashanea » Thu Feb 09, 2012 11:45 pm

Man sorry I couldn't do it, I didn't find strings I had to search for(or I hadn't?). Can you please explain one more time but as for a non php knowing user? big thanks.
Rashanea
 
Posts: 3
Joined: Sat Jan 28, 2012 6:19 pm


Return to qTranslate Suggestions Forum

Who is online

Users browsing this forum: No registered users and 2 guests