woocommerce_conditional = $woocommerce_conditional;
$this->shortlinker = $shortlinker;
$this->product_helper = $product_helper;
$this->current_page_helper = $current_page_helper;
$this->promotion_manager = $promotion_manager;
$this->addon_manager = $addon_manager;
}
/**
* Initializes the integration.
*
* This is the place to register hooks and filters.
*
* @return void
*/
public function register_hooks() {
// Add page with PHP_INT_MAX - 1 to allow other items (like Brand Insights) to be positioned after.
\add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ], ( \PHP_INT_MAX - 1 ) );
\add_filter( 'wpseo_network_submenu_pages', [ $this, 'add_page' ], ( \PHP_INT_MAX - 1 ) );
\add_action( 'admin_init', [ $this, 'do_redirect' ], 1 );
}
/**
* Adds the page to the (currently) last position in the array.
*
* @param array>> $pages The pages.
*
* @return array>> The pages.
*/
public function add_page( $pages ) {
// Don't show the Upgrade button if Yoast SEO WooCommerce addon is active.
if ( $this->addon_manager->is_installed( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) ) {
return $pages;
}
// Don't show the Upgrade button if Premium is active without the WooCommerce plugin.
if ( $this->product_helper->is_premium() && ! $this->woocommerce_conditional->is_met() ) {
return $pages;
}
$button_content = \__( 'Upgrade', 'wordpress-seo' );
if ( $this->promotion_manager->is( 'black-friday-promotion' ) ) {
$button_content = ( $this->product_helper->is_premium() ) ? \__( 'Get 30% off', 'wordpress-seo' ) : \__( '30% off - BF Sale', 'wordpress-seo' );
}
$pages[] = [
General_Page_Integration::PAGE,
'',
'' . $button_content . ' ',
'edit_posts',
self::PAGE,
static function () {
echo 'redirecting...';
},
];
return $pages;
}
/**
* Redirects to the yoast.com.
*
* @return void
*/
public function do_redirect(): void {
if ( $this->current_page_helper->get_current_yoast_seo_page() !== self::PAGE ) {
return;
}
$link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-premium' );
if ( $this->woocommerce_conditional->is_met() ) {
$link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-woocommerce' );
}
\wp_redirect( $link );//phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Safe redirect is used here.
exit();
}
}