Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi Tamatoa,
    maybe it’s not so clear from the discussion above, but you need those other plugins only if your menus ara different (=they contain different items) by language.

    Hi Corparit,
    You could use this plugin:
    https://www.ads-software.com/plugins/menu-items-visibility-control/

    as well as
    https://www.ads-software.com/plugins/widget-logic/

    to easily change what’s displayed in menus and sidebars depending on the current language.
    Just tested, they work well with WPGlobus.

    In the “condition” field, you can use something like:
    get_locale() == ‘en_US’
    to display a menu item only in the english version;
    !(get_locale() == ‘en_US’)
    to display a menu item only if the language IS NOT english.

    Or
    (in_array ( get_locale(), array(‘en_US’, ‘fr_FR’, ‘it_IT’))
    for conditions on multiple languages (not tested, but it should work)

    Even better: instead of get_blog_list() use the suggested new function – wp_get_sites().

    See here

    And here

    Same here.

    I made a quick and dirty patch, here it is (works for me).
    Edit the file /wp-content/plugins/wpmubar/wpmubar.php, look for the function wp_list_sites (around line 85 in version 1.1 pro) and replace it with the following:

    function wp_list_sites($expires = 7200)
    	{
    
    		if (!is_multisite()) return false;
    		// Because the get_blog_list() function is currently flagged as deprecated
    		// due to the potential for high consumption of resources, we'll use
    		// $wpdb to roll out our own SQL query instead. Because the query can be
    		// memory-intensive, we'll store the results using the Transients API
    		if (false === ($site_list = get_transient('multisite_site_list'))) {
    			global $wpdb;
    			$site_list =  get_blog_list(); //$wpdb->get_results($wpdb->prepare('SELECT * FROM wp_blogs ORDER BY blog_id'));
    
    			// Set the Transient cache to expire every two hours
    			set_site_transient('multisite_site_list', $site_list, $expires);
    		}
    
    		$current_site_url = get_site_url(get_current_blog_id());
    		foreach ($site_list as $site) {
    			switch_to_blog($site['blog_id']);
    			$class = (home_url() == $current_site_url) ? ' class="current-site-item"' : '';
    			$html[] = array("blog_id" => $site['blog_id'], "domain" => home_url(), "path" => "");
    			restore_current_blog();
    		}
    
    		return $html;
    	}

    I just used the deprecated get_blog_list() function
    (WARNING: it is very resource intensive if you have a lot of sites), for some reason the plain query through $wpdb is returning an empty set.

    Then replace the occurrences of $site->blog_id with $site[‘blog_id’], as it is an array now (not an object)

    Caveat: as I said, it is a quick and dirty hack to make it work. Should be considered a temporary solution, being based on a deprecated function – a potential bottleneck for your multisite.

Viewing 4 replies - 1 through 4 (of 4 total)