| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wp-content/plugins/wordpress-seo/src/integrations/admin/ |
Upload File : |
<?php
namespace Yoast\WP\SEO\Integrations\Admin;
use Plugin_Upgrader;
use WP_Error;
use WP_Upgrader;
use Yoast\WP\SEO\Conditionals\Check_Required_Version_Conditional;
use Yoast\WP\SEO\Integrations\Integration_Interface;
/**
* The Check_Required_Version class.
*
* This class checks if the required version of Yoast SEO is installed.
* It also adds the `Requires Yoast SEO` header to the list of headers and updates the comparison table for the plugin overwrite.
*/
class Check_Required_Version implements Integration_Interface {
/**
* Initializes the integration.
*
* @return void
*/
public function register_hooks() {
\add_filter( 'upgrader_source_selection', [ $this, 'check_required_version' ], 10, 3 );
\add_filter( 'install_plugin_overwrite_comparison', [ $this, 'update_comparison_table' ], 10, 3 );
}
/**
* Returns the conditionals based on which this loadable should be active.
*
* @return string[] The conditionals based on which this loadable should be active.
*/
public static function get_conditionals() {
return [ Check_Required_Version_Conditional::class ];
}
/**
* Checks if the required version of Yoast SEO is installed.
*
* The code is partly inspired by Plugin_Upgrader::check_package() in wp-admin/includes/class-plugin-upgrader.php.
*
* @param string $source File source location.
* @param string|null $remote_source Remote file source location.
* @param WP_Upgrader|null $upgrader WP_Upgrader instance.
*
* @return string|WP_Error The source location or a WP_Error object if the required version is not installed.
*/
public function check_required_version( $source, $remote_source = null, $upgrader = null ) {
global $wp_filesystem;
// Bail out early if we are not installing/upgrading a plugin.
if ( ! $upgrader instanceof Plugin_Upgrader ) {
return $source;
}
$info = [];
if ( \is_wp_error( $source ) ) {
return $source;
}
$working_directory = \str_replace( $wp_filesystem->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<string> $current_plugin_data Array with current plugin data.
* @param array<string> $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(
'<tr><td class="name-label">%1$s</td><td>%2$s</td><td>%3$s</td></tr>',
\__( '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( '</tbody>', $new_row . '</tbody>', $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', '>=' );
}
}