WordPress.org

Making WordPress.org

Changeset 11168


Ignore:
Timestamp:
08/09/2021 02:21:50 AM (3 months ago)
Author:
dufresnesteven
Message:

Themes: Show multiple theme errors at once during upload.

See: https://github.com/WordPress/wordpress.org/pull/36

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

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php

    r11150 r11168  
    161161     * Runs various tests, creates Trac ticket, repopackage post, and saves the files to the SVN repo.
    162162     *
    163      * @return string Failure or success message.
     163     * @return mixed Failure or success message.
    164164     */
    165165    public function process_upload( $file_upload ) {
     
    188188        }
    189189
     190        $style_errors = array();
     191
    190192        // Do we have a readme.txt? Fetch extra data from there too.
    191193        $this->readme = $this->get_readme_data( $theme_files );
     
    197199        if ( ! $this->has_screenshot( $theme_files ) ) {
    198200            /* translators: 1: screenshot.png, 2: screenshot.jpg */
    199             return sprintf( __( 'The zip file must include a file named %1$s or %2$s.', 'wporg-themes' ),
     201            $style_errors[] = sprintf( __( 'The zip file must include a file named %1$s or %2$s.', 'wporg-themes' ),
    200202                '<code>screenshot.png</code>',
    201203                '<code>screenshot.jpg</code>'
     
    224226            );
    225227
    226             return $error;
     228            $style_errors[] = $error;
    227229        }
    228230
     
    230232        if ( false !== strpos( $this->theme_slug, 'wordpress' ) || preg_match( '/\btheme\b/i', $this->theme_slug ) ) {
    231233            /* translators: 1: 'WordPress', 2: 'theme' */
    232             return sprintf( __( 'You cannot use %1$s or %2$s in your theme name.', 'wporg-themes' ),
     234            $style_errors[] = sprintf( __( 'You cannot use %1$s or %2$s in your theme name.', 'wporg-themes' ),
    233235                'WordPress',
    234236                'theme'
     
    243245        if ( $this->has_reserved_slug() ) {
    244246            /* translators: 1: theme slug, 2: style.css */
    245             return sprintf( __( 'Sorry, the theme name %1$s is reserved for use by WordPress Core. Please change the name of your theme in %2$s and upload it again.', 'wporg-themes' ),
     247            $style_errors[] = sprintf( __( 'Sorry, the theme name %1$s is reserved for use by WordPress Core. Please change the name of your theme in %2$s and upload it again.', 'wporg-themes' ),
    246248                '<code>' . $this->theme_slug . '</code>',
    247249                '<code>style.css</code>'
     
    263265            );
    264266
    265             return $error;
     267            $style_errors[] = $error;
    266268        }
    267269
     
    276278            );
    277279
    278             return $error;
     280            $style_errors[] = $error;
    279281        }
    280282
     
    289291            );
    290292
    291             return $error;
    292         }
    293 
    294         if ( preg_match( '|[^\d\.]|', $this->theme->get( 'Version' ) ) ) {
     293            $style_errors[] = $error;
     294
     295        } else if ( preg_match( '|[^\d\.]|', $this->theme->get( 'Version' ) ) ) {
    295296            /* translators: %s: style.css */
    296             return sprintf( __( 'Version strings can only contain numeric and period characters (like 1.2). Please fix your Version: line in %s and upload your theme again.', 'wporg-themes' ),
     297            $style_errors[] = sprintf( __( 'Version strings can only contain numeric and period characters (like 1.2). Please fix your Version: line in %s and upload your theme again.', 'wporg-themes' ),
    297298                '<code>style.css</code>'
    298299            );
     
    305306        $authoruri = $this->theme->get( 'AuthorURI' );
    306307        if ( !empty( $themeuri ) && !empty( $authoruri ) && $themeuri == $authoruri ) {
    307             return __( 'Duplicate theme and author URLs. A theme URL is a page/site that provides details about this specific theme. An author URL is a page/site that provides information about the author of the theme. You aren&rsquo;t required to provide both, so pick the one that best applies to your URL.', 'wporg-themes' );
     308            $style_errors[] = __( 'Duplicate theme and author URLs. A theme URL is a page/site that provides details about this specific theme. An author URL is a page/site that provides information about the author of the theme. You aren&rsquo;t required to provide both, so pick the one that best applies to your URL.', 'wporg-themes' );
    308309        }
    309310
     
    311312        if ( $this->theme->parent() && ! in_array( 'buddypress', $this->theme->get( 'Tags' ) ) && ! $this->is_parent_available() ) {
    312313            /* translators: %s: parent theme */
    313             return sprintf( __( 'There is no theme called %s in the directory. For child themes, you must use a parent theme that already exists in the directory.', 'wporg-themes' ),
     314            $style_errors[] = sprintf( __( 'There is no theme called %s in the directory. For child themes, you must use a parent theme that already exists in the directory.', 'wporg-themes' ),
    314315                '<code>' . $this->theme->parent() . '</code>'
    315316            );
     
    342343            if ( ! $is_allowed_to_upload_for_theme ) {
    343344                /* translators: 1: theme slug, 2: style.css */
    344                 return sprintf( __( 'There is already a theme called %1$s by a different author. Please change the name of your theme in %2$s and upload it again.', 'wporg-themes' ),
     345                $style_errors[] = sprintf( __( 'There is already a theme called %1$s by a different author. Please change the name of your theme in %2$s and upload it again.', 'wporg-themes' ),
    345346                    '<code>' . $this->theme_slug . '</code>',
    346347                    '<code>style.css</code>'
     
    365366
    366367            if ( $theme_owners && ! in_array( $this->author->ID, $theme_owners ) ) {
    367                 return sprintf(
     368                $style_errors[] = sprintf(
    368369                    /* translators: 1: theme name, 2: style.css */
    369370                    __( 'There is already a theme using the Theme URL %1$s by a different author. Please check the URL of your theme in %2$s and upload it again.', 'wporg-themes' ),
     
    377378        if ( ! empty( $this->theme_post ) && 'suspend' === $this->theme_post->post_status ) {
    378379            /* translators: %s: mailto link */
    379             return sprintf( __( 'This theme is suspended from the Theme Repository and it can&rsquo;t be updated. If you have any questions about this please contact %s.', 'wporg-themes' ),
     380            $style_errors[] = sprintf( __( 'This theme is suspended from the Theme Repository and it can&rsquo;t be updated. If you have any questions about this please contact %s.', 'wporg-themes' ),
    380381                '<a href="mailto:themes@wordpress.org">themes@wordpress.org</a>'
    381382            );
     
    385386        if ( ! empty( $this->theme_post ) && ! version_compare( $this->theme->get( 'Version' ), $this->theme_post->max_version, '>' ) ) {
    386387            /* translators: 1: theme name, 2: theme version, 3: style.css */
    387             return sprintf( __( 'You need to upload a version of %1$s higher than %2$s. Increase the theme version number in %3$s, then upload your zip file again.', 'wporg-themes' ),
     388            $style_errors[] = sprintf( __( 'You need to upload a version of %1$s higher than %2$s. Increase the theme version number in %3$s, then upload your zip file again.', 'wporg-themes' ),
    388389                $this->theme->display( 'Name' ),
    389390                '<code>' . $this->theme_post->max_version . '</code>',
    390391                '<code>style.css</code>'
    391392            );
     393        }
     394
     395        // If we had any issues with information in the style.css, exit early.
     396        if ( ! empty( $style_errors ) ) {
     397            return $style_errors;
    392398        }
    393399
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/upload.php

    r10806 r11168  
    5050
    5151    if ( ! empty( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wporg-themes-upload' ) && 'upload' === $_POST['action'] ) {
    52         $message = wporg_themes_process_upload();
     52        $messages = wporg_themes_process_upload();
    5353
    54         if ( ! empty( $message ) ) {
    55             $notice = "<div class='notice notice-warning'><p>{$message}</p></div>";
     54        if ( ! empty( $messages ) ) {
     55            $notice_content = "";
     56
     57            if ( is_array( $messages ) ) {
     58                foreach ( $messages as $message){
     59                    $notice_content .= "<li>{$message}</li>";
     60                }
     61            } else {
     62                $notice_content = "<li>{$messages}</li>";
     63            }
     64
     65            $notice = "<h2>" . esc_html__( 'Upload Errors', 'wporg-themes' ) . "</h2><div class='notice notice-error notice-large'><ul>{$notice_content}</ul></div>";
    5666        }
    5767    }
Note: See TracChangeset for help on using the changeset viewer.