Making WordPress.org

Changeset 12186


Ignore:
Timestamp:
11/02/2022 03:16:40 AM (4 years ago)
Author:
dd32
Message:

Theme Directory: Allow core committers to upload default themes, both updates and new default themes.

This also allows for default themes (any theme owned by WordPress.org) to bypass Theme Check failures, which happens due to the unexpected slugs.

Previously [10927], [11479], and others.

File:
1 edited

Legend:

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

    r11641 r12186  
    445445                }
    446446
     447                // Default Theme handling.
     448                if (
     449                        // Reserved slugs include twenty* and other terms
     450                        $this->has_reserved_slug() &&
     451                        // ...so limit to twenty* only
     452                        str_starts_with( $this->theme_slug, 'twenty' ) &&
     453                        // The current user is a Core Committer. [ 'user_login' => 'Trac Title', ... ]
     454                        ! empty( $GLOBALS['committers'][ $this->author->user_login ] ) &&
     455                        (
     456                                // New theme submission
     457                                ! $this->theme_post
     458                                ||
     459                                // OR an Update and the theme is owned by WordPress.org.
     460                                'wordpressdotorg' === get_user_by( 'id', $this->theme_post->post_author )->user_login
     461                        )
     462                ) {
     463                        // Set the author to WordPress.org
     464                        $this->author = get_user_by( 'login', 'wordpressdotorg' );
     465
     466                        // WordPress.org is allowed to bypass Theme Check, see further down.
     467                }
     468
    447469                // Make sure it doesn't use a slug deemed not to be used by the public.
    448470                if ( $this->has_reserved_slug() ) {
    … …  
    559581                        $this->theme_post->post_author != $this->author->ID
    560582                ) {
    561 
    562                         $is_allowed_to_upload_for_theme = false;
    563                         if (
    564                                 // The theme is owned by WordPress.org.
    565                                 'wordpressdotorg' === get_user_by( 'id', $this->theme_post->post_author )->user_nicename &&
    566                                 // The current user is a Core Committer. [ 'user_login' => 'Trac Title', ... ]
    567                                 ! empty( $GLOBALS['committers'][ $this->author->user_login ] )
    568                         ) {
    569                                 // Allow core committers to update default themes (as authored by @wordpressdotorg)
    570                                 $is_allowed_to_upload_for_theme = true;
    571                         }
    572 
    573                         if ( ! $is_allowed_to_upload_for_theme ) {
    574                                 $style_errors->add(
    575                                         'cannot_upload_theme',
    576                                         sprintf(
    577                                                 /* translators: 1: theme slug, 2: style.css */
    578                                                 __( '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' ),
    579                                                 '<code>' . $this->theme_slug . '</code>',
    580                                                 '<code>style.css</code>'
    581                                         ) . $are_you_in_the_right_place
    582                                 );
    583                         }
     583                        $style_errors->add(
     584                                'cannot_upload_theme',
     585                                sprintf(
     586                                        /* translators: 1: theme slug, 2: style.css */
     587                                        __( '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' ),
     588                                        '<code>' . $this->theme_slug . '</code>',
     589                                        '<code>style.css</code>'
     590                                ) . $are_you_in_the_right_place
     591                        );
    584592                }
    585593
    … …  
    652660                }
    653661
    654                 // Don't block special themes based on Theme Check.
     662                // Don't block special themes or default themes based on Theme Check.
    655663                if ( has_category( 'special-case-theme', $this->theme_post ) ) {
     664                        $args['block_on_themecheck'] = false;
     665                } elseif ( 'wordpressdotorg' === get_user_by( 'id', $this->theme_post->post_author )->user_login ) {
    656666                        $args['block_on_themecheck'] = false;
    657667                }
    … …  
    9901000                }
    9911001
    992                 // Only committers uploading a default theme *update* are left to be checked for.
    993                 // New default themes MUST be uploaded by `wordpressdotorg` and will fail this check.
    994                 if (
    995                         // Updates only.
    996                         $this->theme_post &&
    997                         // The current user is a Core Committer. [ 'user_login' => 'Trac Title', ... ]
    998                         ! empty( $GLOBALS['committers'][ $this->author->user_login ] ) &&
    999                         // The theme is owned by WordPress.org.
    1000                         'wordpressdotorg' === get_user_by( 'id', $this->theme_post->post_author )->user_login
    1001                 ) {
    1002                         // Slug is reserved, but an update is being uploaded by a core committer.
    1003                         return false;
    1004                 }
    1005 
    10061002                // Slug is reserved, user is not authorized.
    10071003                return true;
    … …  
    11991195                }
    12001196
     1197                /*
     1198                 * Trac reporter is always the authenticated user, unless it's not-auth'd in which case it's the Theme Author.
     1199                 *
     1200                 * This allows for Committers to upload Default themes under 'WordPress.org' but it still be to noted on Trac who uploaded it.
     1201                 * This also allows for SVN imports where the current user is not set.
     1202                 */
     1203                $trac_ticket_reporter = wp_get_current_user()->user_login ?? $this->author->user_login;
     1204
    12011205                // If there's a previous version and the most current version's status is `new`, we update.
    12021206                if (
    … …  
    12151219                                        'type'      => 'theme',
    12161220                                        'keywords'  => implode( ' ', $this->trac_ticket->keywords ),
    1217                                         'reporter'  => $this->author->user_login,
     1221                                        'reporter'  => $trac_ticket_reporter,
    12181222                                        'cc'        => $this->author->user_email,
    12191223                                        'priority'  => $this->trac_ticket->priority,
    … …  
    12271231                                'type'      => 'theme',
    12281232                                'keywords'  => implode( ' ', $this->trac_ticket->keywords ),
    1229                                 'reporter'  => $this->author->user_login,
     1233                                'reporter'  => $trac_ticket_reporter,
    12301234                                'cc'        => $this->author->user_email,
    12311235                                'priority'  => $this->trac_ticket->priority,
    … …  
    15341538                }
    15351539
    1536                 $emails = [
     1540                // Email the Theme Author(s). The uploader & theme author may differ in special cases (default themes).
     1541                $emails = array_filter( array_unique( [
     1542                        // The theme author
    15371543                        $this->author->user_email,
    1538                 ];
    1539 
    1540                 // If the uploader and the author are different, email them both.
    1541                 // This only happens under special circumstances.
    1542                 if (
    1543                         ! empty( $this->theme_post ) &&
    1544                         $this->theme_post->post_author != $this->author->ID
    1545                 ) {
    1546                         $emails[] = get_user_by( 'id', $this->theme_post->post_author )->user_email;
    1547                 }
     1544                        // The theme Author (usually the same)
     1545                        get_user_by( 'id', $this->theme_post->post_author )->user_email ?? false,
     1546                        // The current user (also, usually the same)
     1547                        wp_get_current_user()->user_email
     1548                ] ) );
    15481549
    15491550                wp_mail( $emails, $email_subject, $email_content, 'From: "WordPress Theme Directory" <themes@wordpress.org>' );
Note: See TracChangeset for help on using the changeset viewer.