<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[1378] sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php: WP.org Themes: Process approval and rejection on version update.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/1378">1378</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/1378","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>obenland</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-03-05 04:13:34 +0000 (Thu, 05 Mar 2015)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectorythemedirectoryphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectorythemedirectoryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php      2015-03-04 13:41:31 UTC (rev 1377)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php        2015-03-05 04:13:34 UTC (rev 1378)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -229,24 +229,43 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'pre_insert_term', 'wporg_themes_pre_insert_term' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Returns the status of a theme's version.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Returns the specified meta value for a version of a theme.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param int          $post_id Post ID.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string       $version The theme version to get the status for.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string       $meta_key Post meta key.
+ * @param string       $version Optional. The theme version to get the meta value for. Default: 'latest'.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @return bool|string The version-specific meta value or False on failure.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wporg_themes_get_version_status( $post_id, $version ) {
-       $status = false;
-       $meta   = (array) get_post_meta( $post_id, '_status', true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wporg_themes_get_version_meta( $post_id, $meta_key, $version = 'latest' ) {
+       $value = false;
+       $meta  = (array) get_post_meta( $post_id, $meta_key, true );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        if ( 'latest' == $version ) {
+               $package = new WPORG_Themes_Repo_Package( $post_id );
+               $version = $package->latest_version();
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( ! empty( $meta[ $version ] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $status = $meta[ $version ];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $value = $meta[ $version ];
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        return $status;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $value;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Returns the status of a theme's version.
+ *
+ * @param int          $post_id Post ID.
+ * @param string       $version The theme version to get the status for.
+ * @return bool|string The version-specific meta value or False on failure.
+ */
+function wporg_themes_get_version_status( $post_id, $version ) {
+       return wporg_themes_get_version_meta( $post_id, '_status', $version );
+}
+
+/* UPDATING THEME VERSIONS */
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Handles updating the status of theme versions.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param int       $post_id         Post ID.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -279,10 +298,144 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        break;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * @param int    $post_id         Post ID.
+        * @param string $current_version The theme version that was updated.
+        * @param string $new_status      The new status for that theme version.
+        */
+       do_action( 'wporg_themes_update_version_status', $post_id, $current_version, $new_status );
+
+       /**
+        * The dynamic portion of the hook name, `$new_status`, refers to the new
+        * status of that theme version.
+        *
+        * @param int    $post_id         Post ID.
+        * @param string $current_version The theme version that was updated.
+        */
+       do_action( "wporg_themes_update_version_{$new_status}", $post_id, $current_version );
+
</ins><span class="cx" style="display: block; padding: 0 10px">         return update_post_meta( $post_id, '_status', $meta );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Approves a theme.
+ *
+ * Sets theme version to live, publishes a theme if initially approved, and notifies the theme author.
+ *
+ * @param int    $post_id
+ * @param string $version
+ */
+function wporg_themes_approve_version( $post_id, $version ) {
+       $post      = get_post( $post_id );
+       $ticket_id = wporg_themes_get_version_meta( $post_id, '_ticket_id', $version );
+       $subject = $content = '';
+
+       // TODO: Set locale to theme author language.
+
+       // Congratulate theme author!
+       if ( 'publish' == $post->post_status ) {
+               $subject = sprintf( __( '[WordPress Themes] %1$s %2$s is now live', 'wporg-themes' ), $post->post_title, $version );
+               $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";
+
+       } else {
+               $subject = sprintf( __( '[WordPress Themes] %s has been approved!', 'wporg-themes' ), $post->post_title );
+               $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";
+
+               // First time approval: Publish the theme.
+               wp_publish_post( $post_id );
+       }
+
+       $content .= sprintf( __( 'Any feedback items are at %s.', 'wporg-themes' ), "https://themes.trac.wordpress.org/ticket/$ticket_id" ) . "\n\n--\n";
+       $content .= __( 'The WordPress.org Themes Team', 'wporg-themes' ) . "\n";
+       $content .= 'https://make.wordpress.org/themes';
+
+       wp_mail( get_user_by( 'id', $post->post_author )->user_email, $subject, $content, 'From: themes@wordpress.org' );
+
+       wporg_themes_update_wpthemescom( $post->post_name, $version );
+}
+add_action( 'wporg_themes_update_version_live', 'wporg_themes_approve_version', 10, 2 );
+
+/**
+ * Closes a theme.
+ *
+ * Sets theme version to old and notifies the theme author.
+ *
+ * @param int    $post_id
+ * @param string $version
+ */
+function wporg_themes_close_version( $post_id, $version ) {
+       $post      = get_post( $post_id );
+       $ticket_id = wporg_themes_get_version_meta( $post_id, '_ticket_id', $version );
+
+       // TODO: Set locale to theme author language.
+
+       // Notify theme author.
+       $subject  = sprintf( __( '[WordPress Themes] %s - feedback', 'wporg-themes' ), $post->post_title );
+       $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 );
+       $content .= __( 'The WordPress.org Themes Team', 'wporg-themes' ) . "\n";
+       $content .= 'https://make.wordpress.org/themes';
+
+       wp_mail( get_user_by( 'id', $post->post_author )->user_email, $subject, $content, 'From: themes@wordpress.org' );
+}
+add_action( 'wporg_themes_update_version_old', 'wporg_themes_close_version', 10, 2 );
+
+/**
+ * Updates wp-themes.com with the latest version of a theme.
+ *
+ * @param string $theme_slug
+ * @param string $theme_version
+ */
+function wporg_themes_update_wpthemescom( $theme_slug, $theme_version ) {
+       global $wporg_webs;
+       if ( ! $wporg_webs ) {
+               return;
+       }
+
+       foreach ( $wporg_webs as $server ) {
+               wp_remote_post( "http://$server/", array(
+                       'body'    => array(
+                               'theme_update'        => $theme_slug,
+                               'theme_version'       => $theme_version,
+                               'theme_action'        => 'update',
+                               'theme_update_secret' => THEME_PREVIEWS_SYNC_SECRET,
+                       ),
+                       'headers' => array(
+                               'Host' => 'wp-themes.com',
+                       ),
+               ) );
+       }
+}
+
+/**
+ * Completely removes a theme from wp-themes.com.
+ *
+ * This method is currently not in use.
+ *
+ * @param string $theme_slug
+ */
+function wporg_themes_remove_wpthemescom( $theme_slug ) {
+       global $wporg_webs;
+       if ( ! $wporg_webs ) {
+               return;
+       }
+
+       foreach ( $wporg_webs as $server ) {
+               wp_remote_post( "http://$server/", array(
+                       'body'    => array(
+                               'theme_update'        => $theme_slug,
+                               'theme_action'        => 'remove',
+                               'theme_update_secret' => THEME_PREVIEWS_SYNC_SECRET,
+                       ),
+                       'headers' => array(
+                               'Host' => 'wp-themes.com',
+                       ),
+               ) );
+       }
+}
+
+/* REPOPACKAGE EDITOR ENHANCEMENTS */
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Use theme screen shot for post thumbnails.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string $html
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -302,7 +455,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'post_thumbnail_html', 'wporg_themes_post_thumbnail_html', 10, 5 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * Prevents repopackages from being deleted.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span></span></pre>
</div>
</div>

</body>
</html>