Making WordPress.org

Changeset 9050


Ignore:
Timestamp:
07/16/2019 05:55:10 AM (5 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.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 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.
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php

    r8469 r9050  
    8686                '<code>' . number_format( $latest_wordpress_version - 0.1, 1 ) . '</code>'
    8787            );
    88         } elseif ( empty( $readme->requires ) ) {
    89             $warnings[] = sprintf(
    90                 /* translators: %s: plugin header tag */
    91                 __( 'The %s field is missing.', 'wporg-plugins' ),
    92                 '<code>Requires at least</code>'
    93             );
    9488        }
    9589
     
    120114                '<code>7.0</code>'
    121115            );
    122         } elseif ( empty( $readme->requires_php ) ) {
    123             $warnings[] = sprintf(
    124                 /* translators: %s: plugin header tag */
    125                 __( 'The %s field is missing.', 'wporg-plugins' ),
    126                 '<code>Requires PHP</code>'
    127             );
    128116        }
     117
    129118        if ( empty( $readme->stable_tag ) ) {
    130119            $warnings[] = sprintf(
     
    152141
    153142        // Notes.
     143        if ( empty( $readme->requires ) ) {
     144            $notes[] = sprintf(
     145                /* translators: %s: plugin header tag */
     146                __( 'The %s field is missing. It should be defined here, or in your main plugin file.', 'wporg-plugins' ),
     147                '<code>Requires at least</code>'
     148            );
     149        }
     150
     151        if ( empty( $readme->requires_php ) ) {
     152            $notes[] = sprintf(
     153                /* translators: %s: plugin header tag */
     154                __( 'The %s field is missing. It should be defined here, or in your main plugin file.', 'wporg-plugins' ),
     155                '<code>Requires PHP</code>'
     156            );
     157        }
     158
    154159        if ( empty( $readme->sections['faq'] ) ) {
    155160            $notes[] = sprintf(
     
    159164            );
    160165        }
     166
    161167        if ( empty( $readme->sections['changelog'] ) ) {
    162168            $notes[] = sprintf(
     
    166172            );
    167173        }
     174
    168175        if ( empty( $readme->upgrade_notice ) ) {
    169176            $notes[] = sprintf(
     
    173180            );
    174181        }
     182
    175183        if ( empty( $readme->screenshots ) ) {
    176184            $notes[] = sprintf(
     
    180188            );
    181189        }
     190
    182191        if ( empty( $readme->donate_link ) ) {
    183192            $notes[] = __( 'No donate link was found', 'wporg-plugins' );
Note: See TracChangeset for help on using the changeset viewer.