Wordpress get_option on multisite

If you have a plugin and you want to get its global option (ie that are stored into wp_options table, if you are into a blog, get_option retrieve value from wp_$blogid_options)  on multisite installation, you have two solution:


  1. find and replace all get_option into plugin with my_get_option defined in this manner: 
function my_get_option($key) {
if(is_multisite()) {
switch_to_blog(SITE_ID_CURRENT_SITE);
$option = get_option($key);
restore_current_blog();
return $option;
} else {
return get_option($key);
        }
           }

      2. add filters for each option you want to retrieve:

function myoption() {
        if(is_multisite()) {
switch_to_blog(SITE_ID_CURRENT_SITE);
$option = get_option($key);
restore_current_blog();
return $option;
} else {
return get_option($key);
        }
add_filter( 'pre_option_' . $key, 'myoption' );

       

Commenti