wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

Premium: Remove install/activate nag for Yoast SEO when using both as mu-plugins

Open fiskhandlarn opened this issue 1 year ago • 5 comments

Is your feature request related to a problem? Please describe.

when we run yoast/wordpress-seo and yoast/wordpress-seo-premium as mu-plugins (courtesy of roots/bedrock-autoloader) we still get the nag to activate the base plugin:

Yoast SEO 19.3 must be installed and activated in order to use Yoast SEO Premium.

Describe the solution you'd like

this is a patch for wordpress-seo-premium/src/addon-installer.php i have tried locally, please consider adding it to yoast/wordpress-seo-premium:

--- /public/mu-plugins/wordpress-seo-premium/src/addon-installer.php	Tue Jul 12 10:21:58 2022
+++ /public/mu-plugins/wordpress-seo-premium2/src/addon-installer.php	Tue Jul 19 14:30:18 2022
@@ -133,7 +133,9 @@
 	protected function get_notification_action() {
 		$minimum_version_met = \version_compare( $this->yoast_seo_version, self::MINIMUM_YOAST_SEO_VERSION . '-RC0', '>=' );
 		$network_active      = \is_plugin_active_for_network( \WPSEO_PREMIUM_BASENAME );
-		$yoast_seo_active    = ( $network_active ) ? \is_plugin_active_for_network( $this->yoast_seo_file ) : \is_plugin_active( $this->yoast_seo_file );
+		$yoast_seo_active    =
+            ( false !== strpos( $this->yoast_seo_dir, \WPMU_PLUGIN_DIR ) ) ||
+            ( ( $network_active ) ? \is_plugin_active_for_network( $this->yoast_seo_file ) : \is_plugin_active( $this->yoast_seo_file ) );
 
 		if ( $minimum_version_met && $yoast_seo_active ) {
 			return false;
@@ -300,6 +302,18 @@
 				$this->yoast_seo_dir     = \WP_PLUGIN_DIR . '/' . \dirname( $file );
 			}
 		}
+
+        // Make sure Yoast SEO isn't already installed in the mu-plugins directory.
+        $file = \WPMU_PLUGIN_DIR . DIRECTORY_SEPARATOR . $this->yoast_seo_file;
+        $plugin = @get_plugin_data($file);
+        if (
+            isset( $plugin['TextDomain'] ) && $plugin['TextDomain'] === 'wordpress-seo'
+            && isset( $plugin['Name'] ) && $plugin['Name'] === 'Yoast SEO'
+        ) {
+            // $this->yoast_seo_file is already correct, keep it as it is
+            $this->yoast_seo_version = isset( $plugin['Version'] ) ? $plugin['Version'] : '0';
+            $this->yoast_seo_dir     = \dirname( $file );
+        }
 	}
 
 	/**

Why do you think this feature is something we should consider for the Yoast SEO plugins?

some people like to use mu-plugins to streamline all the requirements without having to manually activate and keep databases in sync.

fiskhandlarn avatar Jul 19 '22 12:07 fiskhandlarn

also: wordpress-seo-premium/src/addon-installer.php already have is_yoast_seo_up_to_date() which checks WPSEO_VERSION and could therefore be used instead of checking against $this->yoast_seo_version (derived from the wordpress-seo/wp-seo.php only if it's in the plugins folder).

fiskhandlarn avatar Sep 23 '22 09:09 fiskhandlarn

+1 for this.

trsteel88 avatar Dec 07 '23 02:12 trsteel88

The other approach here could be that the Wordpress SEO plugin could just have a filter to provide the version to other plugins.

e.g. in the non premium version:

add_filter('wp_seo_current_version', function($version) {
    return '1.1.1';
}, 10, 1);

Then in the premium plugin the version would be checked with:

$value = apply_filters( 'wp_seo_current_version', '0');

If the plugin is installed and active, the version would be returned as '1.1.1'. If it was not installed the $value would be '0'.

This would mean a version would be returned regardless of whether it's a plugin or mu-plugin.

Only caveat here is that another plugin could fake the version by returning a value from this filter (but why would they?)

trsteel88 avatar Dec 14 '23 22:12 trsteel88

+1

juhojama avatar Feb 09 '24 16:02 juhojama