Making WordPress.org


Ignore:
Timestamp:
04/27/2021 03:08:01 AM (4 years ago)
Author:
dd32
Message:

Theme Directory: Allow default theme uploads by core committers.

This allows the twenty* themes to be updated by any current core committer, removing the need for an extra special person available during release windows.

Trac will reflect the user who uploads the theme, but the theme will remain owned by WordPress.org.

New default themes will still be limited to being uploaded by the WordPress.org user, this only controls updates.

File:
1 edited

Legend:

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

    r10923 r10927  
    240240
    241241        // Make sure it doesn't use a slug deemed not to be used by the public.
     242        // This check must be run before `get_theme_post()` to account for "twenty" themes.
    242243        if ( $this->has_reserved_slug() ) {
    243244            /* translators: 1: theme slug, 2: style.css */
     
    327328        // Is there already a theme with the name name by a different author?
    328329        if ( ! empty( $this->theme_post ) && $this->theme_post->post_author != $this->author->ID ) {
    329             /* translators: 1: theme slug, 2: style.css */
    330             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' ),
    331                 '<code>' . $this->theme_slug . '</code>',
    332                 '<code>style.css</code>'
    333             ) . $are_you_in_the_right_place;
     330
     331            $is_allowed_to_upload_for_theme = false;
     332            if (
     333                // The theme is owned by WordPress.org.
     334                'wordpressdotorg' === get_user_by( 'id', $this->theme_post->post_author )->user_nicename &&
     335                // The current user is a Core Committer. [ 'user_login' => 'Trac Title', ... ]
     336                ! empty( $GLOBALS['committers'][ $this->author->user_login ] )
     337            ) {
     338                // Allow core committers to update default themes (as authored by @wordpressdotorg)
     339                $is_allowed_to_upload_for_theme = true;
     340            }
     341
     342            if ( ! $is_allowed_to_upload_for_theme ) {
     343                /* 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                    '<code>' . $this->theme_slug . '</code>',
     346                    '<code>style.css</code>'
     347                ) . $are_you_in_the_right_place;
     348            }
    334349        }
    335350
     
    674689        );
    675690
    676         // force the slug to be correct for the twenty-x themes
    677         if ( in_array( $slug, $reserved_slugs ) && 'wordpressdotorg' == $this->author->user_login ) {
    678             $this->theme_slug = $slug;
    679         }
    680 
    681         return in_array( $slug, $reserved_slugs ) && 'wordpressdotorg' !== $this->author->user_login;
     691        // If it's not a reserved slug, they can have it.
     692        if (
     693            ! in_array( $slug, $reserved_slugs, true ) &&
     694            ! in_array( $this->theme_slug, $reserved_slugs, true )
     695        ) {
     696            return false;
     697        }
     698
     699        // force the slug to be correct for the twenty-x themes.
     700        $this->theme_slug = $slug;
     701
     702        // WordPress.org user is always allowed to upload reserved slugs.
     703        if ( 'wordpressdotorg' === $this->author->user_login ) {
     704            return false;
     705        }
     706
     707        // Only committers uploading a default theme *update* are left to be checked for.
     708        $theme_post = $this->get_theme_post();
     709
     710        // New default themes MUST be uploaded by `wordpressdotorg` and will fail this check.
     711        if (
     712            // Updates only.
     713            $theme_post &&
     714            // The current user is a Core Committer. [ 'user_login' => 'Trac Title', ... ]
     715            ! empty( $GLOBALS['committers'][ $this->author->user_login ] ) &&
     716            // The theme is owned by WordPress.org.
     717            'wordpressdotorg' === get_user_by( 'id', $theme_post->post_author )->user_login
     718        ) {
     719            // Slug is reserved, but an update is being uploaded by a core committer.
     720            return false;
     721        }
     722
     723        // Slug is reserved, user is not authorized.
     724        return true;
    682725    }
    683726
     
    11461189        }
    11471190
    1148         wp_mail( $this->author->user_email, $email_subject, $email_content, 'From: "WordPress Theme Directory" <themes@wordpress.org>' );
     1191        $emails = [
     1192            $this->author->user_email,
     1193        ];
     1194
     1195        // If the uploader and the author are different, email them both.
     1196        // This only happens under special circumstances.
     1197        if ( ! empty( $this->theme_post ) && $this->theme_post->post_author != $this->author->ID ) {
     1198            $emails[] = get_user_by( 'id', $this->theme_post->post_author )->user_email;
     1199        }
     1200
     1201        wp_mail( $emails, $email_subject, $email_content, 'From: "WordPress Theme Directory" <themes@wordpress.org>' );
    11491202    }
    11501203
Note: See TracChangeset for help on using the changeset viewer.