options_helper = $options_helper;
$this->admin_asset_manager = $admin_asset_manager;
}
/**
* {@inheritDoc}
*/
public function register_hooks() {
\add_action( 'admin_notices', [ $this, 'premium_deactivated_notice' ] );
\add_action( 'wp_ajax_dismiss_premium_deactivated_notice', [ $this, 'dismiss_premium_deactivated_notice' ] );
}
/**
* Shows a notice if premium is installed but not activated.
*
* @return void
*/
public function premium_deactivated_notice() {
global $pagenow;
if ( $pagenow === 'update.php' ) {
return;
}
if ( $this->options_helper->get( 'dismiss_premium_deactivated_notice', false ) === true ) {
return;
}
$premium_file = 'wordpress-seo-premium/wp-seo-premium.php';
if ( ! \current_user_can( 'activate_plugin', $premium_file ) ) {
return;
}
if ( $this->premium_is_installed_not_activated( $premium_file ) ) {
$this->admin_asset_manager->enqueue_style( 'monorepo' );
$content = \sprintf(
/* translators: 1: Yoast SEO Premium 2: Link start tag to activate premium, 3: Link closing tag. */
\__( 'You\'ve installed %1$s but it\'s not activated yet. %2$sActivate %1$s now!%3$s', 'wordpress-seo' ),
'Yoast SEO Premium',
'',
''
);
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped above.
echo new Notice_Presenter(
/* translators: 1: Yoast SEO Premium */
\sprintf( \__( 'Activate %1$s!', 'wordpress-seo' ), 'Yoast SEO Premium' ),
$content,
'support-team.svg',
null,
true,
'yoast-premium-deactivated-notice'
);
// phpcs:enable
// Enable permanently dismissing the notice.
echo "";
}
}
/**
* Dismisses the premium deactivated notice.
*
* @return bool
*/
public function dismiss_premium_deactivated_notice() {
return $this->options_helper->set( 'dismiss_premium_deactivated_notice', true );
}
/**
* Returns whether or not premium is installed and not activated.
*
* @param string $premium_file The premium file.
*
* @return bool Whether or not premium is installed and not activated.
*/
protected function premium_is_installed_not_activated( $premium_file ) {
return (
! \defined( 'WPSEO_PREMIUM_FILE' )
&& \file_exists( \WP_PLUGIN_DIR . '/' . $premium_file )
);
}
}