WPSEO_Admin_Bar_Menu::add_root_menu
Adds the admin bar root menu.
Метод класса: WPSEO_Admin_Bar_Menu{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->add_root_menu( $wp_admin_bar );
- $wp_admin_bar(WP_Admin_Bar) (обязательный)
- Admin bar instance to add the menu to.
Код WPSEO_Admin_Bar_Menu::add_root_menu() WPSEO Admin Bar Menu::add root menu Yoast 28.3
protected function add_root_menu( WP_Admin_Bar $wp_admin_bar ) {
$title = $this->get_title();
$score = '';
$settings_url = '';
$counter = '';
$notification_popup = '';
$notification_count = 0;
$post = $this->get_singular_post();
if ( $post ) {
$score = $this->get_post_score( $post );
}
$term = $this->get_singular_term();
if ( $term ) {
$score = $this->get_term_score( $term );
}
$can_manage_options = $this->can_manage_options();
if ( $can_manage_options ) {
$settings_url = $this->get_settings_page_url();
}
if ( empty( $score ) && ! is_network_admin() && $can_manage_options ) {
$notification_center = Yoast_Notification_Center::get();
$notification_count = $notification_center->get_notification_count();
$counter = $this->get_notification_counter( $notification_count );
$notification_popup = $this->get_notification_popup();
}
$admin_bar_menu_args = [
'id' => self::MENU_IDENTIFIER,
'title' => $title . $score . $counter . $notification_popup,
'href' => $settings_url,
'meta' => [ 'tabindex' => ! empty( $settings_url ) ? false : '0' ],
];
$wp_admin_bar->add_menu( $admin_bar_menu_args );
if ( $notification_count > 0 ) {
$admin_bar_menu_args = [
'parent' => self::MENU_IDENTIFIER,
'id' => 'wpseo-notifications',
'title' => __( 'Notifications', 'wordpress-seo' ) . $counter,
'href' => empty( $settings_url ) ? '' : $settings_url . '#/alert-center',
'meta' => [ 'tabindex' => ! empty( $settings_url ) ? false : '0' ],
];
$wp_admin_bar->add_menu( $admin_bar_menu_args );
}
}