<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[17101] trunk/wp-admin: Add delete support to network themes.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17101">17101</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-12-21 16:50:16 +0000 (Tue, 21 Dec 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add delete support to network themes. Props PeteMall. fixes <a href="http://trac.wordpress.org/ticket/15707">#15707</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswpmsthemeslisttablephp">trunk/wp-admin/includes/class-wp-ms-themes-list-table.php</a></li>
<li><a href="#trunkwpadminnetworkthemesphp">trunk/wp-admin/network/themes.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswpmsthemeslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-ms-themes-list-table.php (17100 => 17101)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-ms-themes-list-table.php        2010-12-21 16:27:34 UTC (rev 17100)
+++ trunk/wp-admin/includes/class-wp-ms-themes-list-table.php        2010-12-21 16:50:16 UTC (rev 17101)
</span><span class="lines">@@ -231,9 +231,12 @@
</span><span class="cx">                         $actions['enable-selected'] = $this-&gt;is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
</span><span class="cx">                 if ( 'disabled' != $status )
</span><span class="cx">                         $actions['disable-selected'] = $this-&gt;is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
</span><del>-                if ( current_user_can( 'update_themes' ) &amp;&amp; !$this-&gt;is_site_themes )
-                        $actions['update-selected'] = __( 'Update' );
-
</del><ins>+                if ( ! $this-&gt;is_site_themes ) {
+                        if ( current_user_can( 'delete_themes' ) )
+                                $actions['delete-selected'] = __( 'Delete' );
+                        if ( current_user_can( 'update_themes' ) )
+                                $actions['update-selected'] = __( 'Update' );
+                }
</ins><span class="cx">                 return $actions;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -265,22 +268,26 @@
</span><span class="cx">                 $actions = array(
</span><span class="cx">                         'enable' =&gt; '',
</span><span class="cx">                         'disable' =&gt; '',
</span><del>-                        'edit' =&gt; ''
</del><ins>+                        'edit' =&gt; '',
+                        'delete' =&gt; ''
</ins><span class="cx">                 );
</span><span class="cx"> 
</span><span class="cx">                 $theme_key = esc_html( $theme['Stylesheet'] );
</span><span class="cx"> 
</span><span class="cx">                 if ( empty( $theme['enabled'] ) )
</span><del>-                        $actions['enable'] = '&lt;a href=&quot;' . wp_nonce_url($url . 'action=enable&amp;amp;theme=' . $theme_key . '&amp;amp;paged=' . $page . '&amp;amp;s=' . $s, 'enable-theme_' . $theme_key) . '&quot; title=&quot;' . __('Enable this theme') . '&quot; class=&quot;edit&quot;&gt;' . ( $this-&gt;is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '&lt;/a&gt;';
</del><ins>+                        $actions['enable'] = '&lt;a href=&quot;' . esc_url( wp_nonce_url($url . 'action=enable&amp;amp;theme=' . $theme_key . '&amp;amp;paged=' . $page . '&amp;amp;s=' . $s, 'enable-theme_' . $theme_key) ) . '&quot; title=&quot;' . esc_attr__('Enable this theme') . '&quot; class=&quot;edit&quot;&gt;' . ( $this-&gt;is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '&lt;/a&gt;';
</ins><span class="cx">                 else
</span><del>-                        $actions['disable'] = '&lt;a href=&quot;' . wp_nonce_url($url . 'action=disable&amp;amp;theme=' . $theme_key . '&amp;amp;paged=' . $page . '&amp;amp;s=' . $s, 'disable-theme_' . $theme_key) . '&quot; title=&quot;' . __('Disable this theme') . '&quot;&gt;' . ( $this-&gt;is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '&lt;/a&gt;';
</del><ins>+                        $actions['disable'] = '&lt;a href=&quot;' . esc_url( wp_nonce_url($url . 'action=disable&amp;amp;theme=' . $theme_key . '&amp;amp;paged=' . $page . '&amp;amp;s=' . $s, 'disable-theme_' . $theme_key) ) . '&quot; title=&quot;' . esc_attr__('Disable this theme') . '&quot;&gt;' . ( $this-&gt;is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '&lt;/a&gt;';
</ins><span class="cx"> 
</span><span class="cx">                 if ( current_user_can('edit_themes') )
</span><del>-                        $actions['edit'] = '&lt;a href=&quot;theme-editor.php?theme=' . $theme['Name'] . '&quot; title=&quot;' . __('Open this theme in the Theme Editor') . '&quot; class=&quot;edit&quot;&gt;' . __('Edit') . '&lt;/a&gt;';
</del><ins>+                        $actions['edit'] = '&lt;a href=&quot;' . esc_url('theme-editor.php?theme=' . $theme['Name'] ) . '&quot; title=&quot;' . esc_attr__('Open this theme in the Theme Editor') . '&quot; class=&quot;edit&quot;&gt;' . __('Edit') . '&lt;/a&gt;';
+                        
+                if ( empty( $theme['enabled'] ) &amp;&amp; current_user_can( 'delete_themes' ) &amp;&amp; ! $this-&gt;is_site_themes )
+                        $actions['delete'] = '&lt;a href=&quot;' . esc_url( wp_nonce_url( 'themes.php?action=delete-selected&amp;amp;checked[]=' . $theme_key . '&amp;amp;theme_status=' . $context . '&amp;amp;paged=' . $page . '&amp;amp;s=' . $s, 'bulk-themes' ) ) . '&quot; title=&quot;' . esc_attr__( 'Delete this theme' ) . '&quot; class=&quot;delete&quot;&gt;' . __( 'Delete' ) . '&lt;/a&gt;';
</ins><span class="cx"> 
</span><span class="cx">                 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context );
</span><span class="cx">                 $actions = apply_filters( &quot;theme_action_links_$theme_key&quot;, $actions, $theme_key, $theme, $context );
</span><del>-
</del><ins>+ 
</ins><span class="cx">                 $class = empty( $theme['enabled'] ) ? 'inactive' : 'active';
</span><span class="cx">                 $checkbox_id = md5($theme['Name']) . &quot;_checkbox&quot;;
</span><span class="cx">                 $checkbox = &quot;&lt;input type='checkbox' name='checked[]' value='&quot; . esc_attr( $theme_key ) . &quot;' id='&quot; . $checkbox_id . &quot;' /&gt;&lt;label class='screen-reader-text' for='&quot; . $checkbox_id . &quot;' &gt;&quot; . __('Select') . &quot; &quot; . $theme['Name'] . &quot;&lt;/label&gt;&quot;;
</span><span class="lines">@@ -319,11 +326,11 @@
</span><span class="cx">                                         if ( !empty( $theme['Author'] ) ) {
</span><span class="cx">                                                 $author = $theme['Author'];
</span><span class="cx">                                                 if ( !empty( $theme['Author URI'] ) )
</span><del>-                                                        $author = '&lt;a href=&quot;' . $theme['Author URI'] . '&quot; title=&quot;' . __( 'Visit author homepage' ) . '&quot;&gt;' . $theme['Author'] . '&lt;/a&gt;';
</del><ins>+                                                        $author = '&lt;a href=&quot;' . $theme['Author URI'] . '&quot; title=&quot;' . esc_attr__( 'Visit author homepage' ) . '&quot;&gt;' . $theme['Author'] . '&lt;/a&gt;';
</ins><span class="cx">                                                 $theme_meta[] = sprintf( __( 'By %s' ), $author );
</span><span class="cx">                                         }
</span><span class="cx">                                         if ( !empty( $theme['Theme URI'] ) )
</span><del>-                                                $theme_meta[] = '&lt;a href=&quot;' . $theme['Theme URI'] . '&quot; title=&quot;' . __( 'Visit theme homepage' ) . '&quot;&gt;' . __( 'Visit Theme Site' ) . '&lt;/a&gt;';
</del><ins>+                                                $theme_meta[] = '&lt;a href=&quot;' . $theme['Theme URI'] . '&quot; title=&quot;' . esc_attr__( 'Visit theme homepage' ) . '&quot;&gt;' . __( 'Visit Theme Site' ) . '&lt;/a&gt;';
</ins><span class="cx"> 
</span><span class="cx">                                         $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status );
</span><span class="cx">                                         echo implode( ' | ', $theme_meta );
</span></span></pre></div>
<a id="trunkwpadminnetworkthemesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/network/themes.php (17100 => 17101)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/network/themes.php        2010-12-21 16:27:34 UTC (rev 17100)
+++ trunk/wp-admin/network/themes.php        2010-12-21 16:50:16 UTC (rev 17101)
</span><span class="lines">@@ -65,6 +65,95 @@
</span><span class="cx">                                 unset( $allowed_themes[ $theme ] );
</span><span class="cx">                         update_site_option( 'allowedthemes', $allowed_themes );
</span><span class="cx">                         break;
</span><ins>+                case 'delete':
+                        check_admin_referer('delete-theme_' . $_GET['template']);
+                        if ( !current_user_can('delete_themes') )
+                                wp_die( __( 'Cheatin&amp;#8217; uh?' ) );
+                        delete_theme($_GET['template']);
+                        wp_redirect( network_admin_url('themes.php?deleted=true') );
+                        exit;
+                        break;
+                case 'delete-selected':
+                        if ( ! current_user_can( 'delete_themes' ) )
+                                wp_die( __('You do not have sufficient permissions to delete themes for this site.') );
+
+                        $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
+                        if ( empty( $themes ) ) {
+                                wp_redirect( wp_get_referer() );
+                                exit;
+                        }
+
+                        $main_theme = get_current_theme();
+                        $files_to_delete = $theme_info = array();
+                        foreach( $themes as $key =&gt; $theme ) {
+                                $data = get_theme_data( WP_CONTENT_DIR . '/themes/' . $theme . '/style.css' );
+                                if ( $data['Name'] == $main_theme ) {
+                                        unset( $themes[$key] );
+                                } else {
+                                        $files_to_delete = array_merge( $files_to_delete, list_files( WP_CONTENT_DIR . &quot;/themes/$theme&quot; ) );                                        
+                                        $theme_info[ $theme ] = $data;
+                                }
+                        }
+                        
+                        if ( empty( $themes ) ) {
+                                wp_redirect( add_query_arg( 'error', 'main', wp_get_referer() ) );
+                                exit;
+                        }
+                        
+                        include(ABSPATH . 'wp-admin/update.php');
+
+                        $parent_file = 'themes.php';
+
+                        if ( ! isset( $_REQUEST['verify-delete'] ) ) {
+                                wp_enqueue_script( 'jquery' );
+                                require_once( ABSPATH . 'wp-admin/admin-header.php' );
+                                ?&gt;
+                        &lt;div class=&quot;wrap&quot;&gt;
+                                &lt;?php
+                                        $themes_to_delete = count( $themes );
+                                        screen_icon();
+                                        echo '&lt;h2&gt;' . _n( 'Delete Theme', 'Delete Themes', $themes_to_delete ) . '&lt;/h2&gt;';
+                                ?&gt;
+                                &lt;div class=&quot;error&quot;&gt;&lt;p&gt;&lt;strong&gt;&lt;?php _e( 'Caution:' ); ?&gt;&lt;/strong&gt; &lt;?php echo _n( 'This theme may be active on other sites in the network.', 'These themes may be active on other sites in the network.', $themes_to_delete ); ?&gt;&lt;/p&gt;&lt;/div&gt;
+                                &lt;p&gt;&lt;?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?&gt;&lt;/p&gt;
+                                        &lt;ul class=&quot;ul-disc&quot;&gt;
+                                                &lt;?php foreach ( $theme_info as $theme )
+                                                        echo '&lt;li&gt;', sprintf( __('&lt;strong&gt;%1$s&lt;/strong&gt; by &lt;em&gt;%2$s&lt;/em&gt;' ), esc_html( $theme['Name'] ), esc_html( $theme['AuthorName'] ) ), '&lt;/li&gt;'; /* translators: 1: theme name, 2: theme author */ ?&gt;
+                                        &lt;/ul&gt;
+                                &lt;p&gt;&lt;?php _e('Are you sure you wish to delete these themes?'); ?&gt;&lt;/p&gt;
+                                &lt;form method=&quot;post&quot; action=&quot;&lt;?php echo esc_url($_SERVER['REQUEST_URI']); ?&gt;&quot; style=&quot;display:inline;&quot;&gt;
+                                        &lt;input type=&quot;hidden&quot; name=&quot;verify-delete&quot; value=&quot;1&quot; /&gt;
+                                        &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;delete-selected&quot; /&gt;
+                                        &lt;?php
+                                                foreach ( (array) $themes as $theme )
+                                                        echo '&lt;input type=&quot;hidden&quot; name=&quot;checked[]&quot; value=&quot;' . esc_attr($theme) . '&quot; /&gt;';
+                                        ?&gt;
+                                        &lt;?php wp_nonce_field('bulk-themes') ?&gt;
+                                        &lt;?php submit_button( _n( 'Yes, Delete this theme', 'Yes, Delete these themes', $themes_to_delete ), 'button', 'submit', false ); ?&gt;
+                                &lt;/form&gt;
+                                &lt;form method=&quot;post&quot; action=&quot;&lt;?php echo esc_url(wp_get_referer()); ?&gt;&quot; style=&quot;display:inline;&quot;&gt;
+                                        &lt;?php submit_button( __( 'No, Return me to the theme list' ), 'button', 'submit', false ); ?&gt;
+                                &lt;/form&gt;
+
+                                &lt;p&gt;&lt;a href=&quot;#&quot; onclick=&quot;jQuery('#files-list').toggle(); return false;&quot;&gt;&lt;?php _e('Click to view entire list of files which will be deleted'); ?&gt;&lt;/a&gt;&lt;/p&gt;
+                                &lt;div id=&quot;files-list&quot; style=&quot;display:none;&quot;&gt;
+                                        &lt;ul class=&quot;code&quot;&gt;
+                                        &lt;?php
+                                                foreach ( (array) $files_to_delete as $file )
+                                                        echo '&lt;li&gt;' . esc_html( str_replace( WP_CONTENT_DIR . &quot;/themes&quot;, '', $file) ) . '&lt;/li&gt;';
+                                        ?&gt;
+                                        &lt;/ul&gt;
+                                &lt;/div&gt;
+                        &lt;/div&gt;
+                                &lt;?php
+                                require_once(ABSPATH . 'wp-admin/admin-footer.php');
+                                exit;
+                        } //Endif verify-delete
+                        foreach( $themes as $theme )
+                                $delete_result = delete_theme( $theme );
+                        wp_redirect( network_admin_url( 'themes.php?deleted=true' ) );
+                        exit;
+                        break;
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -87,6 +176,11 @@
</span><span class="cx"> 
</span><span class="cx"> require_once(ABSPATH . 'wp-admin/admin-header.php');
</span><span class="cx"> 
</span><ins>+if ( isset( $_GET['deleted'] ) ) : ?&gt;
+&lt;div class=&quot;updated&quot;&gt;&lt;p&gt;&lt;?php _e('Theme deleted.') ?&gt;&lt;/p&gt;&lt;/div&gt;&lt;?php
+elseif ( isset( $_GET['error'] ) &amp;&amp; 'main' == $_GET['error'] ) : ?&gt;
+&lt;div class=&quot;error&quot;&gt;&lt;p&gt;&lt;?php _e( 'You cannot delete a theme while it is active on the main site.' ); ?&gt;&lt;/p&gt;&lt;/div&gt;&lt;?php
+endif;
</ins><span class="cx"> ?&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;div class=&quot;wrap&quot;&gt;
</span></span></pre>
</div>
</div>

</body>
</html>