Skip to content
Prev Previous commit
Next Next commit
Use version_compare directly
The built in wp functions for this are too new (Added in 5.2)
  • Loading branch information
mrsdizzie committed Dec 6, 2024
commit e522b030ad17f25fcb9f86e21df50e504cb1723b
5 changes: 3 additions & 2 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ public function path( $args, $assoc_args ) {
}

protected function install_from_repo( $slug, $assoc_args ) {
global $wp_version;
$api = plugins_api( 'plugin_information', array( 'slug' => $slug ) );

if ( is_wp_error( $api ) ) {
Expand All @@ -594,8 +595,8 @@ protected function install_from_repo( $slug, $assoc_args ) {
$requires_php = isset( $api->requires_php ) ? $api->requires_php : null;
$requires_wp = isset( $api->requires ) ? $api->requires : null;

$compatible_php = is_php_version_compatible( $requires_php );
$compatible_wp = is_wp_version_compatible( $requires_wp );
$compatible_php = empty( $requires_php ) || version_compare( PHP_VERSION, $requires_php, '>=' );
$compatible_wp = empty( $requires_wp ) || version_compare( $wp_version, $requires_wp, '>=' );

if ( ! $compatible_wp ) {
return new WP_Error( 'requirements_not_met', "This plugin does not work with your version of WordPress. Minimum WordPress requirement is $requires_wp" );
Expand Down
5 changes: 3 additions & 2 deletions src/Theme_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ public function path( $args, $assoc_args ) {
}

protected function install_from_repo( $slug, $assoc_args ) {
global $wp_version;
$api = themes_api( 'theme_information', array( 'slug' => $slug ) );

if ( is_wp_error( $api ) ) {
Expand All @@ -407,8 +408,8 @@ protected function install_from_repo( $slug, $assoc_args ) {
$requires_php = isset( $api->requires_php ) ? $api->requires_php : null;
$requires_wp = isset( $api->requires ) ? $api->requires : null;

$compatible_php = is_php_version_compatible( $requires_php );
$compatible_wp = is_wp_version_compatible( $requires_wp );
$compatible_php = empty( $requires_php ) || version_compare( PHP_VERSION, $requires_php, '>=' );
$compatible_wp = empty( $requires_wp ) || version_compare( $wp_version, $requires_wp, '>=' );

if ( ! $compatible_wp ) {
return new WP_Error( 'requirements_not_met', "This theme does not work with your version of WordPress. Minimum WordPress requirement is $requires_wp" );
Expand Down
Loading