| @@ -4,8 +4,10 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package WPSEO\Suggested_Plugins |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | +use Yoast\WP\SEO\Conditionals\Conditional; | |
| 9 | + | |
| 8 | 10 | /** |
| 9 | 11 | * Class WPSEO_Suggested_Plugins |
| 10 | 12 | */ |
| 11 | 13 | class WPSEO_Suggested_Plugins implements WPSEO_WordPress_Integration { |
| @@ -56,21 +58,24 @@ | ||
| 56 | 58 | // Get all Yoast plugins that have dependencies. |
| 57 | 59 | $plugins = $checker->get_plugins_with_dependencies(); |
| 58 | 60 | |
| 59 | 61 | foreach ( $plugins as $plugin_name => $plugin ) { |
| 62 | + $notification_id = 'wpseo-suggested-plugin-' . $plugin_name; | |
| 63 | + | |
| 60 | 64 | if ( ! $checker->dependencies_are_satisfied( $plugin ) ) { |
| 65 | + $this->notification_center->remove_notification_by_id( $notification_id ); | |
| 66 | + | |
| 61 | 67 | continue; |
| 62 | 68 | } |
| 63 | 69 | |
| 64 | - $notification = $this->get_yoast_seo_suggested_plugins_notification( $plugin_name, $plugin ); | |
| 65 | - | |
| 66 | - if ( ! $checker->is_installed( $plugin ) || ! $checker->is_active( $plugin['slug'] ) ) { | |
| 70 | + if ( ! $checker->is_installed( $plugin ) ) { | |
| 71 | + $notification = $this->get_yoast_seo_suggested_plugins_notification( $notification_id, $plugin ); | |
| 67 | 72 | $this->notification_center->add_notification( $notification ); |
| 68 | 73 | |
| 69 | 74 | continue; |
| 70 | 75 | } |
| 71 | 76 | |
| 72 | - $this->notification_center->remove_notification( $notification ); | |
| 77 | + $this->notification_center->remove_notification_by_id( $notification_id ); | |
| 73 | 78 | } |
| 74 | 79 | } |
| 75 | 80 | |
| 76 | 81 | /** |
| @@ -75,27 +80,23 @@ | ||
| 75 | 80 | |
| 76 | 81 | /** |
| 77 | 82 | * Build Yoast SEO suggested plugins notification. |
| 78 | 83 | * |
| 79 | - * @param string $name The plugin name to use for the unique ID. | |
| 80 | - * @param array $plugin The plugin to retrieve the data from. | |
| 84 | + * @param string $notification_id The id of the notification to be created. | |
| 85 | + * @param array<string, string|bool|array<string, Conditional>> $plugin The plugin to retrieve the data from. | |
| 81 | 86 | * |
| 82 | 87 | * @return Yoast_Notification The notification containing the suggested plugin. |
| 83 | 88 | */ |
| 84 | - protected function get_yoast_seo_suggested_plugins_notification( $name, $plugin ) { | |
| 89 | + protected function get_yoast_seo_suggested_plugins_notification( $notification_id, $plugin ) { | |
| 85 | 90 | $message = $this->create_install_suggested_plugin_message( $plugin ); |
| 86 | 91 | |
| 87 | - if ( $this->availability_checker->is_installed( $plugin ) && ! $this->availability_checker->is_active( $plugin['slug'] ) ) { | |
| 88 | - $message = $this->create_activate_suggested_plugin_message( $plugin ); | |
| 89 | - } | |
| 90 | - | |
| 91 | 92 | return new Yoast_Notification( |
| 92 | 93 | $message, |
| 93 | 94 | [ |
| 94 | - 'id' => 'wpseo-suggested-plugin-' . $name, | |
| 95 | + 'id' => $notification_id, | |
| 95 | 96 | 'type' => Yoast_Notification::WARNING, |
| 96 | 97 | 'capabilities' => [ 'install_plugins' ], |
| 97 | - ] | |
| 98 | + ], | |
| 98 | 99 | ); |
| 99 | 100 | } |
| 100 | 101 | |
| 101 | 102 | /** |
| @@ -115,9 +116,9 @@ | ||
| 115 | 116 | '<strong>', |
| 116 | 117 | $install_link, |
| 117 | 118 | '</strong>', |
| 118 | 119 | $this->create_more_information_link( $suggested_plugin['url'], $suggested_plugin['title'] ), |
| 119 | - '</a>' | |
| 120 | + '</a>', | |
| 120 | 121 | ); |
| 121 | 122 | } |
| 122 | 123 | |
| 123 | 124 | /** |
| @@ -131,31 +132,9 @@ | ||
| 131 | 132 | protected function create_more_information_link( $url, $name ) { |
| 132 | 133 | return sprintf( |
| 133 | 134 | '<a href="%s" aria-label="%s" target="_blank" rel="noopener noreferrer">', |
| 134 | 135 | $url, |
| 135 | - /* translators: %1$s expands to the dependency name. */ | |
| 136 | - sprintf( __( 'More information about %1$s', 'wordpress-seo' ), $name ) | |
| 137 | - ); | |
| 138 | - } | |
| 139 | - | |
| 140 | - /** | |
| 141 | - * Creates a message to suggest the activation of a particular plugin. | |
| 142 | - * | |
| 143 | - * @param array $suggested_plugin The suggested plugin. | |
| 144 | - * | |
| 145 | - * @return string The activate suggested plugin message. | |
| 146 | - */ | |
| 147 | - protected function create_activate_suggested_plugin_message( $suggested_plugin ) { | |
| 148 | - /* translators: %1$s expands to an opening strong tag, %2$s expands to the dependency name, %3$s expands to a closing strong tag, %4$s expands to and opening anchor tag, %5$s expands to a closing anchor tag. */ | |
| 149 | - $message = __( 'It looks like you\'ve installed our %1$s%2$s addon%3$s. %4$sActivate it now%5$s to unlock more tools and SEO features to make your products stand out in search results.', 'wordpress-seo' ); | |
| 150 | - $activation_url = WPSEO_Admin_Utils::get_activation_url( $suggested_plugin['slug'] ); | |
| 151 | - | |
| 152 | - return sprintf( | |
| 153 | - $message, | |
| 154 | - '<strong>', | |
| 155 | - $suggested_plugin['title'], | |
| 156 | - '</strong>', | |
| 157 | - '<a href="' . $activation_url . '">', | |
| 158 | - '</a>' | |
| 136 | + /* translators: Hidden accessibility text; %1$s expands to the dependency name */ | |
| 137 | + sprintf( __( 'More information about %1$s', 'wordpress-seo' ), $name ), | |
| 159 | 138 | ); |
| 160 | 139 | } |
| 161 | 140 | } |