WordPress.org

Making WordPress.org

Changeset 10971


Ignore:
Timestamp:
05/13/2021 07:20:04 PM (7 months ago)
Author:
ocean90
Message:

Plugin Directory: Update text domain check for plugins using the Requires at least header in the plugin's main PHP file.

Fixes #4514.

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

Legend:

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

    r10726 r10971  
    297297        /**
    298298         * Action that fires after a plugin is imported.
    299          * 
     299         *
    300300         * @param WP_Post $plugin         The plugin updated.
    301301         * @param string  $stable_tag     The new stable tag for the plugin.
     
    680680     * @return string The plugin readme.txt or readme.md filename.
    681681     */
    682     static function find_readme_file( $directory ) {
     682    public static function find_readme_file( $directory ) {
    683683        $files = Filesystem::list_files( $directory, false /* non-recursive */, '!(?:^|/)readme\.(txt|md)$!i' );
    684684
     
    700700     * @return object The plugin headers.
    701701     */
    702     static function find_plugin_headers( $directory ) {
     702    public static function find_plugin_headers( $directory ) {
    703703        $files = Filesystem::list_files( $directory, false, '!\.php$!i' );
    704704
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-code-import.php

    r7893 r10971  
    33
    44use Exception;
     5use WordPressdotorg\Plugin_Directory\CLI\Import;
    56use WordPressdotorg\Plugin_Directory\Readme\Parser;
    67use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
     
    8687     */
    8788    private function is_plugin_valid( $export_directory ) {
    88         $readme = new Parser( $this->find_readme_file( $export_directory ) );
     89        $readme   = new Parser( Import::find_readme_file( $export_directory ) );
     90        $requires = $readme->requires;
    8991
    90         // Whether plugin files should be checked for valid text domains.
    91         if ( empty( $readme->requires ) || version_compare( $readme->requires, '4.6', '<' ) ) {
     92        // Prefer requires field from the plugin headers if set.
     93        $headers = Import::find_plugin_headers( $export_directory );
     94        if ( $headers->RequiresWP && preg_match( '!^[\d.]{3,}$!', $headers->RequiresWP ) ) {
     95            $requires = $headers->RequiresWP;
     96        }
     97
     98        // Whether plugin files should be checked for valid text domain setup.
     99        if ( empty( $requires ) || version_compare( $requires, '4.6', '<' ) ) {
    92100            $error                = new WP_Error();
    93101            $esc_export_directory = escapeshellarg( $export_directory );
     
    101109
    102110                if ( ! $has_slug_as_textdomain_header ) {
    103                     $error->add( 'wrong_textdomain', 'Wrong text domain in header.' );
     111                    $error->add( 'wrong_textdomain', 'Requires WordPress ' . ( $requires ?: 'n/a' ) . '; wrong text domain in header, expected `' . $this->plugin . '`.' );
    104112                }
    105113            } else {
    106                 $error->add( 'missing_textdomain', 'Missing text domain in header.' );
     114                $error->add( 'missing_textdomain', 'Requires WordPress ' .  ( $requires ?: 'n/a' ) . '; missing text domain in header.' );
    107115            }
    108116
    109117            if ( ! $has_load_plugin_textdomain ) {
    110                 $error->add( 'missing_load_plugin_textdomain', 'Missing load_plugin_textdomain().' );
     118                $error->add( 'missing_load_plugin_textdomain', 'Requires WordPress ' .  ( $requires ?: 'n/a' ) . '; missing load_plugin_textdomain() call.' );
    111119            }
    112120
     
    118126        return true;
    119127    }
    120 
    121     /**
    122      * Find the plugin readme file.
    123      *
    124      * Looks for either a readme.txt or readme.md file, prioritizing readme.txt.
    125      *
    126      * @param string $directory
    127      * @return string The plugin readme.txt or readme.md filename.
    128      */
    129     private function find_readme_file( $directory ) {
    130         $files = Filesystem::list_files( $directory, false /* non-recursive */, '!^readme\.(txt|md)$!i' );
    131 
    132         // Prioritize readme.txt
    133         foreach ( $files as $file ) {
    134             if ( '.txt' === strtolower( substr( $file, -4 ) ) ) {
    135                 return $file;
    136             }
    137         }
    138 
    139         return reset( $files );
    140     }
    141128}
Note: See TracChangeset for help on using the changeset viewer.