Making WordPress.org


Ignore:
Timestamp:
04/03/2024 07:01:21 AM (6 months ago)
Author:
dd32
Message:

Plugin Directory: Store error codes (rather than english error messages) that occur during a plugin import, to allow the errors to be generated with the appropriate translations.

This expands some errors to better highlight what is invalid as well.

See #6108.

File:
1 edited

Legend:

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

    r13365 r13443  
    106106        // If the readme generated any warnings, raise it to self::$import_warnings;
    107107        if ( $readme->warnings ) {
    108             // Convert the warnings to a human readable format.
    109             $readme_warnings = Readme_Validator::instance()->validate_content( $readme->raw_contents );
    110 
    111             foreach ( [ 'errors', 'warnings' ] as $field ) {
    112                 foreach ( $readme_warnings[ $field ] ?? [] as $warning ) {
    113                     $this->warnings[] = "Readme: {$warning}";
    114                 }
    115             }
     108            $this->warnings = array_merge( $this->warnings, $readme->warnings );
    116109        }
    117110
     
    128121            $update_uri_valid = preg_match( '!^(https?://)?(wordpress.org|w.org)/plugins?/(?P<slug>[^/]+)/?$!i', $headers->UpdateURI, $update_uri_matches );
    129122            if ( ! $update_uri_valid || $update_uri_matches['slug'] !== $plugin_slug ) {
    130                 $this->warnings['invalid_update_uri'] = 'Invalid Update URI header detected: ' . $headers->UpdateURI;
    131 
    132                 throw new Exception( $this->warnings['invalid_update_uri'] );
     123                $this->warnings['invalid_update_uri'] = $headers->UpdateURI;
     124
     125                throw new Exception( Readme_Validator::instance()->translate_code_to_message( 'invalid_update_uri' ) );
    133126            }
    134127        }
     
    153146
    154147        if ( $unmet_dependencies ) {
    155             $this->warnings['unmet_dependencies'] = 'Invalid plugin dependencies specified. The following dependencies could not be resolved: ' . implode( ', ', $requires_plugins_unmet );
    156 
    157             throw new Exception( $this->warnings['unmet_dependencies'] );
     148            $this->warnings['unmet_dependencies'] = $requires_plugins_unmet;
     149
     150            throw new Exception( Readme_Validator::instance()->translate_code_to_message( 'unmet_dependencies', $requires_plugins_unmet ) );
    158151        }
    159152        unset( $_requires_plugins, $unmet_dependencies );
     
    11691162                    }
    11701163
    1171                     // Normalise a "install theme from url" to a install-by-slug.
     1164                    // Normalize a "install theme from url" to a install-by-slug.
    11721165                    if (
    11731166                        'installTheme' === $step['step'] &&
     
    12101203            }
    12111204
    1212 
    12131205            $contents = json_encode( $decoded_file ); // Re-encode to minimize whitespace
    12141206        }
Note: See TracChangeset for help on using the changeset viewer.