wp_content_dir(), \trailingslashit( \WP_CONTENT_DIR ), $source ); if ( ! \is_dir( $working_directory ) ) { // Confidence check, if the above fails, let's not prevent installation. return $source; } // Check that the folder contains at least 1 valid plugin. $files = \glob( $working_directory . '*.php' ); if ( $files ) { foreach ( $files as $file ) { $info = \get_plugin_data( $file, false, false ); if ( ! empty( $info['Name'] ) ) { break; } } } $requires_yoast_seo = ! empty( $info['Requires Yoast SEO'] ) ? $info['Requires Yoast SEO'] : false; if ( ! $this->check_requirement( $requires_yoast_seo ) ) { $error = \sprintf( /* translators: 1: Current Yoast SEO version, 2: Version required by the uploaded plugin. */ \__( 'The Yoast SEO version on your site is %1$s, however the uploaded plugin requires %2$s.', 'wordpress-seo' ), \WPSEO_VERSION, \esc_html( $requires_yoast_seo ) ); return new WP_Error( 'incompatible_yoast_seo_required_version', \__( 'The package could not be installed because it\'s not supported by the currently installed Yoast SEO version.', 'wordpress-seo' ), $error ); } return $source; } /** * Update the comparison table for the plugin installation when overwriting an existing plugin. * * @param string $table The output table with Name, Version, Author, RequiresWP, and RequiresPHP info. * @param array $current_plugin_data Array with current plugin data. * @param array $new_plugin_data Array with uploaded plugin data. * * @return string The updated comparison table. */ public function update_comparison_table( $table, $current_plugin_data, $new_plugin_data ) { $requires_yoast_seo_current = ! empty( $current_plugin_data['Requires Yoast SEO'] ) ? $current_plugin_data['Requires Yoast SEO'] : false; $requires_yoast_seo_new = ! empty( $new_plugin_data['Requires Yoast SEO'] ) ? $new_plugin_data['Requires Yoast SEO'] : false; if ( $requires_yoast_seo_current !== false || $requires_yoast_seo_new !== false ) { $new_row = \sprintf( '%1$s%2$s%3$s', \__( 'Required Yoast SEO version', 'wordpress-seo' ), ( $requires_yoast_seo_current !== false ) ? \esc_html( $requires_yoast_seo_current ) : '-', ( $requires_yoast_seo_new !== false ) ? \esc_html( $requires_yoast_seo_new ) : '-' ); $table = \str_replace( '', $new_row . '', $table ); } return $table; } /** * Check whether the required Yoast SEO version is installed. * * @param string|bool $required_version The required version. * * @return bool Whether the required version is installed, or no version is required. */ private function check_requirement( $required_version ) { if ( $required_version === false ) { return true; } return \version_compare( \WPSEO_VERSION, $required_version . '-RC0', '>=' ); } }