Skip to content

Commit

Permalink
Only use major wp version in version_compare
Browse files Browse the repository at this point in the history
Similar to what would happen in is_wp_version_compatible()
  • Loading branch information
mrsdizzie committed Dec 7, 2024
1 parent e522b03 commit c9852ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ public function path( $args, $assoc_args ) {

protected function install_from_repo( $slug, $assoc_args ) {
global $wp_version;
// Extract the major WordPress version (e.g., "6.3") from the full version string
list($wp_core_version) = explode( '-', $wp_version );
$wp_core_version = implode( '.', array_slice( explode( '.', $wp_core_version ), 0, 2 ) );

$api = plugins_api( 'plugin_information', array( 'slug' => $slug ) );

if ( is_wp_error( $api ) ) {
Expand All @@ -596,7 +600,7 @@ protected function install_from_repo( $slug, $assoc_args ) {
$requires_wp = isset( $api->requires ) ? $api->requires : null;

$compatible_php = empty( $requires_php ) || version_compare( PHP_VERSION, $requires_php, '>=' );
$compatible_wp = empty( $requires_wp ) || version_compare( $wp_version, $requires_wp, '>=' );
$compatible_wp = empty( $requires_wp ) || version_compare( $wp_core_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
6 changes: 5 additions & 1 deletion src/Theme_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ public function path( $args, $assoc_args ) {

protected function install_from_repo( $slug, $assoc_args ) {
global $wp_version;
// Extract the major WordPress version (e.g., "6.3") from the full version string
list($wp_core_version) = explode( '-', $wp_version );
$wp_core_version = implode( '.', array_slice( explode( '.', $wp_core_version ), 0, 2 ) );

$api = themes_api( 'theme_information', array( 'slug' => $slug ) );

if ( is_wp_error( $api ) ) {
Expand All @@ -409,7 +413,7 @@ protected function install_from_repo( $slug, $assoc_args ) {
$requires_wp = isset( $api->requires ) ? $api->requires : null;

$compatible_php = empty( $requires_php ) || version_compare( PHP_VERSION, $requires_php, '>=' );
$compatible_wp = empty( $requires_wp ) || version_compare( $wp_version, $requires_wp, '>=' );
$compatible_wp = empty( $requires_wp ) || version_compare( $wp_core_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

0 comments on commit c9852ac

Please sign in to comment.