Check min. WP and PHP versions before suggesting plugins (#37694)
* Add min_php_version for google and pinterest extensions * Hide extensions that do not meet the min php version requirement. * Add min_wp_version * Add changelog * Revert code style * Compare PHP and WP version only when is_visible is already true * Fix style - use yoda
This commit is contained in:
parent
697a05a9e9
commit
b5b3e37ea9
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: update
|
||||||
|
|
||||||
|
Support min_php_version and min_wp_version for the free extensions feed
|
|
@ -79,6 +79,7 @@ class DefaultFreeExtensions {
|
||||||
public static function get_plugin( $slug ) {
|
public static function get_plugin( $slug ) {
|
||||||
$plugins = array(
|
$plugins = array(
|
||||||
'google-listings-and-ads' => [
|
'google-listings-and-ads' => [
|
||||||
|
'min_php_version' => '7.4',
|
||||||
'name' => __( 'Google Listings & Ads', 'woocommerce' ),
|
'name' => __( 'Google Listings & Ads', 'woocommerce' ),
|
||||||
'description' => sprintf(
|
'description' => sprintf(
|
||||||
/* translators: 1: opening product link tag. 2: closing link tag */
|
/* translators: 1: opening product link tag. 2: closing link tag */
|
||||||
|
@ -130,6 +131,7 @@ class DefaultFreeExtensions {
|
||||||
'image_url' => plugins_url( '/assets/images/onboarding/pinterest.png', WC_PLUGIN_FILE ),
|
'image_url' => plugins_url( '/assets/images/onboarding/pinterest.png', WC_PLUGIN_FILE ),
|
||||||
'manage_url' => 'admin.php?page=wc-admin&path=%2Fpinterest%2Flanding',
|
'manage_url' => 'admin.php?page=wc-admin&path=%2Fpinterest%2Flanding',
|
||||||
'is_built_by_wc' => true,
|
'is_built_by_wc' => true,
|
||||||
|
'min_php_version' => '7.3',
|
||||||
],
|
],
|
||||||
'pinterest-for-woocommerce:alt' => [
|
'pinterest-for-woocommerce:alt' => [
|
||||||
'name' => __( 'Pinterest for WooCommerce', 'woocommerce' ),
|
'name' => __( 'Pinterest for WooCommerce', 'woocommerce' ),
|
||||||
|
@ -349,6 +351,7 @@ class DefaultFreeExtensions {
|
||||||
DefaultPaymentGateways::get_rules_for_cbd( false ),
|
DefaultPaymentGateways::get_rules_for_cbd( false ),
|
||||||
],
|
],
|
||||||
'is_built_by_wc' => true,
|
'is_built_by_wc' => true,
|
||||||
|
'min_wp_version' => '5.9',
|
||||||
],
|
],
|
||||||
'woocommerce-services:shipping' => [
|
'woocommerce-services:shipping' => [
|
||||||
'description' => sprintf(
|
'description' => sprintf(
|
||||||
|
@ -516,6 +519,7 @@ class DefaultFreeExtensions {
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'is_built_by_wc' => false,
|
'is_built_by_wc' => false,
|
||||||
|
'min_wp_version' => '6.0',
|
||||||
],
|
],
|
||||||
'mailpoet' => [
|
'mailpoet' => [
|
||||||
'name' => __( 'MailPoet', 'woocommerce' ),
|
'name' => __( 'MailPoet', 'woocommerce' ),
|
||||||
|
|
|
@ -21,6 +21,7 @@ class EvaluateExtension {
|
||||||
* @return object The evaluated extension.
|
* @return object The evaluated extension.
|
||||||
*/
|
*/
|
||||||
public static function evaluate( $extension ) {
|
public static function evaluate( $extension ) {
|
||||||
|
global $wp_version;
|
||||||
$rule_evaluator = new RuleEvaluator();
|
$rule_evaluator = new RuleEvaluator();
|
||||||
|
|
||||||
if ( isset( $extension->is_visible ) ) {
|
if ( isset( $extension->is_visible ) ) {
|
||||||
|
@ -30,6 +31,17 @@ class EvaluateExtension {
|
||||||
$extension->is_visible = true;
|
$extension->is_visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run PHP and WP version chcecks.
|
||||||
|
if ( true === $extension->is_visible ) {
|
||||||
|
if ( isset( $extension->min_php_version ) && ! version_compare( PHP_VERSION, $extension->min_php_version, '>=' ) ) {
|
||||||
|
$extension->is_visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isset( $extension->min_wp_version ) && ! version_compare( $wp_version, $extension->min_wp_version, '>=' ) ) {
|
||||||
|
$extension->is_visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$installed_plugins = PluginsHelper::get_installed_plugin_slugs();
|
$installed_plugins = PluginsHelper::get_installed_plugin_slugs();
|
||||||
$activated_plugins = PluginsHelper::get_active_plugin_slugs();
|
$activated_plugins = PluginsHelper::get_active_plugin_slugs();
|
||||||
$extension->is_installed = in_array( explode( ':', $extension->key )[0], $installed_plugins, true );
|
$extension->is_installed = in_array( explode( ':', $extension->key )[0], $installed_plugins, true );
|
||||||
|
|
Loading…
Reference in New Issue