WPSEO_Admin_Bar_Menu::add_menu
Adds the admin bar menu.
Метод класса: WPSEO_Admin_Bar_Menu{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
$WPSEO_Admin_Bar_Menu = new WPSEO_Admin_Bar_Menu(); $WPSEO_Admin_Bar_Menu->add_menu( $wp_admin_bar );
- $wp_admin_bar(WP_Admin_Bar) (обязательный)
- Admin bar instance to add the menu to.
Код WPSEO_Admin_Bar_Menu::add_menu() WPSEO Admin Bar Menu::add menu Yoast 27.6
public function add_menu( WP_Admin_Bar $wp_admin_bar ) {
// On block editor pages, the admin bar only shows on mobile, where having this menu icon is not very helpful.
if ( is_admin() ) {
$screen = get_current_screen();
if ( isset( $screen ) && $screen->is_block_editor() ) {
return;
}
}
// If the current user can't write posts, this is all of no use, so let's not output an admin menu.
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}
$this->add_root_menu( $wp_admin_bar );
/**
* Adds a submenu item in the top of the adminbar.
*
* @param WP_Admin_Bar $wp_admin_bar Admin bar instance to add the menu to.
* @param string $menu_identifier The menu identifier.
*/
do_action( 'wpseo_add_adminbar_submenu', $wp_admin_bar, self::MENU_IDENTIFIER );
if ( ! is_admin() ) {
if ( is_singular() || is_tag() || is_tax() || is_category() ) {
$is_seo_enabled = $this->get_is_seo_enabled();
$is_readability_enabled = $this->get_is_readability_enabled();
$indexable = $this->get_current_indexable();
if ( $is_seo_enabled ) {
$focus_keyword = ( ! is_a( $indexable, 'Yoast\WP\SEO\Models\Indexable' ) || $indexable->primary_focus_keyword === null ) ? __( 'not set', 'wordpress-seo' ) : $indexable->primary_focus_keyword;
$wp_admin_bar->add_menu(
[
'parent' => self::MENU_IDENTIFIER,
'id' => 'wpseo-seo-focus-keyword',
'title' => __( 'Focus keyphrase: ', 'wordpress-seo' ) . '<span class="wpseo-focus-keyword">' . $focus_keyword . '</span>',
'meta' => [ 'tabindex' => '0' ],
],
);
$wp_admin_bar->add_menu(
[
'parent' => self::MENU_IDENTIFIER,
'id' => 'wpseo-seo-score',
'title' => __( 'SEO score', 'wordpress-seo' ) . ': ' . $this->score_icon_helper->for_seo( $indexable, 'adminbar-sub-menu-score' )
->present(),
'meta' => [ 'tabindex' => '0' ],
],
);
}
if ( $is_readability_enabled ) {
$wp_admin_bar->add_menu(
[
'parent' => self::MENU_IDENTIFIER,
'id' => 'wpseo-readability-score',
'title' => __( 'Readability', 'wordpress-seo' ) . ': ' . $this->score_icon_helper->for_readability( $indexable->readability_score, 'adminbar-sub-menu-score' )
->present(),
'meta' => [ 'tabindex' => '0' ],
],
);
}
if ( ! $this->product_helper->is_premium() ) {
$wp_admin_bar->add_menu(
[
'parent' => self::MENU_IDENTIFIER,
'id' => 'wpseo-frontend-inspector',
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-frontend-inspector' ),
'title' => __( 'Front-end SEO inspector', 'wordpress-seo' ) . new Premium_Badge_Presenter( 'wpseo-frontend-inspector-badge' ),
'meta' => [
'tabindex' => '0',
'target' => '_blank',
],
],
);
}
}
$this->add_analysis_submenu( $wp_admin_bar );
$this->add_seo_tools_submenu( $wp_admin_bar );
$this->add_how_to_submenu( $wp_admin_bar );
$this->add_get_help_submenu( $wp_admin_bar );
}
if ( ! is_admin() || is_blog_admin() ) {
$this->add_settings_submenu( $wp_admin_bar );
}
elseif ( is_network_admin() ) {
$this->add_network_settings_submenu( $wp_admin_bar );
}
$this->add_premium_link( $wp_admin_bar );
$this->add_brand_insights_link( $wp_admin_bar );
}