Making WordPress.org

Changeset 13133


Ignore:
Timestamp:
01/22/2024 01:13:35 AM (15 months ago)
Author:
dd32
Message:

Plugin Directory: Readme: Expand the number of warnings generated by the Readme parser.

This will allow for tools which reuse it to detect and warn about more invalid cases.

Props dd32, rabmalin, mukesh27.
Closes https://github.com/WordPress/wordpress.org/pull/190.
Fixes #7412.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme
Files:
2 edited

Legend:

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

    r12582 r13133  
    145145     * @var array
    146146     */
    147     private $ignore_tags = array(
     147    public $ignore_tags = array(
    148148        'plugin',
    149149        'wordpress',
     
    226226        // Handle readme's which do `=== Plugin Name ===\nMy SuperAwesomePlugin Name\n...`
    227227        if ( 'plugin name' == strtolower( $this->name ) ) {
     228            $this->warnings['invalid_plugin_name_header'] = true;
     229
    228230            $this->name = $line = $this->get_first_nonwhitespace( $contents );
    229231
     
    274276            $this->tags = array_map( 'trim', $this->tags );
    275277            $this->tags = array_filter( $this->tags );
    276             $this->tags = array_diff( $this->tags, $this->ignore_tags );
    277             $this->tags = array_slice( $this->tags, 0, 5 );
     278            if ( array_intersect( $this->tags, $this->ignore_tags ) ) {
     279                $this->tags = array_diff( $this->tags, $this->ignore_tags );
     280                $this->warnings['ignored_tags'] = true;
     281            }
     282            if ( count( $this->tags ) > 5 ) {
     283                $this->tags = array_slice( $this->tags, 0, 5 );
     284                $this->warnings['too_many_tags'] = true;
     285            }
    278286        }
    279287        if ( ! empty( $headers['requires'] ) ) {
     
    409417        if ( ! $this->short_description && ! empty( $this->sections['description'] ) ) {
    410418            $this->short_description = array_filter( explode( "\n", $this->sections['description'] ) )[0];
     419            $this->warnings['no_short_description_present'] = true;
    411420        }
    412421
     
    415424        $this->short_description = $this->parse_markdown( $this->short_description );
    416425        $this->short_description = wp_strip_all_tags( $this->short_description );
    417         $this->short_description = $this->trim_length( $this->short_description, 150 );
     426        $short_description       = $this->trim_length( $this->short_description, 150 );
     427        if ( $short_description !== $this->short_description ) {
     428            if ( empty( $this->warnings['no_short_description_present'] ) ) {
     429                $this->warnings['trimmed_short_description'] = true;
     430            }
     431            $this->short_description = $short_description;
     432        }
    418433
    419434        if ( isset( $this->sections['screenshots'] ) ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php

    r12614 r13133  
    7272
    7373        // Fatal errors.
    74         if ( empty( $readme->name ) ) {
     74        if ( empty( $readme->name ) || isset( $readme->warnings['invalid_plugin_name_header'] ) ) {
    7575            $errors[] = sprintf(
    7676                /* translators: 1: 'Plugin Name' section title, 2: 'Plugin Name' */
     
    145145        }
    146146
     147        if ( isset( $readme->warnings['too_many_tags'] ) ) {
     148            $warnings[] = __( 'One or more tags were ignored. Please limit your plugin to 5 tags.', 'wporg-plugins' );
     149        }
     150
     151        if ( isset( $readme->warnings['ignored_tags'] ) ) {
     152            $warnings[] = sprintf(
     153                /* translators: %s: list of tags not supported */
     154                __( 'One or more tags were ignored. The following tags are not permitted: %s', 'wporg-plugins' ),
     155                '<code>' . implode( '</code>, <code>', $readme->ignore_tags ) . '</code>'
     156            );
     157        }
     158
    147159        // Notes.
    148160        if ( empty( $readme->requires ) ) {
     
    162174        }
    163175
     176        if ( isset( $readme->warnings['no_short_description_present'] ) ) {
     177            $notes[] = sprintf(
     178                /* translators: %s: section title */
     179                __( 'The %s section is missing. An excerpt was generated from your main plugin description.', 'wporg-plugins' ),
     180                '<code>Short Description</code>'
     181            );
     182        } elseif( isset( $readme->warnings['trimmed_short_description'] ) ) {
     183            $notes[] = sprintf(
     184                /* translators: %s: section title */
     185                __( 'The %s section is too long and was truncated. A maximum of 150 characters is supported.', 'wporg-plugins' ),
     186                '<code>Short Description</code>'
     187            );
     188        }
     189
    164190        if ( empty( $readme->sections['faq'] ) ) {
    165191            $notes[] = sprintf(
Note: See TracChangeset for help on using the changeset viewer.