site-themes.php cleanup. Props PeteMall. see #14897

git-svn-id: http://svn.automattic.com/wordpress/trunk@16242 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-11-08 21:52:54 +00:00
parent 39c1f5dc43
commit d08a1970de
3 changed files with 113 additions and 81 deletions

View File

@ -7,6 +7,9 @@
* @since 3.1.0 * @since 3.1.0
*/ */
class WP_MS_Themes_List_Table extends WP_List_Table { class WP_MS_Themes_List_Table extends WP_List_Table {
var $site_id;
var $is_site_themes;
function WP_MS_Themes_List_Table() { function WP_MS_Themes_List_Table() {
global $status, $page; global $status, $page;
@ -37,8 +40,10 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
} }
} }
if ( !current_user_can('manage_network_themes') ) if ( $this->is_site_themes && !current_user_can('manage_sites') )
wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) ); 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.' ) );
} }
function prepare_items() { function prepare_items() {
@ -54,11 +59,17 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
'upgrade' => array() 'upgrade' => array()
); );
$allowed_themes = get_site_allowed_themes(); $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 );
$current = get_site_transient( 'update_themes' ); $current = get_site_transient( 'update_themes' );
foreach ( (array) $themes['all'] as $key => $theme ) { foreach ( (array) $themes['all'] as $key => $theme ) {
$theme_key = esc_html( $theme['Stylesheet'] ); $theme_key = esc_html( $theme['Stylesheet'] );
if ( isset( $allowed_themes [ $theme_key ] ) ) { if ( isset( $allowed_themes [ $theme_key ] ) ) {
$themes['all'][$key]['enabled'] = true; $themes['all'][$key]['enabled'] = true;
$themes['enabled'][$key] = $themes['all'][$key]; $themes['enabled'][$key] = $themes['all'][$key];
@ -69,6 +80,12 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
} }
if ( isset( $current->response[ $theme['Template'] ] ) ) if ( isset( $current->response[ $theme['Template'] ] ) )
$themes['upgrade'][$key] = $themes['all'][$key]; $themes['upgrade'][$key] = $themes['all'][$key];
if ( $this->is_site_themes && isset( $site_allowed_themes[$theme_key] ) ) {
unset( $themes['all'][$key] );
unset( $themes['enabled'][$key] );
unset( $themes['disabled'][$key] );
}
} }
if ( !current_user_can( 'update_themes' ) ) if ( !current_user_can( 'update_themes' ) )
@ -188,8 +205,13 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
break; break;
} }
if ( $this->is_site_themes )
$url = 'site-themes.php?id=' . $this->site_id;
else
$url = 'themes.php';
$status_links[$type] = sprintf( "<a href='%s' %s>%s</a>", $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
add_query_arg('theme_status', $type, 'themes.php'), add_query_arg('theme_status', $type, $url),
( $type == $status ) ? ' class="current"' : '', ( $type == $status ) ? ' class="current"' : '',
sprintf( $text, number_format_i18n( $count ) ) sprintf( $text, number_format_i18n( $count ) )
); );
@ -203,9 +225,9 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$actions = array(); $actions = array();
if ( 'enabled' != $status ) if ( 'enabled' != $status )
$actions['network-enable-selected'] = __( 'Enable' ); $actions['enable-selected'] = __( 'Enable' );
if ( 'disabled' != $status ) if ( 'disabled' != $status )
$actions['network-disable-selected'] = __( 'Disable' ); $actions['disable-selected'] = __( 'Disable' );
if ( current_user_can( 'update_themes' ) ) if ( current_user_can( 'update_themes' ) )
$actions['update-selected'] = __( 'Update' ); $actions['update-selected'] = __( 'Update' );
@ -225,24 +247,26 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
global $status, $page, $s; global $status, $page, $s;
$context = $status; $context = $status;
if ( $this->is_site_themes )
$url = "site-themes.php?id={$this->site_id}&amp;";
else
$url = 'themes.php?';
foreach ( $this->items as $key => $theme ) { foreach ( $this->items as $key => $theme ) {
// preorder // preorder
$actions = array( $actions = array(
'network_enable' => '', 'enable' => '',
'network_disable' => '', 'disable' => '',
'edit' => '' 'edit' => ''
); );
$theme_key = esc_html( $theme['Stylesheet'] ); $theme_key = esc_html( $theme['Stylesheet'] );
if ( empty( $theme['enabled'] ) ) { if ( empty( $theme['enabled'] ) )
if ( current_user_can( 'manage_network_themes' ) ) $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>';
$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
} 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>';
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>';
}
if ( current_user_can('edit_themes') ) if ( current_user_can('edit_themes') )
$actions['edit'] = '<a href="theme-editor.php?theme=' . $theme['Name'] . '" title="' . __('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>'; $actions['edit'] = '<a href="theme-editor.php?theme=' . $theme['Name'] . '" title="' . __('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';

View File

@ -1,26 +1,32 @@
<?php <?php
/** /**
* Edit Site Themes Administration Screen * Multisite themes administration panel.
* *
* @package WordPress * @package WordPress
* @subpackage Administration * @subpackage Multisite
* @since 3.1.0 * @since 3.1.0
*/ */
/** Load WordPress Administration Bootstrap */ require_once( './admin.php' );
require_once('./admin.php');
if ( ! is_multisite() ) $wp_list_table = get_list_table('WP_MS_Themes_List_Table');
wp_die( __( 'Multisite support is not enabled.' ) ); $wp_list_table->check_permissions();
if ( ! current_user_can('manage_sites') ) $action = $wp_list_table->current_action();
wp_die(__('You do not have sufficient permissions to edit this site.'));
$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']);
$id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
if ( ! $id ) if ( ! $id )
wp_die( __('Invalid site ID.') ); wp_die( __('Invalid site ID.') );
$wp_list_table->site_id = $id;
$wp_list_table->is_site_themes = true;
$wp_list_table->prepare_items();
$details = get_blog_details( $id ); $details = get_blog_details( $id );
if ( $details->site_id != $wpdb->siteid ) if ( $details->site_id != $wpdb->siteid )
@ -28,28 +34,52 @@ if ( $details->site_id != $wpdb->siteid )
$is_main_site = is_main_site( $id ); $is_main_site = is_main_site( $id );
if ( isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] ) { if ( $action ) {
check_admin_referer( 'edit-site' );
switch_to_blog( $id ); switch_to_blog( $id );
$allowed_themes = get_option( 'allowedthemes' );
$allowedthemes = array(); switch ( $action ) {
if ( isset($_POST['theme']) && is_array( $_POST['theme'] ) ) { case 'enable':
foreach ( $_POST['theme'] as $theme => $val ) { $theme = $_GET['theme'];
if ( 'on' == $val ) if ( !$allowed_themes )
$allowedthemes[$theme] = true; $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;
} }
update_option( 'allowedthemes', $allowedthemes );
update_option( 'allowedthemes', $allowed_themes );
restore_current_blog(); restore_current_blog();
wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-themes.php') );
} wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message
exit;
if ( isset($_GET['update']) ) {
$messages = array();
if ( 'updated' == $_GET['update'] )
$messages[] = __('Site users updated.');
} }
$title = sprintf( __('Edit Site: %s'), get_blogaddress_by_id($id)); $title = sprintf( __('Edit Site: %s'), get_blogaddress_by_id($id));
@ -58,6 +88,11 @@ $submenu_file = 'sites.php';
require('../admin-header.php'); require('../admin-header.php');
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');
?> ?>
<div class="wrap"> <div class="wrap">
@ -73,48 +108,22 @@ foreach ( $tabs as $tab_id => $tab ) {
} }
?> ?>
</h3> </h3>
<p class="description"><?php _e( 'Network enabled themes are not shown on this screen.' ) ?></p>
<?php <?php
if ( ! empty( $messages ) ) { if ( ! empty( $messages ) ) {
foreach ( $messages as $msg ) foreach ( $messages as $msg )
echo '<div id="message" class="updated"><p>' . $msg . '</p></div>'; echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
} ?> }
$wp_list_table->views(); ?>
<form method="post" action="site-themes.php?action=update-site"> <form method="post" action="site-themes.php?action=update-site">
<?php wp_nonce_field( 'edit-site' ); ?> <?php wp_nonce_field( 'edit-site' ); ?>
<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /> <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
<?php
$themes = get_themes();
$blog_allowed_themes = wpmu_get_blog_allowedthemes( $id );
$allowed_themes = get_site_option( 'allowedthemes' );
if ( ! $allowed_themes ) <?php $wp_list_table->display(); ?>
$allowed_themes = array_keys( $themes );
$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.');
}
?>
</form> </form>
</div> </div>
<?php <?php include(ABSPATH . 'wp-admin/admin-footer.php'); ?>
require('../admin-footer.php');

View File

@ -17,24 +17,24 @@ $action = $wp_list_table->current_action();
$s = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
// Clean up request URI from temporary args for screen options/paging uri's to work as expected. // 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']); $_SERVER['REQUEST_URI'] = remove_query_arg(array('enable', 'disable', 'enable-selected', 'disable-selected'), $_SERVER['REQUEST_URI']);
if ( $action ) { if ( $action ) {
$allowed_themes = get_site_option( 'allowedthemes' ); $allowed_themes = get_site_option( 'allowedthemes' );
switch ( $action ) { switch ( $action ) {
case 'network-enable': case 'enable':
$allowed_themes[ $_GET['theme'] ] = true; $allowed_themes[ $_GET['theme'] ] = true;
update_site_option( 'allowedthemes', $allowed_themes ); update_site_option( 'allowedthemes', $allowed_themes );
wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message
exit; exit;
break; break;
case 'network-disable': case 'disable':
unset( $allowed_themes[ $_GET['theme'] ] ); unset( $allowed_themes[ $_GET['theme'] ] );
update_site_option( 'allowedthemes', $allowed_themes ); update_site_option( 'allowedthemes', $allowed_themes );
wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message
exit; exit;
break; break;
case 'network-enable-selected': case 'enable-selected':
$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
if ( empty($themes) ) { if ( empty($themes) ) {
wp_redirect( wp_get_referer() ); wp_redirect( wp_get_referer() );
@ -44,7 +44,7 @@ if ( $action ) {
$allowed_themes[ $theme ] = true; $allowed_themes[ $theme ] = true;
update_site_option( 'allowedthemes', $allowed_themes ); update_site_option( 'allowedthemes', $allowed_themes );
break; break;
case 'network-disable-selected': case 'disable-selected':
$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
if ( empty($themes) ) { if ( empty($themes) ) {
wp_redirect( wp_get_referer() ); wp_redirect( wp_get_referer() );
@ -81,7 +81,6 @@ require_once(ABSPATH . 'wp-admin/admin-header.php');
<div class="wrap"> <div class="wrap">
<?php screen_icon('themes'); ?> <?php screen_icon('themes'); ?>
<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> <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>
<p><?php _e( 'Themes must be enabled for your network before they will be available to individual sites.' ) ?></p>
<form method="get" action=""> <form method="get" action="">
<p class="search-box"> <p class="search-box">