<!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>[1395] sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory: WP.org Themes: Add a custom post status for suspended themes.</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/1395">1395</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/1395","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-11 22:55:10 +0000 (Wed, 11 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: Add a custom post status for suspended themes.

Fixes <a href="http://meta.trac.wordpress.org/ticket/949">#949</a>.</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>

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

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryadmineditphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/admin-edit.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/admin-edit.php                           (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/admin-edit.php     2015-03-11 22:55:10 UTC (rev 1395)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,406 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Adjustments to the edit.php screen for repopackage posts.
+ */
+
+/**
+ * Adds custom capabilities on plugin activation.
+ */
+function wporg_themes_add_caps() {
+
+       // Give Editors and higher the ability to suspend and reinstate a theme.
+       foreach ( array( 'administrator', 'author', 'editor' ) as $role ) {
+               $wp_roles = get_role( $role );
+
+               $wp_roles->add_cap( 'suspend_themes' );
+               $wp_roles->add_cap( 'reinstate_themes' );
+       }
+}
+add_action( 'wporg_themes_activation', 'wporg_themes_add_caps' );
+
+/**
+ * Removes custom capabilities on plugin deactivation.
+ */
+function wporg_themes_remove_caps() {
+       foreach ( array( 'administrator', 'author', 'editor' ) as $role ) {
+               $wp_roles = get_role( $role );
+
+               $wp_roles->remove_cap( 'suspend_themes' );
+               $wp_roles->remove_cap( 'reinstate_themes' );
+       }
+}
+add_action( 'wporg_themes_deactivation', 'wporg_themes_remove_caps' );
+
+/**
+ * Registers custom post status for suspended themes.
+ */
+function wporg_themes_post_status() {
+
+       // Themes can be "suspended" to hide them.
+       register_post_status( 'suspend', array(
+               'label'                     => __( 'Suspended', 'wporg-themes' ),
+               'public'                    => false,
+               'exclude_from_search'       => true,
+               'show_in_admin_all_list'    => true,
+               'show_in_admin_status_list' => true,
+               'label_count'               => _n_noop( 'Suspended <span class="count">(%s)</span>', 'Suspended <span class="count">(%s)</span>', 'wporg-themes' ),
+       ) );
+}
+add_action( 'init', 'wporg_themes_post_status' );
+
+/**
+ * Capability mapping for custom caps.
+ *
+ * @param array  $caps Returns the user's actual capabilities.
+ * @param string $cap  Capability name.
+ * @return array
+ */
+function wporg_themes_map_meta_cap( $caps, $cap ) {
+       switch ( $cap ) {
+               case 'delete_categories':
+               case 'edit_categories':
+               case 'manage_categories':
+
+                       if ( ! is_super_admin() ) {
+                               $caps[] = 'do_not_allow';
+                       }
+                       break;
+
+               case 'suspend_theme':
+                       $caps[] = 'suspend_themes';
+                       unset( $caps[ array_search( $cap, $caps ) ] );
+                       break;
+
+               case 'reinstate_theme':
+                       $caps[] = 'reinstate_themes';
+                       unset( $caps[ array_search( $cap, $caps ) ] );
+                       break;
+       }
+
+       return $caps;
+}
+add_filter( 'map_meta_cap', 'wporg_themes_map_meta_cap', 10, 2 );
+
+/**
+ * Adds suspend and reinstate actions.
+ *
+ * @param array   $actions
+ * @param WP_Post $post
+ * @return array
+ */
+function wporg_themes_post_row_actions( $actions, $post ) {
+       if ( 'repopackage' == $post->post_type ) {
+               $before = array_slice( $actions, 0, - 1, true );
+               $after  = array_slice( $actions, - 1, 1, true );
+               $custom = array();
+
+               if ( current_user_can( 'reintate_theme', $post->ID ) && 'suspend' == $post->post_status ) {
+                       $custom = array( 'reintate' => sprintf( '<a class="submit-reinstate_theme" title="%1$s" href="%2$s">%3$s</a>', esc_attr__( 'Reinstate this item', 'wporg-themes' ), esc_url( wporg_themes_get_reinstate_url( $post ) ), __( 'Reinstate', 'wporg-themes' ) ) );
+               }
+               elseif ( current_user_can( 'suspend_theme', $post->ID ) ) {
+                       $custom = array( 'suspend' => sprintf( '<a class="submit-suspend_theme" title="%1$s" href="%2$s">%3$s</a>', esc_attr__( 'Suspend this item', 'wporg-themes' ), esc_url( wporg_themes_get_suspend_url( $post ) ), __( 'Suspend', 'wporg-themes' ) ) );
+               }
+
+               $actions = array_merge( $before, $custom, $after );
+       }
+
+       return $actions;
+}
+add_filter( 'post_row_actions', 'wporg_themes_post_row_actions', 10, 2 );
+
+/**
+ * Adds a suspend/reinstate link to the Publish meta box in the theme editor.
+ */
+function wporg_themes_post_submitbox_misc_actions() {
+       $post = get_post();
+       if ( ! $post || 'repopackage' != $post->post_type ) {
+               return;
+       }
+
+       $links = array();
+
+       if ( current_user_can( 'suspend_theme', $post->ID ) && 'suspend' != $post->post_status ) {
+               $links[] = sprintf( '<a class="submit-suspend_theme submitdelete" title="%1$s" href="%2$s">%3$s</a>', esc_attr__( 'Suspend this item', 'wporg-themes' ), esc_url( wporg_themes_get_suspend_url( $post ) ), __( 'Suspend', 'wporg-themes' ) );
+       }
+       elseif ( current_user_can( 'reinstate_theme', $post->ID ) && 'suspend' == $post->post_status ) {
+               $links[] = sprintf( '<a class="submit-reinstate_theme" title="%1$s" href="%2$s">%3$s</a>', esc_attr__( 'Suspend this item', 'wporg-themes' ), esc_url( wporg_themes_get_reinstate_url( $post ) ), __( 'Reinstate', 'wporg-themes' ) );
+       }
+
+       if ( ! empty( $links ) ) {
+               echo '<div class="misc-pub-section">' . implode( ' | ', $links ) . '</div>';
+       }
+}
+add_action( 'post_submitbox_misc_actions', 'wporg_themes_post_submitbox_misc_actions' );
+
+/**
+ * Action link to suspend a theme.
+ *
+ * @param WP_Post $post
+ * @return string URL
+ */
+function wporg_themes_get_suspend_url( $post ) {
+       return wp_nonce_url( add_query_arg( 'action', 'suspend', admin_url( sprintf( get_post_type_object( $post->post_type )->_edit_link, $post->ID ) ) ), "suspend-post_{$post->ID}" );
+}
+
+/**
+ * Action link to reinstate a theme.
+ *
+ * @param WP_Post $post
+ * @return string URL
+ */
+function wporg_themes_get_reinstate_url( $post ) {
+       return wp_nonce_url( add_query_arg( 'action', 'reinstate', admin_url( sprintf( get_post_type_object( $post->post_type )->_edit_link, $post->ID ) ) ), "reinstate-post_{$post->ID}" );
+}
+
+/**
+ * Suspend a theme.
+ */
+function wporg_themes_suspend_theme() {
+       $post_id = isset( $_GET['post'] ) ? (int) $_GET['post'] : 0;
+
+       if ( ! $post_id ) {
+               wp_redirect( admin_url( 'edit.php' ) );
+               exit();
+       }
+
+       check_admin_referer( 'suspend-post_' . $post_id );
+
+       $post = get_post( $post_id );
+
+       if ( 'suspend' == $post->post_status ) {
+               wp_die( __( 'This item has already been suspended.', 'wporg-themes' ) );
+       }
+
+       if ( ! get_post_type_object( $post->post_type ) ) {
+               wp_die( __( 'Unknown post type.', 'wporg-themes' ) );
+       }
+
+       if ( ! current_user_can( 'suspend_theme', $post_id ) || 'repopackage' != $post->post_type ) {
+               wp_die( __( 'You are not allowed to suspend this item.', 'wporg-themes' ) );
+       }
+
+       wp_update_post( array(
+               'ID'          => $post_id,
+               'post_status' => 'suspend',
+       ) );
+
+       wp_redirect( add_query_arg( 'suspended', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'reinstaded' ), wp_get_referer() ) ) );
+       exit();
+}
+add_filter( 'admin_action_suspend', 'wporg_themes_suspend_theme' );
+
+/**
+ * Reinstate a theme.
+ */
+function wporg_themes_reinstate_theme() {
+       $post_id = isset( $_GET['post'] ) ? (int) $_GET['post'] : 0;
+
+       if ( ! $post_id ) {
+               wp_redirect( admin_url( 'edit.php' ) );
+               exit();
+       }
+
+       check_admin_referer( 'reinstate-post_' . $post_id );
+
+       $post = get_post( $post_id );
+
+       if ( 'suspend' != $post->post_status ) {
+               wp_die( __( 'This item has already been reinstated.', 'wporg-themes' ) );
+       }
+
+       if ( ! get_post_type_object( $post->post_type ) ) {
+               wp_die( __( 'Unknown post type.', 'wporg-themes' ) );
+       }
+
+       if ( ! current_user_can( 'reinstate_theme', $post_id ) || 'repopackage' != $post->post_type ) {
+               wp_die( __( 'You are not allowed to reinstate this item.', 'wporg-themes' ) );
+       }
+
+       wp_update_post( array(
+               'ID'          => $post_id,
+               'post_status' => 'draft',
+       ) );
+
+       wp_redirect( add_query_arg( 'reinstated', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'suspended' ), wp_get_referer() ) ) );
+       exit();
+}
+add_filter( 'admin_action_reinstate', 'wporg_themes_reinstate_theme' );
+
+/**
+ * Give the user feedback after suspending or reinstating a theme.
+ */
+function wporg_themes_admin_notices() {
+       if ( ! empty( $_GET['suspended'] ) ) {
+               $suspended = absint( $_GET['suspended'] );
+               $message   = _n( '%s theme suspended.', '%s themes suspended.', $suspended, 'wporg-themes' );
+
+               add_settings_error( 'wporg_themes', 'suspended', sprintf( $message, $suspended ) );
+       }
+
+       elseif ( ! empty( $_GET['reinstated'] ) ) {
+               $reinstated = absint( $_GET['reinstated'] );
+               $message    = _n( '%s theme reinstated.', '%s themes reinstated.', $reinstated, 'wporg-themes' );
+
+               add_settings_error( 'wporg_themes', 'reinstated', sprintf( $message, $reinstated ), 'updated' );
+       }
+
+       // Display admin notices, if any.
+       settings_errors( 'wporg_themes' );
+}
+add_filter( 'admin_notices', 'wporg_themes_admin_notices' );
+
+/**
+ * Use theme screen shot for post thumbnails.
+ *
+ * @param string $html
+ * @param int    $post_id
+ * @return string
+ */
+function wporg_themes_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size ) {
+       $post = get_post( $post_id );
+       if ( 'repopackage' == $post->post_type ) {
+               $theme = new WPORG_Themes_Repo_Package( $post );
+               $src   = add_query_arg( array( 'w' => $size, 'strip' => 'all' ), $theme->screenshot_url() );
+
+               $html = '<img src="' . esc_url( $src ) . '"/>';
+       }
+
+       return $html;
+}
+add_filter( 'post_thumbnail_html', 'wporg_themes_post_thumbnail_html', 10, 5 );
+
+/**
+ * Prevents repopackages from being deleted.
+ *
+ * @param int $post_id
+ */
+function wporg_theme_no_delete_repopackage( $post_id ) {
+       if ( 'repopackage' == get_post( $post_id )->post_type ) {
+               wp_die( __( 'Repopackages can not be deleted.', 'wporg-themes' ), '', array(
+                       'back_link' => true,
+               ) );
+       }
+}
+add_filter( 'before_delete_post', 'wporg_theme_no_delete_repopackage' );
+
+/**
+ * Better view in the Packages screen.
+ *
+ * @param array $columns
+ * @return array
+ */
+function wporg_themes_repopackage_columns( $columns ) {
+       $columns = array_merge( $columns, array(
+               'version'    => __( 'Version', 'wporg-themes' ),
+               'theme-url'  => __( 'Theme URL', 'wporg-themes' ),
+               'author-url' => __( 'Author URL', 'wporg-themes' ),
+               'ticket'     => __( 'Ticket ID', 'wporg-themes' ),
+       ) );
+       unset( $columns['categories'] );
+
+       return $columns;
+}
+add_filter( 'manage_repopackage_posts_columns', 'wporg_themes_repopackage_columns' );
+
+/**
+ * Custom columns for the admin screen.
+ *
+ * @param string $column
+ * @param int    $post_id
+ */
+function wporg_themes_repopackage_custom_columns( $column, $post_id ) {
+       $theme = new WPORG_Themes_Repo_Package( $post_id );
+
+       switch ( $column ) {
+               case 'ticket':
+                       if ( $theme->ticket ) {
+                               printf( '<a href="%1$s">%2$s</a>', esc_url( 'https://themes.trac.wordpress.org/ticket/' . $theme->ticket ), '#' . $theme->ticket );
+                       }
+                       break;
+               case 'theme-url':
+               case 'author-url':
+                       echo make_clickable( $theme->$column );
+                       break;
+               default:
+                       echo $theme->$column;
+       }
+}
+add_action( 'manage_repopackage_posts_custom_column', 'wporg_themes_repopackage_custom_columns', 10, 2 );
+
+/**
+ * Meta box to choose which version is live.
+ */
+function wporg_themes_add_meta_box() {
+       add_meta_box(
+               'wporg_themes_versions',
+               __( 'Theme Versions', 'wporg-themes' ),
+               'wporg_themes_meta_box_callback',
+               'repopackage',
+               'side',
+               'high'
+       );
+}
+add_action( 'add_meta_boxes', 'wporg_themes_add_meta_box' );
+
+/**
+ * Displays the content of the `_status` meta box.
+ *
+ * @param WP_Post $post
+ */
+function wporg_themes_meta_box_callback( $post ) {
+       $versions = get_post_meta( $post->ID, '_status', true );
+
+       if ( empty( $versions ) ) {
+               return;
+       }
+
+       // Add an nonce field so we can check for it later.
+       wp_nonce_field( 'wporg_themes_meta_box', 'wporg_themes_meta_box_nonce' );
+
+       foreach ( $versions as $version => $status ) :
+               ?>
+               <p><?php echo $version; ?> -
+                       <select name="wporg_themes_status[<?php echo base64_encode( $version ); // base64 because version numbers don't work so well as parts of keys ?>]">
+                               <option value="new" <?php selected( $status, 'new' ); ?>><?php esc_html_e( 'New', 'wporg-themes' ); ?></option>
+                               <option value="live" <?php selected( $status, 'live' ); ?>><?php esc_html_e( 'Live', 'wporg-themes' ); ?></option>
+                               <option value="old" <?php selected( $status, 'old' ); ?>><?php esc_html_e( 'Old', 'wporg-themes' ); ?></option>
+                       </select>
+               </p>
+       <?php
+       endforeach;
+}
+
+/**
+ * Sanitizes and saves meta box settings.
+ *
+ * @param int $post_id
+ */
+function wporg_themes_save_meta_box_data( $post_id ) {
+       // All the safety checks.
+       if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
+               return;
+       }
+       if ( ! isset( $_POST['wporg_themes_meta_box_nonce'] ) ) {
+               return;
+       }
+       if ( ! wp_verify_nonce( $_POST['wporg_themes_meta_box_nonce'], 'wporg_themes_meta_box' ) ) {
+               return;
+       }
+       // TODO should this be a post type specific capability?
+       if ( ! current_user_can( 'edit_post', $post_id ) ) {
+               return;
+       }
+
+       $new_status = array();
+       foreach ( $_POST['wporg_themes_status'] as $version => $status ) {
+               // We could check of the passed status is valid, but wporg_themes_update_version_status() handles that beautifully.
+               $new_status[ base64_decode( $version ) ] = $status;
+       }
+       uksort( $new_status, 'version_compare' );
+
+       // Update the statuses.
+       foreach ( $new_status as $version => $status ) {
+               wporg_themes_update_version_status( $post_id, $version, $status );
+       }
+}
+add_action( 'save_post', 'wporg_themes_save_meta_box_data' );
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/admin-edit.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><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-11 14:03:19 UTC (rev 1394)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php        2015-03-11 22:55:10 UTC (rev 1395)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -23,10 +23,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Load Themes API adjustments.
</span><span class="cx" style="display: block; padding: 0 10px"> include_once plugin_dir_path( __FILE__ ) . 'themes-api.php';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-register_activation_hook( __FILE__, 'flush_rewrite_rules' );
-register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Load adjustments to the edit.php screen for repopackage posts.
+include_once plugin_dir_path( __FILE__ ) . 'admin-edit.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Things to change on activation.
+ */
+function wporg_themes_activate() {
+       flush_rewrite_rules();
+
+       do_action( 'wporg_themes_activation' );
+}
+register_activation_hook( __FILE__, 'wporg_themes_activate' );
+
+/**
+ * Things to change on deactivation.
+ */
+function wporg_themes_deactivate() {
+       flush_rewrite_rules();
+
+       do_action( 'wporg_themes_deactivation' );
+}
+register_deactivation_hook( __FILE__, 'wporg_themes_deactivate' );
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Initialize.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function wporg_themes_init() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -192,31 +213,6 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Capability mapping for custom caps.
- *
- * @param array  $caps    Returns the user's actual capabilities.
- * @param string $cap     Capability name.
- * @param int    $user_id The user ID.
- * @param array  $args    Adds the context to the cap. Typically the object ID.
- * @return array
- */
-function wporg_themes_map_meta_cap( $caps, $cap, $user_id, $args ) {
-       switch ( $cap ) {
-               case 'delete_categories':
-               case 'edit_categories':
-               case 'manage_categories':
-
-                       if ( ! is_super_admin() ) {
-                               $caps[] = 'do_not_allow';
-                       }
-                       break;
-       }
-
-       return $caps;
-}
-add_filter( 'map_meta_cap', 'wporg_themes_map_meta_cap', 10, 4 );
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px">  * Checks if ther current users is a super admin before allowing terms to be added.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string           $term The term to add or update.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -502,161 +498,3 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-/* REPOPACKAGE EDITOR ENHANCEMENTS */
-
-/**
- * Use theme screen shot for post thumbnails.
- *
- * @param string $html
- * @param int    $post_id
- * @return string
- */
-function wporg_themes_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size ) {
-       $post = get_post( $post_id );
-       if ( 'repopackage' == $post->post_type ) {
-               $theme = new WPORG_Themes_Repo_Package( $post );
-               $src   = add_query_arg( array( 'w' => $size, 'strip' => 'all' ), $theme->screenshot_url() );
-
-               $html = '<img src="' . esc_url( $src ) . '"/>';
-       }
-
-       return $html;
-}
-add_filter( 'post_thumbnail_html', 'wporg_themes_post_thumbnail_html', 10, 5 );
-
-/**
- * Prevents repopackages from being deleted.
- *
- * @param int $post_id
- */
-function wporg_theme_no_delete_repopackage( $post_id ) {
-       if ( 'repopackage' == get_post( $post_id )->post_type ) {
-               wp_die( __( 'Repopackages can not be deleted.', 'wporg-themes' ), '', array(
-                       'back_link' => true,
-               ) );
-       }
-}
-add_filter( 'before_delete_post', 'wporg_theme_no_delete_repopackage' );
-
-/**
- * Better view in the Packages screen.
- *
- * @param array $columns
- * @return array
- */
-function wporg_themes_repopackage_columns( $columns ) {
-       $columns = array_merge( $columns, array(
-               'version'    => __( 'Version', 'wporg-themes' ),
-               'theme-url'  => __( 'Theme URL', 'wporg-themes' ),
-               'author-url' => __( 'Author URL', 'wporg-themes' ),
-               'ticket'     => __( 'Ticket ID', 'wporg-themes' ),
-       ) );
-       unset( $columns['categories'] );
-
-       return $columns;
-}
-add_filter( 'manage_repopackage_posts_columns', 'wporg_themes_repopackage_columns' );
-
-/**
- * Custom columns for the admin screen.
- *
- * @param string $column
- * @param int    $post_id
- */
-function wporg_themes_repopackage_custom_columns( $column, $post_id ) {
-       $theme = new WPORG_Themes_Repo_Package( $post_id );
-
-       switch ( $column ) {
-               case 'ticket':
-                       if ( $theme->ticket ) {
-                               printf( '<a href="%1$s">%2$s</a>', esc_url( 'https://themes.trac.wordpress.org/ticket/' . $theme->ticket ), '#' . $theme->ticket );
-                       }
-                       break;
-               case 'theme-url':
-               case 'author-url':
-                       echo make_clickable( $theme->$column );
-                       break;
-               default:
-                       echo $theme->$column;
-       }
-}
-add_action( 'manage_repopackage_posts_custom_column', 'wporg_themes_repopackage_custom_columns', 10, 2 );
-
-/**
- * Meta box to choose which version is live.
- */
-function wporg_themes_add_meta_box() {
-       add_meta_box(
-               'wporg_themes_versions',
-               __( 'Theme Versions', 'wporg-themes' ),
-               'wporg_themes_meta_box_callback',
-               'repopackage',
-               'side',
-               'high'
-       );
-}
-add_action( 'add_meta_boxes', 'wporg_themes_add_meta_box' );
-
-/**
- * Displays the content of the `_status` meta box.
- *
- * @param WP_Post $post
- */
-function wporg_themes_meta_box_callback( $post ) {
-       $versions = get_post_meta( $post->ID, '_status', true );
-
-       if ( empty( $versions ) ) {
-               return;
-       }
-
-       // Add an nonce field so we can check for it later.
-       wp_nonce_field( 'wporg_themes_meta_box', 'wporg_themes_meta_box_nonce' );
-
-       foreach ( $versions as $version => $status ) :
-               ?>
-               <p><?php echo $version; ?> -
-                       <select name="wporg_themes_status[<?php echo base64_encode( $version ); // base64 because version numbers don't work so well as parts of keys ?>]">
-                               <option value="new" <?php selected( $status, 'new' ); ?>><?php esc_html_e( 'New', 'wporg-themes' ); ?></option>
-                               <option value="live" <?php selected( $status, 'live' ); ?>><?php esc_html_e( 'Live', 'wporg-themes' ); ?></option>
-                               <option value="old" <?php selected( $status, 'old' ); ?>><?php esc_html_e( 'Old', 'wporg-themes' ); ?></option>
-                       </select>
-               </p>
-       <?php
-       endforeach;
-}
-
-/**
- * Sanitizes and saves meta box settings.
- *
- * @param int $post_id
- */
-function wporg_themes_save_meta_box_data( $post_id ) {
-       // All the safety checks.
-       if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
-               return;
-       }
-       if ( ! isset( $_POST['wporg_themes_meta_box_nonce'] ) ) {
-               return;
-       }
-       if ( ! wp_verify_nonce( $_POST['wporg_themes_meta_box_nonce'], 'wporg_themes_meta_box' ) ) {
-               return;
-       }
-       // TODO should this be a post type specific capability?
-       if ( ! current_user_can( 'edit_post', $post_id ) ) {
-               return;
-       }
-
-       $new_status = array();
-       foreach ( $_POST['wporg_themes_status'] as $version => $status ) {
-               // We could check of the passed status is valid, but wporg_themes_update_version_status() handles that beautifully.
-               $new_status[ base64_decode( $version ) ] = $status;
-       }
-       uksort( $new_status, 'version_compare' );
-
-       // Update the statuses.
-       foreach ( $new_status as $version => $status ) {
-               wporg_themes_update_version_status( $post_id, $version, $status );
-       }
-}
-add_action( 'save_post', 'wporg_themes_save_meta_box_data' );
</del></span></pre>
</div>
</div>

</body>
</html>