Make WordPress Core

Ticket #46938: 46938.2.diff

File 46938.2.diff, 3.1 KB (added by afragen, 6 years ago)

give precedence to plugin headers

  • wp-admin/includes/plugin.php

    diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php
    index 7a1b038518..67ca8258f5 100644
    a b  
    3131 *     Network: Optional. Specify "Network: true" to require that a plugin is activated
    3232 *          across all sites in an installation. This will prevent a plugin from being
    3333 *          activated on a single site when Multisite is enabled.
     34 *     Requires WP: Optional. Specify the minimum required WordPress version.
     35 *     Requires PHP: Optional. Specify the minimum required PHP version.
    3436 *      * / # Remove the space to close comment
    3537 *
    3638 * Some users have issues with opening large files and manipulating the contents
     
    4648 * reading.
    4749 *
    4850 * @since 1.5.0
     51 * @since 5.3.0 Added `RequiresWP` and `RequiresPHP`.
    4952 *
    5053 * @param string $plugin_file Absolute path to the main plugin file.
    5154 * @param bool   $markup      Optional. If the returned data should have HTML markup applied.
     
    6366 *     @type string $TextDomain  Plugin textdomain.
    6467 *     @type string $DomainPath  Plugins relative directory path to .mo files.
    6568 *     @type bool   $Network     Whether the plugin can only be activated network-wide.
     69 *     @type string $RequiresWP  Minimum required version of WordPress.
     70 *     @type string $RequiresPHP Minimum required version of PHP.
    6671 * }
    6772 */
    6873function get_plugin_data( $plugin_file, $markup = true, $translate = true ) {
    function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { 
    7782                'TextDomain'  => 'Text Domain',
    7883                'DomainPath'  => 'Domain Path',
    7984                'Network'     => 'Network',
     85                'RequiresWP'  => 'Requires WP',
     86                'RequiresPHP' => 'Requires PHP',
    8087                // Site Wide Only is deprecated in favor of Network.
    8188                '_sitewide'   => 'Site Wide Only',
    8289        );
    function validate_plugin( $plugin ) { 
    10851092 */
    10861093function validate_plugin_requirements( $plugin ) {
    10871094        $readme_file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/readme.txt';
     1095        $plugin_data = array(
     1096                'requires'     => '',
     1097                'requires_php' => '',
     1098        );
    10881099
    10891100        if ( file_exists( $readme_file ) ) {
    10901101                $plugin_data = get_file_data(
    function validate_plugin_requirements( $plugin ) { 
    10951106                        ),
    10961107                        'plugin'
    10971108                );
    1098         } else {
    1099                 return true;
    11001109        }
    11011110
     1111        $plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) );
     1112
     1113        // Check for headers in plugin file, precedence to plugin headers.
     1114        $plugin_data['requires']     = empty( $plugin_data['RequiresWP'] ) ? $plugin_data['requires'] : $plugin_data['RequiresWP'];
     1115        $plugin_data['requires_php'] = empty( $plugin_data['RequiresPHP'] ) ? $plugin_data['requires_php'] : $plugin_data['RequiresPHP'];
     1116
    11021117        $plugin_data['wp_compatible']  = is_wp_version_compatible( $plugin_data['requires'] );
    11031118        $plugin_data['php_compatible'] = is_php_version_compatible( $plugin_data['requires_php'] );
    11041119
    1105         $plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) );
    1106 
    11071120        if ( ! $plugin_data['wp_compatible'] && ! $plugin_data['php_compatible'] ) {
    11081121                return new WP_Error(
    11091122                        'plugin_wp_php_incompatible',