Inpsyde\MultilingualPress\Module\AlternativeLanguageTitleInAdminBar\AlternativeLanguageTitles::get PHP Метод

get() публичный Метод

Returns the alternative language title for the site with the given ID.
С версии: 3.0.0
public get ( integer $site_id ) : string
$site_id integer Optional. Site ID. Defaults to 0.
Результат string The alternative language title for the site with the given ID.
    public function get($site_id = 0)
    {
        if (!$site_id) {
            $site_id = get_current_blog_id();
        }
        $titles = wp_cache_get($this->cache_key, $this->cache_group);
        if (!is_array($titles)) {
            $titles = [];
        } elseif (isset($titles[$site_id])) {
            return $titles[$site_id];
        }
        // TODO: Don't hardcode the option name.
        $languages = get_site_option('inpsyde_multilingual');
        // TODO: Maybe also don't hardcode the 'text' key...?
        if (!isset($languages[$site_id]['text'])) {
            return '';
        }
        $title = $languages[$site_id]['text'];
        $titles[$site_id] = $title;
        wp_cache_set($this->cache_key, $titles, $this->cache_group);
        return $title;
    }

Usage Example

 /**
  * Replaces all site names with the individual site's alternative language title, if not empty.
  *
  * @since   3.0.0
  * @wp-hook admin_bar_menu
  *
  * @param WP_Admin_Bar $wp_admin_bar The WordPress admin bar object.
  *
  * @return WP_Admin_Bar The manipulated WordPress admin bar object.
  */
 public function replace_site_nodes(WP_Admin_Bar $wp_admin_bar)
 {
     if (empty($wp_admin_bar->user->blogs)) {
         return $wp_admin_bar;
     }
     foreach ((array) $wp_admin_bar->user->blogs as $site) {
         if (empty($site->userblog_id)) {
             continue;
         }
         $title = $this->titles->get($site->userblog_id);
         if (!$title) {
             continue;
         }
         $wp_admin_bar->user->blogs[$site->userblog_id]->blogname = $title;
     }
     return $wp_admin_bar;
 }
AlternativeLanguageTitles