WPSEO_Admin_Bar_Menu::add_premium_link
Adds the admin bar How To submenu.
Метод класса: WPSEO_Admin_Bar_Menu{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->add_premium_link( $wp_admin_bar );
- $wp_admin_bar(WP_Admin_Bar) (обязательный)
- Admin bar instance to add the menu to.
Код WPSEO_Admin_Bar_Menu::add_premium_link() WPSEO Admin Bar Menu::add premium link Yoast 27.6
protected function add_premium_link( WP_Admin_Bar $wp_admin_bar ) {
// Don't show the Upgrade button if Yoast SEO WooCommerce addon is active.
$addon_manager = new WPSEO_Addon_Manager();
if ( $addon_manager->is_installed( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) ) {
return;
}
$has_woocommerce = ( new Woocommerce_Conditional() )->is_met();
// Don't show the Upgrade button if Premium is active without the WooCommerce plugin.
if ( $this->product_helper->is_premium() && ! $has_woocommerce ) {
return;
}
$link = $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-get-premium' );
if ( $has_woocommerce ) {
$link = $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-get-premium-woocommerce' );
}
$button_label = esc_html__( 'Upgrade', 'wordpress-seo' );
if ( YoastSEO()->classes->get( Promotion_Manager::class )->is( 'black-friday-promotion' ) ) {
$button_label = esc_html__( '30% off - BF Sale', 'wordpress-seo' );
}
$wp_admin_bar->add_menu(
[
'parent' => self::MENU_IDENTIFIER,
'id' => 'wpseo-get-premium',
// Circumvent an issue in the WP admin bar API in order to pass `data` attributes. See https://core.trac.wordpress.org/ticket/38636.
'title' => sprintf(
'<a href="%1$s" target="_blank" data-action="load-nfd-ctb" data-ctb-id="f6a84663-465f-4cb5-8ba5-f7a6d72224b2">%2$s</a>',
esc_url( $link ),
$button_label,
),
'meta' => [
'tabindex' => '0',
],
],
);
}