WordPress.org

Make WordPress Core

Opened 2 months ago

Closed 8 weeks ago

#47835 closed defect (bug) (fixed)

PHP requirement always set to null for plugins

Reported by: diddledan Owned by: SergeyBiryukov
Milestone: 5.2.3 Priority: normal
Severity: minor Version: 5.2
Component: Site Health Keywords: has-patch fixed-major
Focuses: Cc:
PR Number:

Description

The file class-wp-plugins-list-table.php line 764 (https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/class-wp-plugins-list-table.php#L764) references a variable called $plugin. This variable is not defined anywhere in the function so the test will always return false, meaning that $requires_php will always be set to null:

$requires_php   = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;

This line was introduced in version 5.2.0

Attachments (4)

46051.patch (681 bytes) - added by sharaz 2 months ago.
47835.patch (681 bytes) - added by sharaz 2 months ago.
47835.diff (716 bytes) - added by vaishalipanchal 2 months ago.
Patch.
47835.2.diff (912 bytes) - added by SergeyBiryukov 2 months ago.

Download all attachments as: .zip

Change History (15)

#1 @afragen
2 months ago

  • Component changed from Administration to Site Health

I think you’re correct. It should be $plugin_data['requires_php'].

I’ll step through the the code tomorrow and make certain.

Good pick up. Thanks.

#2 @SergeyBiryukov
2 months ago

  • Milestone changed from Awaiting Review to 5.3

@sharaz
2 months ago

#3 @sharaz
2 months ago

  • Keywords has-patch added

@sharaz
2 months ago

#4 @SergeyBiryukov
2 months ago

  • Milestone changed from 5.3 to 5.2.3

@vaishalipanchal
2 months ago

Patch.

#5 @SergeyBiryukov
2 months ago

  • Milestone changed from 5.2.3 to 5.3

This turned out to be not as straightforward as it seems :)

Background:

  • [44937] introduced PHP compatibility check in WP_Plugins_List_Table::single_row()
  • [45185] updated the check to use the new is_php_version_compatible() function.

Initially, I thought the check should be updated to use validate_plugin_requirements() to account for the data both from the plugin's main PHP file and readme.txt:

$compatible_php = ! is_wp_error( validate_plugin_requirements( $plugin_file ) );

However, upon a closer look, the purpose of the PHP compatibility check in this particular place is to disable the checkbox that could be used for bulk updating plugins, as some of the plugin updates might be incompatible.

The problem with this is that $plugin_data refers to the currently installed version of the plugin (which should already by compatible per the changes in #43986 and #43992), not the updated version that might have different requirements.

The information about the update is only available in wp_plugin_update_row(), which has its own PHP compatibility check per [44937].

So, unless I'm missing something, the current PHP compatibility check in WP_Plugins_List_Table::single_row() doesn't work as expected even with the proposed variable correction and should be removed. See 47835.2.diff.

Disabling the checkbox for incompatible updates makes sense, but I don't see a clean way to do that at the moment.

Last edited 2 months ago by SergeyBiryukov (previous) (diff)

#6 @SergeyBiryukov
2 months ago

The problem with this is that $plugin_data refers to the currently installed version of the plugin

Nevermind, I missed that $plugin_data is merged with the plugin API response earlier.

$plugin_data['RequiresPHP'] does indeed refer to the header from the currently installed plugin version, however $plugin_data['requires_php'] refers to the available update.

47835.diff is good to go.

#7 @SergeyBiryukov
2 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 45750:

Site Health: Use correct variable when checking PHP requirements for a plugin update in WP_Plugins_List_Table::single_row().

Props diddledan, sharaz, vaishalipanchal.
Fixes #47835.

#8 @SergeyBiryukov
2 months ago

  • Keywords fixed-major added
  • Milestone changed from 5.3 to 5.2.3
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 5.2.3 consideration.

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


2 months ago

#10 @JeffPaul
8 weeks ago

Confirmed via @afragen in bugscrub (see Slack link above) that this has been tested.

#11 @SergeyBiryukov
8 weeks ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 45833:

Site Health: Use correct variable when checking PHP requirements for a plugin update in WP_Plugins_List_Table::single_row().

Props diddledan, sharaz, vaishalipanchal, afragen.
Merges [45750] to the 5.2 branch.
Fixes #47835.

Note: See TracTickets for help on using tickets.