Making WordPress.org


Ignore:
Timestamp:
03/05/2015 04:13:34 AM (9 years ago)
Author:
obenland
Message:

WP.org Themes: Process approval and rejection on version update.

This brings most of the trac review sync helper functions over to the plugin
and allows for manual approval and rejection from wp-admin.

The sync script can now be simplified to just calling
wporg_themes_update_version_status() with the correct status parameter.

File:
1 edited

Legend:

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

    r1376 r1378  
    230230
    231231/**
     232 * Returns the specified meta value for a version of a theme.
     233 *
     234 * @param int          $post_id Post ID.
     235 * @param string       $meta_key Post meta key.
     236 * @param string       $version Optional. The theme version to get the meta value for. Default: 'latest'.
     237 * @return bool|string The version-specific meta value or False on failure.
     238 */
     239function wporg_themes_get_version_meta( $post_id, $meta_key, $version = 'latest' ) {
     240    $value = false;
     241    $meta  = (array) get_post_meta( $post_id, $meta_key, true );
     242
     243    if ( 'latest' == $version ) {
     244        $package = new WPORG_Themes_Repo_Package( $post_id );
     245        $version = $package->latest_version();
     246    }
     247
     248    if ( ! empty( $meta[ $version ] ) ) {
     249        $value = $meta[ $version ];
     250    }
     251
     252    return $value;
     253}
     254
     255/**
    232256 * Returns the status of a theme's version.
    233257 *
     
    237261 */
    238262function wporg_themes_get_version_status( $post_id, $version ) {
    239     $status = false;
    240     $meta   = (array) get_post_meta( $post_id, '_status', true );
    241 
    242     if ( ! empty( $meta[ $version ] ) ) {
    243         $status = $meta[ $version ];
    244     }
    245 
    246     return $status;
    247 }
     263    return wporg_themes_get_version_meta( $post_id, '_status', $version );
     264}
     265
     266/* UPDATING THEME VERSIONS */
    248267
    249268/**
     
    280299    }
    281300
     301    /**
     302     * @param int    $post_id         Post ID.
     303     * @param string $current_version The theme version that was updated.
     304     * @param string $new_status      The new status for that theme version.
     305     */
     306    do_action( 'wporg_themes_update_version_status', $post_id, $current_version, $new_status );
     307
     308    /**
     309     * The dynamic portion of the hook name, `$new_status`, refers to the new
     310     * status of that theme version.
     311     *
     312     * @param int    $post_id         Post ID.
     313     * @param string $current_version The theme version that was updated.
     314     */
     315    do_action( "wporg_themes_update_version_{$new_status}", $post_id, $current_version );
     316
    282317    return update_post_meta( $post_id, '_status', $meta );
    283318}
     319
     320/**
     321 * Approves a theme.
     322 *
     323 * Sets theme version to live, publishes a theme if initially approved, and notifies the theme author.
     324 *
     325 * @param int    $post_id
     326 * @param string $version
     327 */
     328function wporg_themes_approve_version( $post_id, $version ) {
     329    $post      = get_post( $post_id );
     330    $ticket_id = wporg_themes_get_version_meta( $post_id, '_ticket_id', $version );
     331    $subject = $content = '';
     332
     333    // TODO: Set locale to theme author language.
     334
     335    // Congratulate theme author!
     336    if ( 'publish' == $post->post_status ) {
     337        $subject = sprintf( __( '[WordPress Themes] %1$s %2$s is now live', 'wporg-themes' ), $post->post_title, $version );
     338        $content = sprintf( __( 'Version %1$s of %2$s is now live at https://wordpress.org/themes/%3$s.', 'wporg-themes' ), $version, $post->post_title, $post->post_name ) . "\n\n";
     339
     340    } else {
     341        $subject = sprintf( __( '[WordPress Themes] %s has been approved!', 'wporg-themes' ), $post->post_title );
     342        $content = sprintf( __( 'Congratulations, your new theme %1$s is now available to the public at https://wordpress.org/themes/%2$s.', 'wporg-themes' ), $post->post_title, $post->post_name ) . "\n\n";
     343
     344        // First time approval: Publish the theme.
     345        wp_publish_post( $post_id );
     346    }
     347
     348    $content .= sprintf( __( 'Any feedback items are at %s.', 'wporg-themes' ), "https://themes.trac.wordpress.org/ticket/$ticket_id" ) . "\n\n--\n";
     349    $content .= __( 'The WordPress.org Themes Team', 'wporg-themes' ) . "\n";
     350    $content .= 'https://make.wordpress.org/themes';
     351
     352    wp_mail( get_user_by( 'id', $post->post_author )->user_email, $subject, $content, 'From: themes@wordpress.org' );
     353
     354    wporg_themes_update_wpthemescom( $post->post_name, $version );
     355}
     356add_action( 'wporg_themes_update_version_live', 'wporg_themes_approve_version', 10, 2 );
     357
     358/**
     359 * Closes a theme.
     360 *
     361 * Sets theme version to old and notifies the theme author.
     362 *
     363 * @param int    $post_id
     364 * @param string $version
     365 */
     366function wporg_themes_close_version( $post_id, $version ) {
     367    $post      = get_post( $post_id );
     368    $ticket_id = wporg_themes_get_version_meta( $post_id, '_ticket_id', $version );
     369
     370    // TODO: Set locale to theme author language.
     371
     372    // Notify theme author.
     373    $subject  = sprintf( __( '[WordPress Themes] %s - feedback', 'wporg-themes' ), $post->post_title );
     374    $content  = sprintf( __( 'Feedback for the %1$s theme is at https://themes.trac.wordpress.org/ticket/%2$s', 'wporg' ) . "\n\n--\n", $post->post_title, $ticket_id );
     375    $content .= __( 'The WordPress.org Themes Team', 'wporg-themes' ) . "\n";
     376    $content .= 'https://make.wordpress.org/themes';
     377
     378    wp_mail( get_user_by( 'id', $post->post_author )->user_email, $subject, $content, 'From: themes@wordpress.org' );
     379}
     380add_action( 'wporg_themes_update_version_old', 'wporg_themes_close_version', 10, 2 );
     381
     382/**
     383 * Updates wp-themes.com with the latest version of a theme.
     384 *
     385 * @param string $theme_slug
     386 * @param string $theme_version
     387 */
     388function wporg_themes_update_wpthemescom( $theme_slug, $theme_version ) {
     389    global $wporg_webs;
     390    if ( ! $wporg_webs ) {
     391        return;
     392    }
     393
     394    foreach ( $wporg_webs as $server ) {
     395        wp_remote_post( "http://$server/", array(
     396            'body'    => array(
     397                'theme_update'        => $theme_slug,
     398                'theme_version'       => $theme_version,
     399                'theme_action'        => 'update',
     400                'theme_update_secret' => THEME_PREVIEWS_SYNC_SECRET,
     401            ),
     402            'headers' => array(
     403                'Host' => 'wp-themes.com',
     404            ),
     405        ) );
     406    }
     407}
     408
     409/**
     410 * Completely removes a theme from wp-themes.com.
     411 *
     412 * This method is currently not in use.
     413 *
     414 * @param string $theme_slug
     415 */
     416function wporg_themes_remove_wpthemescom( $theme_slug ) {
     417    global $wporg_webs;
     418    if ( ! $wporg_webs ) {
     419        return;
     420    }
     421
     422    foreach ( $wporg_webs as $server ) {
     423        wp_remote_post( "http://$server/", array(
     424            'body'    => array(
     425                'theme_update'        => $theme_slug,
     426                'theme_action'        => 'remove',
     427                'theme_update_secret' => THEME_PREVIEWS_SYNC_SECRET,
     428            ),
     429            'headers' => array(
     430                'Host' => 'wp-themes.com',
     431            ),
     432        ) );
     433    }
     434}
     435
     436/* REPOPACKAGE EDITOR ENHANCEMENTS */
    284437
    285438/**
     
    302455}
    303456add_filter( 'post_thumbnail_html', 'wporg_themes_post_thumbnail_html', 10, 5 );
    304 
    305457
    306458/**
Note: See TracChangeset for help on using the changeset viewer.