Making WordPress.org

Changeset 1397


Ignore:
Timestamp:
03/13/2015 12:04:27 PM (9 years ago)
Author:
obenland
Message:

WP.org Themes: Don't update theme post until new version was approved.

Theme description and tags might change in new versions, so the post can't be
updated with that new information until that version has been approved.

This also fixes a bug where the post date would be set to the upload date of
the new version, mixing new themes with updated themes in the Latest Themes
view in the Directory.

Fixes #943.

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

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/admin-edit.php

    r1395 r1397  
    392392    }
    393393
     394    // Only run once.
     395    remove_action( 'save_post', __FUNCTION__ );
     396
    394397    $new_status = array();
    395398    foreach ( $_POST['wporg_themes_status'] as $version => $status ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php

    r1385 r1397  
    525525    public function create_or_update_theme_post( $ticket_id ) {
    526526        $upload_date = current_time( 'mysql' );
    527         $post_args   = array(
    528             'post_author'    => $this->author->ID,
    529             'post_title'     => $this->theme->get( 'Name' ),
    530             'post_name'      => $this->theme_slug,
    531             'post_content'   => $this->theme->get( 'Description' ),
    532             'post_parent'    => $this->theme->post_parent,
    533             'post_date'      => $upload_date,
    534             'comment_status' => 'closed',
    535             'ping_status'    => 'closed',
    536             'post_type'      => 'repopackage',
    537             'tags_input'     => $this->theme->get( 'Tags' ),
    538         );
    539 
    540         // If we already have a post, update it.
     527
     528        // If we already have a post, get its ID.
    541529        if ( ! empty( $this->theme_post ) ) {
    542             $post_args['ID'] = $this->theme_post->ID;
    543 
    544             $post_id = wp_update_post( $post_args );
    545 
    546             // Otherwise create it for this new theme.
     530            $post_id = $this->theme_post->ID;
     531
     532        // Otherwise create it for this new theme.
    547533        } else {
    548             $post_id = wp_insert_post( $post_args );
     534            $post_id = wp_insert_post( array(
     535                'post_author'    => $this->author->ID,
     536                'post_title'     => $this->theme->get( 'Name' ),
     537                'post_name'      => $this->theme_slug,
     538                'post_content'   => $this->theme->get( 'Description' ),
     539                'post_parent'    => $this->theme->post_parent,
     540                'post_date'      => $upload_date,
     541                'post_date_gmt'  => $upload_date,
     542                'comment_status' => 'closed',
     543                'ping_status'    => 'closed',
     544                'post_type'      => 'repopackage',
     545                'tags_input'     => $this->theme->get( 'Tags' ),
     546            ) );
    549547        }
    550548
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    r1395 r1397  
    339339    wporg_themes_update_wpthemescom( $post->post_name, $version );
    340340
     341    // Update the post with this version's description and tags.
     342    $theme_data = wporg_themes_get_header_data( sprintf( 'https://themes.svn.wordpress.org/%1$s/%2$s/style.css', $post->post_name, $version ) );
     343    wp_update_post( array(
     344        'ID'           => $post_id,
     345        'post_content' => $theme_data['Description'],
     346        'tags_input'   => $theme_data['Tags'],
     347    ) );
     348
    341349    /*
    342350     * Bail if we're activating an old version, the author does not need to be
     
    499507    }
    500508}
     509
     510/**
     511 * Custom version of core's deprecated `get_theme_data()` function.
     512 *
     513 * @param string $theme_file Path to the file.
     514 * @return array File headers.
     515 */
     516function wporg_themes_get_header_data( $theme_file ) {
     517    $themes_allowed_tags = array(
     518        'a'       => array(
     519            'href'  => array(),
     520            'title' => array(),
     521        ),
     522        'abbr'    => array(
     523            'title' => array(),
     524        ),
     525        'acronym' => array(
     526            'title' => array(),
     527        ),
     528        'code'    => array(),
     529        'em'      => array(),
     530        'strong'  => array(),
     531    );
     532
     533    $theme_data = implode( '', file( $theme_file ) );
     534    $theme_data = str_replace( '\r', '\n', $theme_data );
     535    preg_match( '|^[ \t\/*#@]*Theme Name:(.*)$|mi', $theme_data, $theme_name );
     536    preg_match( '|^[ \t\/*#@]*Theme URI:(.*)$|mi', $theme_data, $theme_uri );
     537    preg_match( '|^[ \t\/*#@]*Description:(.*)$|mi', $theme_data, $description );
     538
     539    if ( preg_match( '|^[ \t\/*#@]*Author URI:(.*)$|mi', $theme_data, $author_uri ) ) {
     540        $author_uri = esc_url( trim( $author_uri[1] ) );
     541    } else {
     542        $author_uri = '';
     543    }
     544
     545    if ( preg_match( '|^[ \t\/*#@]*Template:(.*)$|mi', $theme_data, $template ) ) {
     546        $template = wp_kses( trim( $template[1] ), $themes_allowed_tags );
     547    } else {
     548        $template = '';
     549    }
     550
     551    if ( preg_match( '|^[ \t\/*#@]*Version:(.*)$|mi', $theme_data, $version ) ) {
     552        $version = wp_kses( trim( $version[1] ), $themes_allowed_tags );
     553    } else {
     554        $version = '';
     555    }
     556
     557    if ( preg_match( '|^[ \t\/*#@]*Status:(.*)$|mi', $theme_data, $status ) ) {
     558        $status = wp_kses( trim( $status[1] ), $themes_allowed_tags );
     559    } else {
     560        $status = 'publish';
     561    }
     562
     563    if ( preg_match( '|^[ \t\/*#@]*Tags:(.*)$|mi', $theme_data, $tags ) ) {
     564        $tags = array_map( 'trim', explode( ',', wp_kses( trim( $tags[1] ), array() ) ) );
     565    } else {
     566        $tags = array();
     567    }
     568
     569    if ( preg_match( '|^[ \t\/*#@]*Author:(.*)$|mi', $theme_data, $author_name ) ) {
     570        $author = wp_kses( trim( $author_name[1] ), $themes_allowed_tags );
     571    } else {
     572        $author = 'Anonymous';
     573    }
     574
     575    $name        = $theme = wp_kses( trim( $theme_name[1] ), $themes_allowed_tags );
     576    $theme_uri   = esc_url( trim( $theme_uri[1] ) );
     577    $description = wp_kses( trim( $description[1] ), $themes_allowed_tags );
     578
     579    return array(
     580        'Name'        => $name,
     581        'Title'       => $theme,
     582        'URI'         => $theme_uri,
     583        'Description' => $description,
     584        'Author'      => $author,
     585        'Author_URI'  => $author_uri,
     586        'Version'     => $version,
     587        'Template'    => $template,
     588        'Status'      => $status,
     589        'Tags'        => $tags,
     590    );
     591}
Note: See TracChangeset for help on using the changeset viewer.