: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Creates an instance of Yoast_Notification.
* @param string $product_name The product to create the notification for.
* @param string $short_link The short link for the addon notification.
* @return Yoast_Notification The created notification.
protected function create_notification( $product_name, $short_link ) {
$notification_options = [
'type' => Yoast_Notification::ERROR,
'id' => 'wpseo-dismiss-' . sanitize_title_with_dashes( $product_name, null, 'save' ),
'capabilities' => 'wpseo_manage_options',
return new Yoast_Notification(
/* translators: %1$s expands to a strong tag, %2$s expands to the product name, %3$s expands to a closing strong tag, %4$s expands to an a tag. %5$s expands to MyYoast, %6$s expands to a closing a tag, %7$s expands to the product name */
__( '%1$s %2$s isn\'t working as expected %3$s and you are not receiving updates or support! Make sure to %4$s activate your product subscription in %5$s%6$s to unlock all the features of %7$s.', 'wordpress-seo' ),
'<a href="' . WPSEO_Shortlinker::get( $short_link ) . '" target="_blank">',
* Checks whether a plugin expiry date has been passed.
* @param stdClass $subscription Plugin subscription.
* @return bool Has the plugin expired.
protected function has_subscription_expired( $subscription ) {
return ( strtotime( $subscription->expiry_date ) - time() ) < 0;
* Converts a subscription to plugin based format.
* @param stdClass $subscription The subscription to convert.
* @param stdClass|null $yoast_free_data The Yoast Free's data.
* @param bool $plugin_info Whether we're in the plugin information modal.
* @param string $plugin_file The plugin filename.
* @return stdClass The converted subscription.
protected function convert_subscription_to_plugin( $subscription, $yoast_free_data = null, $plugin_info = false, $plugin_file = '' ) {
if ( isset( $subscription->product->changelog ) ) {
// We need to replace h2's and h3's with h4's because the styling expects that.
$changelog = str_replace( '</h2', '</h4', str_replace( '<h2', '<h4', $subscription->product->changelog ) );
$changelog = str_replace( '</h3', '</h4', str_replace( '<h3', '<h4', $changelog ) );
// If we're running this because we want to just show the plugin info in the version details modal, we can fallback to the Yoast Free constants, since that modal will not be accessible anyway in the event that the new Free version increases those constants.
// It can be expanded if we have the 'tested' and 'requires_php' data be returned from wp.org in the future.
'requires' => ( $plugin_info ) ? YOAST_SEO_WP_REQUIRED : null,
'new_version' => ( $subscription->product->version ?? '' ),
'name' => $subscription->product->name,
'slug' => $subscription->product->slug,
'plugin' => $plugin_file,
'url' => $subscription->product->store_url,
'last_update' => $subscription->product->last_updated,
'homepage' => $subscription->product->store_url,
'download_link' => $subscription->product->download,
'package' => $subscription->product->download,
'changelog' => $changelog,
'support' => $this->get_support_section(),
'2x' => $this->get_icon( $subscription->product->slug ),
'update_supported' => true,
'banners' => $this->get_banners( $subscription->product->slug ),
// If we have extracted Yoast Free's data before, use that. If not, resort to the defaults.
'tested' => YOAST_SEO_WP_TESTED,
'requires' => ( $yoast_free_data->requires ?? $defaults['requires'] ),
'requires_php' => YOAST_SEO_PHP_REQUIRED,
* Returns the plugin's icon URL.
* @param string $slug The plugin slug.
* @return string The icon URL for this plugin.
protected function get_icon( $slug ) {
return 'https://yoa.st/local-seo-icon';
return 'https://yoa.st/news-seo-icon';
return 'https://yoa.st/yoast-seo-icon';
return 'https://yoa.st/video-seo-icon';
case self::WOOCOMMERCE_SLUG:
return 'https://yoa.st/woo-seo-icon';
* Return an array of plugin banner URLs.
* @param string $slug The plugin slug.
protected function get_banners( $slug ) {
'high' => 'https://yoa.st/yoast-seo-banner-local',
'low' => 'https://yoa.st/yoast-seo-banner-low-local',
'high' => 'https://yoa.st/yoast-seo-banner-news',
'low' => 'https://yoa.st/yoast-seo-banner-low-news',
'high' => 'https://yoa.st/yoast-seo-banner-premium',
'low' => 'https://yoa.st/yoast-seo-banner-low-premium',
'high' => 'https://yoa.st/yoast-seo-banner-video',
'low' => 'https://yoa.st/yoast-seo-banner-low-video',
case self::WOOCOMMERCE_SLUG:
'high' => 'https://yoa.st/yoast-seo-banner-woo',
'low' => 'https://yoa.st/yoast-seo-banner-low-woo',
* Checks if the given plugin_file belongs to a Yoast addon.
* @param string $plugin_file Path to the plugin.
* @return bool True when plugin file is for a Yoast addon.
protected function is_yoast_addon( $plugin_file ) {
return $this->get_slug_by_plugin_file( $plugin_file ) !== '';
* Retrieves the addon slug by given plugin file path.
* @param string $plugin_file The file path to the plugin.
* @return string The slug when found or empty string when not.
protected function get_slug_by_plugin_file( $plugin_file ) {
// Yoast SEO Free isn't an addon, but we needed it in Premium to fetch translations.
if ( YoastSEO()->helpers->product->is_premium() ) {
$addons['wp-seo.php'] = self::FREE_SLUG;
foreach ( $addons as $addon => $addon_slug ) {
if ( strpos( $plugin_file, $addon ) !== false ) {
* Retrieves the installed Yoast addons.
* @return array The installed plugins.
protected function get_installed_addons() {
return array_filter( $this->get_plugins(), [ $this, 'is_yoast_addon' ], ARRAY_FILTER_USE_KEY );
* Retrieves a list of active addons.
* @return array The active addons.
protected function get_active_addons() {
return array_filter( $this->get_installed_addons(), [ $this, 'is_plugin_active' ], ARRAY_FILTER_USE_KEY );
* Retrieves the current sites from the API.
* @return bool|stdClass Object when request is successful. False if not.
protected function request_current_sites() {
$api_request = new WPSEO_MyYoast_Api_Request( 'sites/current' );
if ( $api_request->fire() ) {
return $api_request->get_response();
return $this->get_site_information_default();
* Retrieves the transient value with the site information.
* @return stdClass|false The transient value.
protected function get_site_information_transient() {
// Force re-check on license & dashboard pages.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['page'] ) && is_string( $_GET['page'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only strictly comparing and thus no need to sanitize.
$current_page = wp_unslash( $_GET['page'] );
// Check whether the licenses are valid or whether we need to show notifications.
$quick = ( $current_page === 'wpseo_licenses' || $current_page === 'wpseo_dashboard' );
// Also do a fresh request on Plugins & Core Update pages.
$quick = $quick || $pagenow === 'plugins.php';
$quick = $quick || $pagenow === 'update-core.php';
return get_transient( self::SITE_INFORMATION_TRANSIENT_QUICK );
return get_transient( self::SITE_INFORMATION_TRANSIENT );
* Sets the site information transient.
* @param stdClass $site_information The site information to save.
protected function set_site_information_transient( $site_information ) {
set_transient( self::SITE_INFORMATION_TRANSIENT, $site_information, DAY_IN_SECONDS );
set_transient( self::SITE_INFORMATION_TRANSIENT_QUICK, $site_information, 60 );
* Retrieves all installed WordPress plugins.
* @return array The plugins.
protected function get_plugins() {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
* Checks if the given plugin file belongs to an active plugin.
* @param string $plugin_file The file path to the plugin.
* @return bool True when plugin is active.
protected function is_plugin_active( $plugin_file ) {
return is_plugin_active( $plugin_file );
* Returns an object with no subscriptions.
* @return stdClass Site information.
protected function get_site_information_default() {
'url' => WPSEO_Utils::get_home_url(),
* Maps the plugin API response.
* @param object $site_information Site information as received from the API.
* @return stdClass Mapped site information.
protected function map_site_information( $site_information ) {
'url' => $site_information->url,
'subscriptions' => array_map( [ $this, 'map_subscription' ], $site_information->subscriptions ),
* Maps a plugin subscription.
* @param object $subscription Subscription information as received from the API.
* @return stdClass Mapped subscription.
protected function map_subscription( $subscription ) {
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Not our properties.
'renewal_url' => $subscription->renewalUrl,
'expiry_date' => $subscription->expiryDate,
'version' => $subscription->product->version,
'name' => $subscription->product->name,
'slug' => $subscription->product->slug,
'last_updated' => $subscription->product->lastUpdated,
'store_url' => $subscription->product->storeUrl,
// Ternary operator is necessary because download can be undefined.
'download' => ( $subscription->product->download ?? null ),
'changelog' => $subscription->product->changelog,
* Retrieves the site information.
* @return stdClass The site information.
private function get_site_information() {
if ( ! $this->has_installed_addons() ) {
return $this->get_site_information_default();
return $this->get_myyoast_site_information();
* Retrieves the contents for the support section.
* @return string The support section content.
protected function get_support_section() {
return '<h4>' . __( 'Need support?', 'wordpress-seo' ) . '</h4>'
/* translators: 1: expands to <a> that refers to the help page, 2: </a> closing tag. */
. sprintf( __( 'You can probably find an answer to your question in our %1$shelp center%2$s.', 'wordpress-seo' ), '<a href="https://yoast.com/help/">', '</a>' )
/* translators: %s expands to a mailto support link. */
. sprintf( __( 'If you still need support and have an active subscription for this product, please email %s.', 'wordpress-seo' ), '<a href="mailto:support@yoast.com">support@yoast.com</a>' )