Making WordPress.org


Ignore:
Timestamp:
07/16/2019 05:55:10 AM (7 years ago)
Author:
dd32
Message:

Plugin Directory: Preference the Requires PHP and Requires at least headers defined in the Plugins .php header over the readme.txt values.

This also moves the missing fields in the readme.txt to being notes rather than warnings in the readme validator.

This matches the behaviour in WordPress 5.3, see #WP46938.
Fixes #4514.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r8976 r9050  
    2626        public $readme_fields = array(
    2727                'tested',
    28                 'requires',
    29                 'requires_php',
    3028                'donate_link',
    3129                'license',
     
    3331                'upgrade_notice',
    3432                'screenshots',
     33
     34                // These headers are stored as post meta, but are handled separately.
     35                // 'requires',
     36                // 'requires_php',
    3537        );
    3638
     
    4042                'Name'       => 'header_name',
    4143                'PluginURI'  => 'header_plugin_uri',
    42                 'Version'    => 'version',
    4344                'Author'     => 'header_author',
    4445                'AuthorURI'  => 'header_author_uri',
    4546                'TextDomain' => 'header_textdomain',
     47
     48                // These headers are stored in these fields, but are handled separately.
     49                // 'Version'     => 'version',
     50                // 'RequiresWP'  => 'requires',
     51                // 'RequiresPHP' => 'requires_php',
    4652        );
    4753
     
    147153                }
    148154
     155                // Store the plugin headers we need. Note that 'Version', 'RequiresWP', and 'RequiresPHP' are handled below.
    149156                foreach ( $this->plugin_headers as $plugin_header => $meta_field ) {
    150                         if ( 'Version' == $plugin_header ) {
    151                                 continue; // We'll specifically update the latest version after everything is built.
    152                         }
    153157                        update_post_meta( $plugin->ID, $meta_field, ( isset( $headers->$plugin_header ) ? wp_slash( $headers->$plugin_header ) : '' ) );
    154158                }
    155159
    156                 update_post_meta( $plugin->ID, 'tagged_versions', wp_slash( $tagged_versions ) );
    157                 update_post_meta( $plugin->ID, 'sections', wp_slash( array_keys( $readme->sections ) ) );
     160                // Update the Requires and Requires PHP fields, prefering those from the Plugin Headers.
     161                // Unfortunately the value within $headers is not always a well-formed value.
     162                $requires     = $readme->requires;
     163                $requires_php = $readme->requires_php;
     164                if ( $headers->RequiresWP && preg_match( '!^[\d.]{3,}$!', $headers->RequiresWP ) ) {
     165                        $requires = $headers->RequiresWP;
     166                }
     167                if ( $headers->RequiresPHP && preg_match( '!^[\d.]{3,}$!', $headers->RequiresPHP ) ) {
     168                        $requires_php = $headers->RequiresPHP;
     169                }
     170
     171                update_post_meta( $plugin->ID, 'requires',           wp_slash( $requires ) );
     172                update_post_meta( $plugin->ID, 'requires_php',       wp_slash( $requires_php ) );
     173                update_post_meta( $plugin->ID, 'tagged_versions',    wp_slash( $tagged_versions ) );
     174                update_post_meta( $plugin->ID, 'sections',           wp_slash( array_keys( $readme->sections ) ) );
    158175                update_post_meta( $plugin->ID, 'assets_screenshots', wp_slash( $assets['screenshot'] ) );
    159                 update_post_meta( $plugin->ID, 'assets_icons', wp_slash( $assets['icon'] ) );
    160                 update_post_meta( $plugin->ID, 'assets_banners', wp_slash( $assets['banner'] ) );
    161                 update_post_meta( $plugin->ID, 'last_updated', wp_slash( $plugin->post_modified_gmt ) );
    162                 update_post_meta( $plugin->ID, 'plugin_status', wp_slash( $plugin->post_status ) );
     176                update_post_meta( $plugin->ID, 'assets_icons',       wp_slash( $assets['icon'] ) );
     177                update_post_meta( $plugin->ID, 'assets_banners',     wp_slash( $assets['banner'] ) );
     178                update_post_meta( $plugin->ID, 'last_updated',       wp_slash( $plugin->post_modified_gmt ) );
     179                update_post_meta( $plugin->ID, 'plugin_status',      wp_slash( $plugin->post_status ) );
    163180
    164181                // Calculate the 'plugin color' from the average color of the banner if provided. This is used for fallback icons.
Note: See TracChangeset for help on using the changeset viewer.