Skip to content

Commit

Permalink
Upgrade/Install: Remove parsing of readme.txt files for plugin or t…
Browse files Browse the repository at this point in the history
…heme requirements.

This affects:
* `validate_plugin_requirements()`
* `validate_theme_requirements()`

Historically, the `Requires PHP` header was introduced in #meta2952 for the Plugin Directory first, so at the time it made sense to have it defined in the same place as `Requires at least`, which only existed in `readme.txt`. 

Since parsing of PHP and WordPress requirements was later added to WordPress core, the core should retrieve all the necessary data from the main plugin or theme file and not from `readme.txt`, which only contains the data meant for the Plugin or Theme Directory.

The recommended place for `Requires PHP` and `Requires at least` headers is as follows:
* The plugin's main PHP file
* The theme's `style.css` file

The place for the `Tested up to` header remains in `readme.txt` for the time being, as it's not used by WordPress core.

Follow-up to [44978], [45546], [47573], [47574], [meta5841], [meta9050].

Props afragen, Otto42, joyously, williampatton, audrasjb.
Fixes #48520. See #48515, #meta2952, #meta4514, #meta4621.

git-svn-id: https://develop.svn.wordpress.org/trunk@51092 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jun 8, 2021
1 parent 611d953 commit 38d47a9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
19 changes: 1 addition & 18 deletions src/wp-admin/includes/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1119,12 +1119,10 @@ function validate_plugin( $plugin ) {
* Uses the information from `Requires at least` and `Requires PHP` headers
* defined in the plugin's main PHP file.
*
* If the headers are not present in the plugin's main PHP file,
* `readme.txt` is also checked as a fallback.
*
* @since 5.2.0
* @since 5.3.0 Added support for reading the headers from the plugin's
* main PHP file, with `readme.txt` as a fallback.
* @since 5.8.0 Removed support for using `readme.txt` as a fallback.
*
* @param string $plugin Path to the plugin file relative to the plugins directory.
* @return true|WP_Error True if requirements are met, WP_Error on failure.
Expand All @@ -1137,21 +1135,6 @@ function validate_plugin_requirements( $plugin ) {
'requires_php' => ! empty( $plugin_headers['RequiresPHP'] ) ? $plugin_headers['RequiresPHP'] : '',
);

$readme_file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/readme.txt';

if ( file_exists( $readme_file ) ) {
$readme_headers = get_file_data(
$readme_file,
array(
'requires' => 'Requires at least',
'requires_php' => 'Requires PHP',
),
'plugin'
);

$requirements = array_merge( $readme_headers, $requirements );
}

$compatible_wp = is_wp_version_compatible( $requirements['requires'] );
$compatible_php = is_php_version_compatible( $requirements['requires_php'] );

Expand Down
19 changes: 1 addition & 18 deletions src/wp-includes/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,8 @@ function validate_current_theme() {
* Uses the information from `Requires at least` and `Requires PHP` headers
* defined in the theme's `style.css` file.
*
* If the headers are not present in the theme's stylesheet file,
* `readme.txt` is also checked as a fallback.
*
* @since 5.5.0
* @since 5.8.0 Removed support for using `readme.txt` as a fallback.
*
* @param string $stylesheet Directory name for the theme.
* @return true|WP_Error True if requirements are met, WP_Error on failure.
Expand All @@ -915,21 +913,6 @@ function validate_theme_requirements( $stylesheet ) {
'requires_php' => ! empty( $theme->get( 'RequiresPHP' ) ) ? $theme->get( 'RequiresPHP' ) : '',
);

$readme_file = $theme->theme_root . '/' . $stylesheet . '/readme.txt';

if ( file_exists( $readme_file ) ) {
$readme_headers = get_file_data(
$readme_file,
array(
'requires' => 'Requires at least',
'requires_php' => 'Requires PHP',
),
'theme'
);

$requirements = array_merge( $readme_headers, $requirements );
}

$compatible_wp = is_wp_version_compatible( $requirements['requires'] );
$compatible_php = is_php_version_compatible( $requirements['requires_php'] );

Expand Down

0 comments on commit 38d47a9

Please sign in to comment.