<!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>[16242] trunk/wp-admin: site-themes.php cleanup.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16242">16242</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-11-08 21:52:54 +0000 (Mon, 08 Nov 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>site-themes.php cleanup. Props PeteMall. see <a href="http://trac.wordpress.org/ticket/14897">#14897</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="#trunkwpadminnetworksitethemesphp">trunk/wp-admin/network/site-themes.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 (16241 => 16242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-ms-themes-list-table.php        2010-11-08 19:40:05 UTC (rev 16241)
+++ trunk/wp-admin/includes/class-wp-ms-themes-list-table.php        2010-11-08 21:52:54 UTC (rev 16242)
</span><span class="lines">@@ -7,6 +7,9 @@
</span><span class="cx"> * @since 3.1.0
</span><span class="cx"> */
</span><span class="cx"> class WP_MS_Themes_List_Table extends WP_List_Table {
</span><ins>+        
+        var $site_id;
+        var $is_site_themes;
</ins><span class="cx">
</span><span class="cx">         function WP_MS_Themes_List_Table() {
</span><span class="cx">                 global $status, $page;
</span><span class="lines">@@ -37,8 +40,10 @@
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                if ( !current_user_can('manage_network_themes') )
-                        wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) );
</del><ins>+                if ( $this->is_site_themes && !current_user_can('manage_sites') )
+                        wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) );
+                else if ( !$this->is_site_themes && !current_user_can('manage_network_themes') )
+                        wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function prepare_items() {
</span><span class="lines">@@ -54,11 +59,17 @@
</span><span class="cx">                         'upgrade' => array()
</span><span class="cx">                 );
</span><span class="cx">
</span><del>-                $allowed_themes = get_site_allowed_themes();
</del><ins>+                $site_allowed_themes = get_site_allowed_themes();
+                if ( !$this->is_site_themes )
+                        $allowed_themes = $site_allowed_themes;
+                else
+                        $allowed_themes = wpmu_get_blog_allowedthemes( $this->site_id );
+                
</ins><span class="cx">                 $current = get_site_transient( 'update_themes' );
</span><span class="cx">
</span><span class="cx">                 foreach ( (array) $themes['all'] as $key => $theme ) {
</span><span class="cx">                         $theme_key = esc_html( $theme['Stylesheet'] );
</span><ins>+
</ins><span class="cx">                         if ( isset( $allowed_themes [ $theme_key ] ) ) {
</span><span class="cx">                                 $themes['all'][$key]['enabled'] = true;
</span><span class="cx">                                 $themes['enabled'][$key] = $themes['all'][$key];
</span><span class="lines">@@ -69,6 +80,12 @@
</span><span class="cx">                         }
</span><span class="cx">                         if ( isset( $current->response[ $theme['Template'] ] ) )
</span><span class="cx">                                 $themes['upgrade'][$key] = $themes['all'][$key];
</span><ins>+
+                        if ( $this->is_site_themes && isset( $site_allowed_themes[$theme_key] ) ) {
+                                unset( $themes['all'][$key] );
+                                unset( $themes['enabled'][$key] );
+                                unset( $themes['disabled'][$key] );
+                        }
</ins><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 if ( !current_user_can( 'update_themes' ) )
</span><span class="lines">@@ -188,8 +205,13 @@
</span><span class="cx">                                         break;
</span><span class="cx">                         }
</span><span class="cx">
</span><ins>+                        if ( $this->is_site_themes )
+                                $url = 'site-themes.php?id=' . $this->site_id;
+                        else
+                                $url = 'themes.php';
+
</ins><span class="cx">                         $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
</span><del>-                                add_query_arg('theme_status', $type, 'themes.php'),
</del><ins>+                                add_query_arg('theme_status', $type, $url),
</ins><span class="cx">                                 ( $type == $status ) ? ' class="current"' : '',
</span><span class="cx">                                 sprintf( $text, number_format_i18n( $count ) )
</span><span class="cx">                         );
</span><span class="lines">@@ -203,9 +225,9 @@
</span><span class="cx">
</span><span class="cx">                 $actions = array();
</span><span class="cx">                 if ( 'enabled' != $status )
</span><del>-                        $actions['network-enable-selected'] = __( 'Enable' );
</del><ins>+                        $actions['enable-selected'] = __( 'Enable' );
</ins><span class="cx">                 if ( 'disabled' != $status )
</span><del>-                        $actions['network-disable-selected'] = __( 'Disable' );
</del><ins>+                        $actions['disable-selected'] = __( 'Disable' );
</ins><span class="cx">                 if ( current_user_can( 'update_themes' ) )
</span><span class="cx">                         $actions['update-selected'] = __( 'Update' );
</span><span class="cx">                         
</span><span class="lines">@@ -225,24 +247,26 @@
</span><span class="cx">                 global $status, $page, $s;
</span><span class="cx">
</span><span class="cx">                 $context = $status;
</span><ins>+                
+                if ( $this->is_site_themes )
+                        $url = "site-themes.php?id={$this->site_id}&amp;";
+                else
+                        $url = 'themes.php?';
</ins><span class="cx">
</span><span class="cx">                 foreach ( $this->items as $key => $theme ) {
</span><span class="cx">                         // preorder
</span><span class="cx">                         $actions = array(
</span><del>-                                'network_enable' => '',
-                                'network_disable' => '',
</del><ins>+                                'enable' => '',
+                                'disable' => '',
</ins><span class="cx">                                 'edit' => ''
</span><span class="cx">                         );
</span><span class="cx">                         
</span><span class="cx">                         $theme_key = esc_html( $theme['Stylesheet'] );
</span><span class="cx">
</span><del>-                        if ( empty( $theme['enabled'] ) ) {
-                                if ( current_user_can( 'manage_network_themes' ) )
-                                        $actions['network_enable'] = '<a href="' . wp_nonce_url('themes.php?action=network-enable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'enable-theme_' . $theme_key) . '" title="' . __('Enable this theme for all sites in this network') . '" class="edit">' . __('Enable') . '</a>';
-                        } else {
-                                if ( current_user_can( 'manage_network_themes' ) )
-                                        $actions['network_disable'] = '<a href="' . wp_nonce_url('themes.php?action=network-disable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'disable-theme_' . $theme_key) . '" title="' . __('Disable this theme') . '">' . __('Disable') . '</a>';
-                        }
</del><ins>+                        if ( empty( $theme['enabled'] ) )
+                                        $actions['enable'] = '<a href="' . wp_nonce_url($url . 'action=enable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'enable-theme_' . $theme_key) . '" title="' . __('Enable this theme') . '" class="edit">' . __('Enable') . '</a>';
+                        else
+                                        $actions['disable'] = '<a href="' . wp_nonce_url($url . 'action=disable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'disable-theme_' . $theme_key) . '" title="' . __('Disable this theme') . '">' . __('Disable') . '</a>';
</ins><span class="cx">                         
</span><span class="cx">                         if ( current_user_can('edit_themes') )
</span><span class="cx">                                 $actions['edit'] = '<a href="theme-editor.php?theme=' . $theme['Name'] . '" title="' . __('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
</span></span></pre></div>
<a id="trunkwpadminnetworksitethemesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/network/site-themes.php (16241 => 16242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/network/site-themes.php        2010-11-08 19:40:05 UTC (rev 16241)
+++ trunk/wp-admin/network/site-themes.php        2010-11-08 21:52:54 UTC (rev 16242)
</span><span class="lines">@@ -1,26 +1,32 @@
</span><span class="cx"> <?php
</span><del>-
</del><span class="cx"> /**
</span><del>- * Edit Site Themes Administration Screen
</del><ins>+ * Multisite themes administration panel.
</ins><span class="cx"> *
</span><span class="cx"> * @package WordPress
</span><del>- * @subpackage Administration
</del><ins>+ * @subpackage Multisite
</ins><span class="cx"> * @since 3.1.0
</span><span class="cx"> */
</span><span class="cx">
</span><del>-/** Load WordPress Administration Bootstrap */
-require_once('./admin.php');
</del><ins>+require_once( './admin.php' );
</ins><span class="cx">
</span><del>-if ( ! is_multisite() )
-        wp_die( __( 'Multisite support is not enabled.' ) );
</del><ins>+$wp_list_table = get_list_table('WP_MS_Themes_List_Table');
+$wp_list_table->check_permissions();
</ins><span class="cx">
</span><del>-if ( ! current_user_can('manage_sites') )
-        wp_die(__('You do not have sufficient permissions to edit this site.'));
</del><ins>+$action = $wp_list_table->current_action();
</ins><span class="cx">
</span><ins>+$s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
+
+// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
+$_SERVER['REQUEST_URI'] = remove_query_arg(array('network-enable', 'network-disable', 'network-enable-selected', 'network-disable-selected'), $_SERVER['REQUEST_URI']);
+
</ins><span class="cx"> $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
</span><span class="cx">
</span><span class="cx"> if ( ! $id )
</span><span class="cx">         wp_die( __('Invalid site ID.') );
</span><ins>+        
+$wp_list_table->site_id = $id;
+$wp_list_table->is_site_themes = true;
+$wp_list_table->prepare_items();
</ins><span class="cx">
</span><span class="cx"> $details = get_blog_details( $id );
</span><span class="cx"> if ( $details->site_id != $wpdb->siteid )
</span><span class="lines">@@ -28,36 +34,65 @@
</span><span class="cx">
</span><span class="cx"> $is_main_site = is_main_site( $id );
</span><span class="cx">
</span><del>-if ( isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] ) {
-        check_admin_referer( 'edit-site' );
-
</del><ins>+if ( $action ) {
</ins><span class="cx">         switch_to_blog( $id );
</span><ins>+        $allowed_themes = get_option( 'allowedthemes' );
</ins><span class="cx">
</span><del>-        $allowedthemes = array();
-        if ( isset($_POST['theme']) && is_array( $_POST['theme'] ) ) {
-                foreach ( $_POST['theme'] as $theme => $val ) {
-                        if ( 'on' == $val )
-                                $allowedthemes[$theme] = true;
-                }
</del><ins>+        switch ( $action ) {
+                case 'enable':
+                        $theme = $_GET['theme'];
+                        if ( !$allowed_themes )
+                                $allowed_themes = array( $theme => true );
+                        else
+                                $allowed_themes[$theme] = true;
+                        break;
+                case 'disable':
+                        $theme = $_GET['theme'];
+                        if ( !$allowed_themes )
+                                $allowed_themes = array();
+                        else
+                                unset( $allowed_themes[$theme] );
+                        break;
+                case 'enable-selected':
+                        $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
+                        if ( empty($themes) ) {
+                                restore_current_blog();
+                                wp_redirect( wp_get_referer() );
+                                exit;
+                        }                                                
+                        foreach( (array) $themes as $theme )
+                                $allowed_themes[ $theme ] = true;
+                        break;
+                case 'disable-selected':
+                        $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
+                        if ( empty($themes) ) {
+                                restore_current_blog();
+                                wp_redirect( wp_get_referer() );
+                                exit;
+                        }                                                
+                        foreach( (array) $themes as $theme )
+                                unset( $allowed_themes[ $theme ] );
+                        break;
</ins><span class="cx">         }
</span><del>-        update_option( 'allowedthemes', $allowedthemes );
-
</del><ins>+        
+        update_option( 'allowedthemes', $allowed_themes );
</ins><span class="cx">         restore_current_blog();
</span><del>-        wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-themes.php') );
</del><ins>+        
+        wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message
+        exit;        
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-if ( isset($_GET['update']) ) {
-        $messages = array();
-        if ( 'updated' == $_GET['update'] )
-                $messages[] = __('Site users updated.');
-}
-
</del><span class="cx"> $title = sprintf( __('Edit Site: %s'), get_blogaddress_by_id($id));
</span><span class="cx"> $parent_file = 'sites.php';
</span><span class="cx"> $submenu_file = 'sites.php';
</span><span class="cx">
</span><span class="cx"> require('../admin-header.php');
</span><span class="cx">
</span><ins>+add_thickbox();
+
+add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' ), 'default' => 999) );
+
+require_once(ABSPATH . 'wp-admin/admin-header.php');
</ins><span class="cx"> ?>
</span><span class="cx">
</span><span class="cx"> <div class="wrap">
</span><span class="lines">@@ -73,48 +108,22 @@
</span><span class="cx"> }
</span><span class="cx"> ?>
</span><span class="cx"> </h3>
</span><ins>+<p class="description"><?php _e( 'Network enabled themes are not shown on this screen.' ) ?></p>
</ins><span class="cx"> <?php
</span><span class="cx"> if ( ! empty( $messages ) ) {
</span><span class="cx">         foreach ( $messages as $msg )
</span><span class="cx">                 echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
</span><del>-} ?>
</del><ins>+}
+
+$wp_list_table->views(); ?>
+
</ins><span class="cx"> <form method="post" action="site-themes.php?action=update-site">
</span><span class="cx">         <?php wp_nonce_field( 'edit-site' ); ?>
</span><span class="cx">         <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
</span><del>-<?php
-$themes = get_themes();
-$blog_allowed_themes = wpmu_get_blog_allowedthemes( $id );
-$allowed_themes = get_site_option( 'allowedthemes' );
</del><span class="cx">
</span><del>-if ( ! $allowed_themes )
-        $allowed_themes = array_keys( $themes );
</del><ins>+<?php $wp_list_table->display(); ?>
</ins><span class="cx">
</span><del>-$out = '';
-foreach ( $themes as $key => $theme ) {
-        $theme_key = esc_html( $theme['Stylesheet'] );
-        if ( ! isset( $allowed_themes[$theme_key] ) ) {
-                $checked = isset( $blog_allowed_themes[ $theme_key ] ) ? 'checked="checked"' : '';
-                $out .= '<tr class="form-field form-required">
-                                <th title="' . esc_attr( $theme["Description"] ).'" scope="row">' . esc_html( $key ) . '</th>
-                                <td><label><input name="theme[' . esc_attr( $theme_key ) . ']" type="checkbox" style="width:20px;" value="on" '.$checked.'/> ' . __( 'Active' ) . '</label></td>
-                        </tr>';
-        }
-}
-
-if ( $out != '' ) {
-?>
-<p class="description"><?php _e( 'Activate the themename of an existing theme and hit "Update Options" to allow the theme for this site.' ) ?></p>
-<table class="form-table">
-<?php echo $out; ?>
-</table>
-<?php
-submit_button();
-} else {
-        _e('All themes are allowed.');
-}
-?>
</del><span class="cx"> </form>
</span><span class="cx">
</span><span class="cx"> </div>
</span><del>-<?php
-require('../admin-footer.php');
</del><span class="cx">\ No newline at end of file
</span><ins>+<?php include(ABSPATH . 'wp-admin/admin-footer.php'); ?>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpadminnetworkthemesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/network/themes.php (16241 => 16242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/network/themes.php        2010-11-08 19:40:05 UTC (rev 16241)
+++ trunk/wp-admin/network/themes.php        2010-11-08 21:52:54 UTC (rev 16242)
</span><span class="lines">@@ -17,24 +17,24 @@
</span><span class="cx"> $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
</span><span class="cx">
</span><span class="cx"> // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
</span><del>-$_SERVER['REQUEST_URI'] = remove_query_arg(array('network-enable', 'network-disable', 'network-enable-selected', 'network-disable-selected'), $_SERVER['REQUEST_URI']);
</del><ins>+$_SERVER['REQUEST_URI'] = remove_query_arg(array('enable', 'disable', 'enable-selected', 'disable-selected'), $_SERVER['REQUEST_URI']);
</ins><span class="cx">
</span><span class="cx"> if ( $action ) {
</span><span class="cx">         $allowed_themes = get_site_option( 'allowedthemes' );        
</span><span class="cx">         switch ( $action ) {
</span><del>-                case 'network-enable':
</del><ins>+                case 'enable':
</ins><span class="cx">                         $allowed_themes[ $_GET['theme'] ] = true;
</span><span class="cx">                         update_site_option( 'allowedthemes', $allowed_themes );
</span><span class="cx">                         wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message
</span><span class="cx">                         exit;                        
</span><span class="cx">                         break;
</span><del>-                case 'network-disable':
</del><ins>+                case 'disable':
</ins><span class="cx">                         unset( $allowed_themes[ $_GET['theme'] ] );
</span><span class="cx">                         update_site_option( 'allowedthemes', $allowed_themes );
</span><span class="cx">                         wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message
</span><span class="cx">                         exit;
</span><span class="cx">                         break;
</span><del>-                case 'network-enable-selected':
</del><ins>+                case 'enable-selected':
</ins><span class="cx">                         $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
</span><span class="cx">                         if ( empty($themes) ) {
</span><span class="cx">                                 wp_redirect( wp_get_referer() );
</span><span class="lines">@@ -44,7 +44,7 @@
</span><span class="cx">                                 $allowed_themes[ $theme ] = true;
</span><span class="cx">                         update_site_option( 'allowedthemes', $allowed_themes );
</span><span class="cx">                         break;
</span><del>-                case 'network-disable-selected':
</del><ins>+                case 'disable-selected':
</ins><span class="cx">                         $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
</span><span class="cx">                         if ( empty($themes) ) {
</span><span class="cx">                                 wp_redirect( wp_get_referer() );
</span><span class="lines">@@ -81,7 +81,6 @@
</span><span class="cx"> <div class="wrap">
</span><span class="cx"> <?php screen_icon('themes'); ?>
</span><span class="cx"> <h2><?php echo esc_html( $title ); if ( current_user_can('install_themes') ) { ?> <a href="theme-install.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'theme'); ?></a><?php } ?></h2>
</span><del>-<p><?php _e( 'Themes must be enabled for your network before they will be available to individual sites.' ) ?></p>
</del><span class="cx">
</span><span class="cx"> <form method="get" action="">
</span><span class="cx"> <p class="search-box">
</span></span></pre>
</div>
</div>
</body>
</html>