Automattic\WooCommerce\Admin
PluginsHelper::get_requirements_error_reason
Compose a reason for an install that failed an unmet PHP or WordPress version requirement.
WordPress reports these with copy written for the zip-upload flow ("the uploaded plugin requires"), so build our own sentence from the versions it actually checked: the package headers it read in Plugin_Upgrader::check_package(), which can differ from the wp.org listing metadata.
Method of the class: PluginsHelper{}
No Hooks.
Returns
string. The reason, or an empty string when the error is not a requirement failure.
Usage
$result = PluginsHelper::get_requirements_error_reason( $error, $plugin_data ): string;
- $error(mixed) (required)
- The WP_Error from the upgrader skin, or any non-error value.
- $plugin_data(mixed) (required)
- The headers of the package that failed, as
Plugin_Upgrader::$new_plugin_dataholds them.
Changelog
| Since 11.2.0 | Introduced. |
PluginsHelper::get_requirements_error_reason() PluginsHelper::get requirements error reason code WC 11.2.1
public static function get_requirements_error_reason( $error, $plugin_data ): string {
if ( ! is_wp_error( $error ) || ! is_array( $plugin_data ) ) {
return '';
}
switch ( $error->get_error_code() ) {
case 'incompatible_php_required_version':
$required_php = self::get_required_version( $plugin_data['RequiresPHP'] ?? null );
if ( '' === $required_php ) {
return '';
}
return self::normalize_reason(
sprintf(
/* translators: 1: PHP version the plugin requires, 2: PHP version this site runs. */
__( 'It requires PHP %1$s or newer, but this site runs PHP %2$s.', 'woocommerce' ),
$required_php,
PHP_VERSION
)
);
case 'incompatible_wp_required_version':
$required_wp = self::get_required_version( $plugin_data['RequiresWP'] ?? null );
if ( '' === $required_wp ) {
return '';
}
return self::normalize_reason(
sprintf(
/* translators: 1: WordPress version the plugin requires, 2: WordPress version this site runs. */
__( 'It requires WordPress %1$s or newer, but this site runs WordPress %2$s.', 'woocommerce' ),
$required_wp,
get_bloginfo( 'version' )
)
);
}
return '';
}