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:
Moon 2023-04-13 19:24:20 -07:00 committed by GitHub
parent 697a05a9e9
commit b5b3e37ea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 11 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
Support min_php_version and min_wp_version for the free extensions feed

View File

@ -79,17 +79,18 @@ class DefaultFreeExtensions {
public static function get_plugin( $slug ) {
$plugins = array(
'google-listings-and-ads' => [
'name' => __( 'Google Listings & Ads', 'woocommerce' ),
'description' => sprintf(
'min_php_version' => '7.4',
'name' => __( 'Google Listings & Ads', 'woocommerce' ),
'description' => sprintf(
/* translators: 1: opening product link tag. 2: closing link tag */
__( 'Drive sales with %1$sGoogle Listings and Ads%2$s', 'woocommerce' ),
'<a href="https://woocommerce.com/products/google-listings-and-ads" target="_blank">',
'</a>'
),
'image_url' => plugins_url( '/assets/images/onboarding/google.svg', WC_PLUGIN_FILE ),
'manage_url' => 'admin.php?page=wc-admin&path=%2Fgoogle%2Fstart',
'is_built_by_wc' => true,
'is_visible' => [
'image_url' => plugins_url( '/assets/images/onboarding/google.svg', WC_PLUGIN_FILE ),
'manage_url' => 'admin.php?page=wc-admin&path=%2Fgoogle%2Fstart',
'is_built_by_wc' => true,
'is_visible' => [
[
'type' => 'not',
'operand' => [
@ -125,11 +126,12 @@ class DefaultFreeExtensions {
'is_built_by_wc' => false,
],
'pinterest-for-woocommerce' => [
'name' => __( 'Pinterest for WooCommerce', 'woocommerce' ),
'description' => __( 'Get your products in front of Pinners searching for ideas and things to buy.', 'woocommerce' ),
'image_url' => plugins_url( '/assets/images/onboarding/pinterest.png', WC_PLUGIN_FILE ),
'manage_url' => 'admin.php?page=wc-admin&path=%2Fpinterest%2Flanding',
'is_built_by_wc' => true,
'name' => __( 'Pinterest for WooCommerce', 'woocommerce' ),
'description' => __( 'Get your products in front of Pinners searching for ideas and things to buy.', 'woocommerce' ),
'image_url' => plugins_url( '/assets/images/onboarding/pinterest.png', WC_PLUGIN_FILE ),
'manage_url' => 'admin.php?page=wc-admin&path=%2Fpinterest%2Flanding',
'is_built_by_wc' => true,
'min_php_version' => '7.3',
],
'pinterest-for-woocommerce:alt' => [
'name' => __( 'Pinterest for WooCommerce', 'woocommerce' ),
@ -349,6 +351,7 @@ class DefaultFreeExtensions {
DefaultPaymentGateways::get_rules_for_cbd( false ),
],
'is_built_by_wc' => true,
'min_wp_version' => '5.9',
],
'woocommerce-services:shipping' => [
'description' => sprintf(
@ -516,6 +519,7 @@ class DefaultFreeExtensions {
],
],
'is_built_by_wc' => false,
'min_wp_version' => '6.0',
],
'mailpoet' => [
'name' => __( 'MailPoet', 'woocommerce' ),

View File

@ -21,6 +21,7 @@ class EvaluateExtension {
* @return object The evaluated extension.
*/
public static function evaluate( $extension ) {
global $wp_version;
$rule_evaluator = new RuleEvaluator();
if ( isset( $extension->is_visible ) ) {
@ -30,6 +31,17 @@ class EvaluateExtension {
$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();
$activated_plugins = PluginsHelper::get_active_plugin_slugs();
$extension->is_installed = in_array( explode( ':', $extension->key )[0], $installed_plugins, true );