Making WordPress.org

Ticket #4039: 4039.diff

File 4039.diff, 4.6 KB (added by dd32, 6 years ago)
  • class-wporg-themes-upload.php

    class WPORG_Themes_Upload { 
    234234                        /* translators: %s: parent theme */
    235235                        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' ),
    236236                                '<code>' . $this->theme->parent() . '</code>'
    237237                        );
    238238                }
    239239
    240240                // Is there already a theme with the name name by a different author?
    241241                if ( ! empty( $this->theme_post ) && $this->theme_post->post_author != $this->author->ID ) {
    242242                        /* translators: 1: theme slug, 2: style.css */
    243243                        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' ),
    244244                                '<code>' . $this->theme_slug . '</code>',
    245245                                '<code>style.css</code>'
    246246                        );
    247247                }
    248248
     249                // Check if the ThemeURI is already in use by another theme by another author.
     250                if ( $theme_uri = $this->theme->get( 'ThemeURI' ) ) {
     251                        $theme_uris_matches = get_posts( array(
     252                                'post_type'        => 'repopackage',
     253                                'post_status'      => array( 'publish' ),
     254                                'suppress_filters' => true, // This prevents the date-based query mods from running.
     255                                'meta_query'       => array(
     256                                        array(
     257                                                'key'     => '_theme_url',
     258                                                'value'   => '"' . $theme_uri . '"', // Searching within a Serialized PHP value
     259                                                'compare' => 'LIKE'
     260                                        )
     261                                )
     262                        ) );
     263                        $theme_owners = wp_list_pluck( $theme_uris_matches, 'post_author' );
     264
     265                        if ( $theme_owners && ! in_array( $this->author->ID, $theme_owners ) ) {
     266                                return sprintf(
     267                                        __( 'There is already a theme using the Theme URL %s by a different author. TODO Please change ??? TODO', 'wporg-themes' ),
     268                                        '<code>' . esc_html( $theme_uri ) . '</code>'
     269                                );
     270                        }
     271                }
     272
    249273                // We know it's the correct author, now we can check if it's suspended.
    250274                if ( ! empty( $this->theme_post ) && 'suspend' === $this->theme_post->post_status ) {
    251275                        /* translators: %s: mailto link */
    252276                        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' ),
    253277                                '<a href="mailto:themes@wordpress.org">themes@wordpress.org</a>'
    254278                        );
    255279                }
    256280
    257281                // Don't send special themes through Theme Check.
    258282                if ( ! has_category( 'special-case-theme', $this->theme_post ) ) {
    259283                        // Pass it through Theme Check and see how great this theme really is.
    260284                        $result = $this->check_theme( $theme_files );
    261285
    262286                        if ( ! $result ) {
    263287                                /* translators: 1: Theme Check Plugin URL, 2: make.wordpress.org/themes */
  • query-modifications.php

    function wporg_themes_pre_get_posts( $qu 
    9696                        // Only include themes that have existed for at least 2 weeks into the popular listing
    9797                        // This avoids cases where a new theme skews our popularity algorithms.
    9898                        $query->query_vars['date_query']['existing_themes_only'] = array(
    9999                                'column' => 'post_date',
    100100                                'before'  => date( 'Y-m-d', strtotime( '-2 weeks' ) )
    101101                        );
    102102
    103103                        // Sort by the popularity meta key
    104104                        $query->query_vars['meta_key'] = '_popularity';
    105105                        $query->query_vars['meta_type'] = 'DECIMAL(20,10)';
    106106                        $query->query_vars['orderby'] = 'meta_value DESC';
    107107                        break;
    108108        }
    109109
    110110        // Unless a specific theme, or author is being requested, limit results to the last 2 years.
    111         if ( empty( $query->query_vars['name'] ) && empty( $query->query_vars['author_name'] ) && ! in_array( $query->query_vars['browse'], array( 'favorites', 'new', 'updated' ) ) ) {
     111        if ( empty( $query->query_vars['suppress_filters'] ) && empty( $query->query_vars['name'] ) && empty( $query->query_vars['author_name'] ) && ! in_array( $query->query_vars['browse'], array( 'favorites', 'new', 'updated' ) ) ) {
    112112                $query->query_vars['date_query']['recent_themes_only'] = array(
    113113                        'column' => 'post_modified',
    114114                        'after'  => date( 'Y-m-d', strtotime( '-2 years' ) ),
    115115                );
    116116        }
    117117
    118118        // Prioritize translated themes for localized requests, except when viewing a specific ordered themes.
    119119        if ( 'en_US' !== get_locale() && ! in_array( $query->query_vars['browse'], array( 'favorites', 'new', 'updated' ) )  ) {
    120120                add_filter( 'posts_clauses', 'wporg_themes_prioritize_translated_posts_clauses' );
    121121        }
    122122
    123123}
    124124add_action( 'pre_get_posts', 'wporg_themes_pre_get_posts' );
    125125
    126126/**