Making WordPress.org


Ignore:
Timestamp:
02/27/2015 06:03:24 PM (11 years ago)
Author:
Otto42
Message:

Determine proper theme-slug and use it everywhere instead of relying on WP_Theme to give it to us, because WP_Theme returns the directory name. This makes sense for WP_Theme in core, where the directory name is needed to find the theme, however here we need the sanitized version of the theme name to detemine the slug in the directory and in SVN.

File:
1 edited

Legend:

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

    r1346 r1349  
    108108                // We have a stylesheet, let's set up the theme, theme post, and author.
    109109                $this->theme      = new WP_Theme( basename( dirname( $style_css ) ), dirname( dirname( $style_css ) ) );
    110                 $this->theme_post = $this->get_theme_post();
    111                 $this->author     = wp_get_current_user();
    112110
    113111                // We need a screen shot. People love screen shots.
     
    121119                // Let's check some theme headers, shall we?
    122120
    123                 if ( ! $this->theme->get( 'Name' ) ) {
     121                if ( ! $this->theme_name = $this->theme->get( 'Name' ) ) {
    124122                        return __( "The theme has no name. Add it to style.css and upload the theme again. <a href='https://codex.wordpress.org/Theme_Development#Theme_Style_Sheet'>Theme Style Sheets</a>", 'wporg-themes' );
    125123                }
     124
     125                // determine the theme slug based on the name of the theme in the stylesheet
     126                $this->theme_slug = sanitize_title_with_dashes( $this->theme_name );
     127
     128                // populate the theme post and author
     129                $this->theme_post = $this->get_theme_post();
     130                $this->author     = wp_get_current_user();
    126131
    127132                $theme_description = $this->strip_non_utf8( (string) $this->theme->get( 'Description' ) );
     
    144149                // Make sure we have version that is higher than any previously uploaded version of this theme.
    145150                if ( ! empty( $this->theme_post ) && ! version_compare( $this->theme->get( 'Version' ), $this->theme_post->max_version, '>' ) ) {
    146                         return sprintf( __( 'You need to upload a version of %1$s higher than %2$s. Increase the theme version number in <code>style.css</code>, then upload your zip file again.', 'wporg-themes' ), $this->theme->display( 'Name' ), '<code>' . $this->theme->display( 'Version' ) . '</code>' );
     151                        return sprintf( __( 'You need to upload a version of %1$s higher than %2$s. Increase the theme version number in <code>style.css</code>, then upload your zip file again.', 'wporg-themes' ), $this->theme->display( 'Name' ), '<code>' . $this->theme_post->max_version . '</code>' );
    147152                }
    148153
     
    159164                // Make sure it doesn't use a slug deemed not to be used by the public.
    160165                if ( $this->has_reserved_slug() ) {
    161                         return sprintf( __( 'Sorry, the theme name %s is reserved for use by WordPress Core. Please change the name of your theme in <code>style.css</code> and upload it again.', 'wporg-themes' ), '<code>' . $this->theme->get_stylesheet() . '</code>' );
     166                        return sprintf( __( 'Sorry, the theme name %s is reserved for use by WordPress Core. Please change the name of your theme in <code>style.css</code> and upload it again.', 'wporg-themes' ), '<code>' . $this->theme_slug . '</code>' );
    162167                }
    163168
    164169                // Is there already a theme with the name name by a different author?
    165170                if ( ! empty( $this->theme_post ) && $this->theme_post->post_author != $this->author->ID ) {
    166                         return sprintf( __( 'There is already a theme called %s by a different author. Please change the name of your theme in <code>style.css</code> and upload it again.', 'wporg-themes' ), '<code>' . $this->theme->get_stylesheet() . '</code>' );
     171                        return sprintf( __( 'There is already a theme called %s by a different author. Please change the name of your theme in <code>style.css</code> and upload it again.', 'wporg-themes' ), '<code>' . $this->theme_slug . '</code>' );
    167172                }
    168173
     
    276281        public function get_theme_post() {
    277282                $themes = get_posts( array(
    278                         'name'             => $this->theme->get_stylesheet(),
     283                        'name'             => $this->theme_slug,
    279284                        'posts_per_page'   => 1,
    280285                        'post_type'        => 'repopackage',
     
    345350                        array( 'twenty-ten', 'twenty-eleven', 'twenty-twelve', 'twenty-thirteen', 'twenty-fourteen', 'twenty-fifteen', 'twenty-sixteen', 'twenty-seventeen', 'twenty-eighteen', 'twenty-nineteen', 'twenty-twenty' ),
    346351                        array( 'twentyten',  'twentyeleven',  'twentytwelve',  'twentythirteen',  'twentyfourteen',  'twentyfifteen',  'twentysixteen',  'twentyseventeen',  'twentyeighteen',  'twentynineteen',  'twentytwenty'  ),
    347                         $this->theme->get_stylesheet()
     352                        $this->theme_slug
    348353                );
    349354
     
    403408                // Keywords
    404409                $this->trac_ticket->keywords = array(
    405                         'theme-' . $this->theme->get_stylesheet(),
     410                        'theme-' . $this->theme_slug,
    406411                );
    407412
     
    438443                $this->trac_ticket->diff_line = '';
    439444                if ( ! empty( $this->theme_post->max_version ) ) {
    440                         $this->trac_ticket->diff_line = "\n" . sprintf( __( 'Diff with previous version: %s', 'wporg-themes' ), "https://themes.trac.wordpress.org/changeset?old_path={$this->theme->get_stylesheet()}/{$this->theme_post->max_version}&new_path={$this->theme->get_stylesheet()}/{$this->theme->display( 'Version' )}\n" );
     445                        $this->trac_ticket->diff_line = "\n" . sprintf( __( 'Diff with previous version: %s', 'wporg-themes' ), "https://themes.trac.wordpress.org/changeset?old_path={$this->theme_slug}/{$this->theme_post->max_version}&new_path={$this->theme_slug}/{$this->theme->display( 'Version' )}\n" );
    441446                }
    442447
     
    450455Author URL - {$this->theme->display( 'AuthorURI' )}
    451456
    452 SVN - https://themes.svn.wordpress.org/{$this->theme->get_stylesheet()}/{$this->theme->display( 'Version' )}
    453 ZIP - https://wordpress.org/themes/download/{$this->theme->get_stylesheet()}.{$this->theme->display( 'Version' )}.zip?nostats=1
     457SVN - https://themes.svn.wordpress.org/{$this->theme_slug}/{$this->theme->display( 'Version' )}
     458ZIP - https://wordpress.org/themes/download/{$this->theme_slug}.{$this->theme->display( 'Version' )}.zip?nostats=1
    454459{$this->trac_ticket->parent_link}
    455460{$this->trac_ticket->diff_line}
    456461History:
    457 [[TicketQuery(format=table, keywords=~theme-{$this->theme->get_stylesheet()}, col=id|summary|status|resolution|owner)]]
    458 
    459 [[Image(https://themes.svn.wordpress.org/{$this->theme->get_stylesheet()}/{$this->theme->display( 'Version' )}/{$this->theme->screenshot}, width=640)]]
     462[[TicketQuery(format=table, keywords=~theme-{$this->theme_slug}, col=id|summary|status|resolution|owner)]]
     463
     464[[Image(https://themes.svn.wordpress.org/{$this->theme_slug}/{$this->theme->display( 'Version' )}/{$this->theme->screenshot}, width=640)]]
    460465TICKET;
    461466        }
     
    513518                        'post_author'    => $this->author->ID,
    514519                        'post_title'     => $this->theme->get( 'Name' ),
    515                         'post_name'      => $this->theme->get_stylesheet(),
     520                        'post_name'      => $this->theme_slug,
    516521                        'post_content'   => $this->theme->get( 'Description' ),
    517522                        'post_parent'    => $this->theme->post_parent,
     
    563568                $import_msg = empty( $this->theme_post ) ?  __( 'New theme: %1$s - %2$s', 'wporg-themes' ) : __( 'New version of %1$s - %2$s', 'wporg-themes' );
    564569                $import_msg = escapeshellarg( sprintf( $import_msg, $this->theme->display( 'Name' ), $this->theme->display( 'Version' ) ) );
    565                 $svn_path   = escapeshellarg( "https://themes.svn.wordpress.org/{$this->theme->get_stylesheet()}/{$this->theme->display( 'Version' )}" );
     570                $svn_path   = escapeshellarg( "https://themes.svn.wordpress.org/{$this->theme_slug}/{$this->theme->display( 'Version' )}" );
    566571                $theme_path = escapeshellarg( $this->theme_dir );
    567572                $svn        = escapeshellarg( self::SVN );
Note: See TracChangeset for help on using the changeset viewer.