From 03d34fd1f843963c98b889d379222aa937a7c2f9 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Mon, 8 Nov 2010 21:52:54 +0000 Subject: [PATCH] site-themes.php cleanup. Props PeteMall. see #14897 git-svn-id: https://develop.svn.wordpress.org/trunk@16242 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-ms-themes-list-table.php | 54 ++++++-- wp-admin/network/site-themes.php | 129 ++++++++++-------- wp-admin/network/themes.php | 11 +- 3 files changed, 113 insertions(+), 81 deletions(-) diff --git a/wp-admin/includes/class-wp-ms-themes-list-table.php b/wp-admin/includes/class-wp-ms-themes-list-table.php index e57697a5c2..2a71e7e520 100644 --- a/wp-admin/includes/class-wp-ms-themes-list-table.php +++ b/wp-admin/includes/class-wp-ms-themes-list-table.php @@ -7,6 +7,9 @@ * @since 3.1.0 */ class WP_MS_Themes_List_Table extends WP_List_Table { + + var $site_id; + var $is_site_themes; function WP_MS_Themes_List_Table() { global $status, $page; @@ -37,8 +40,10 @@ class WP_MS_Themes_List_Table extends WP_List_Table { } } - if ( !current_user_can('manage_network_themes') ) - wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) ); + 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.' ) ); } function prepare_items() { @@ -54,11 +59,17 @@ class WP_MS_Themes_List_Table extends WP_List_Table { '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' ); foreach ( (array) $themes['all'] as $key => $theme ) { $theme_key = esc_html( $theme['Stylesheet'] ); + if ( isset( $allowed_themes [ $theme_key ] ) ) { $themes['all'][$key]['enabled'] = true; $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'] ] ) ) $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' ) ) @@ -188,8 +205,13 @@ class WP_MS_Themes_List_Table extends WP_List_Table { break; } + if ( $this->is_site_themes ) + $url = 'site-themes.php?id=' . $this->site_id; + else + $url = 'themes.php'; + $status_links[$type] = sprintf( "%s", - add_query_arg('theme_status', $type, 'themes.php'), + add_query_arg('theme_status', $type, $url), ( $type == $status ) ? ' class="current"' : '', sprintf( $text, number_format_i18n( $count ) ) ); @@ -203,9 +225,9 @@ class WP_MS_Themes_List_Table extends WP_List_Table { $actions = array(); if ( 'enabled' != $status ) - $actions['network-enable-selected'] = __( 'Enable' ); + $actions['enable-selected'] = __( 'Enable' ); if ( 'disabled' != $status ) - $actions['network-disable-selected'] = __( 'Disable' ); + $actions['disable-selected'] = __( 'Disable' ); if ( current_user_can( 'update_themes' ) ) $actions['update-selected'] = __( 'Update' ); @@ -225,24 +247,26 @@ class WP_MS_Themes_List_Table extends WP_List_Table { global $status, $page, $s; $context = $status; + + if ( $this->is_site_themes ) + $url = "site-themes.php?id={$this->site_id}&"; + else + $url = 'themes.php?'; foreach ( $this->items as $key => $theme ) { // preorder $actions = array( - 'network_enable' => '', - 'network_disable' => '', + 'enable' => '', + 'disable' => '', 'edit' => '' ); $theme_key = esc_html( $theme['Stylesheet'] ); - if ( empty( $theme['enabled'] ) ) { - if ( current_user_can( 'manage_network_themes' ) ) - $actions['network_enable'] = '' . __('Enable') . ''; - } else { - if ( current_user_can( 'manage_network_themes' ) ) - $actions['network_disable'] = '' . __('Disable') . ''; - } + if ( empty( $theme['enabled'] ) ) + $actions['enable'] = '' . __('Enable') . ''; + else + $actions['disable'] = '' . __('Disable') . ''; if ( current_user_can('edit_themes') ) $actions['edit'] = '' . __('Edit') . ''; diff --git a/wp-admin/network/site-themes.php b/wp-admin/network/site-themes.php index 008d65ec83..0b8ae63160 100644 --- a/wp-admin/network/site-themes.php +++ b/wp-admin/network/site-themes.php @@ -1,26 +1,32 @@ check_permissions(); -if ( ! current_user_can('manage_sites') ) - wp_die(__('You do not have sufficient permissions to edit this site.')); +$action = $wp_list_table->current_action(); + +$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; if ( ! $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 ); if ( $details->site_id != $wpdb->siteid ) @@ -28,28 +34,52 @@ if ( $details->site_id != $wpdb->siteid ) $is_main_site = is_main_site( $id ); -if ( isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] ) { - check_admin_referer( 'edit-site' ); - +if ( $action ) { switch_to_blog( $id ); + $allowed_themes = get_option( 'allowedthemes' ); - $allowedthemes = array(); - if ( isset($_POST['theme']) && is_array( $_POST['theme'] ) ) { - foreach ( $_POST['theme'] as $theme => $val ) { - if ( 'on' == $val ) - $allowedthemes[$theme] = true; - } + 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; } - update_option( 'allowedthemes', $allowedthemes ); - + + update_option( 'allowedthemes', $allowed_themes ); restore_current_blog(); - wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-themes.php') ); -} - -if ( isset($_GET['update']) ) { - $messages = array(); - if ( 'updated' == $_GET['update'] ) - $messages[] = __('Site users updated.'); + + wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message + exit; } $title = sprintf( __('Edit Site: %s'), get_blogaddress_by_id($id)); @@ -58,6 +88,11 @@ $submenu_file = 'sites.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'); ?>
@@ -73,48 +108,22 @@ foreach ( $tabs as $tab_id => $tab ) { } ?> +

' . $msg . '

'; -} ?> +} + +$wp_list_table->views(); ?> +
-display(); ?> -$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 .= ' - ' . esc_html( $key ) . ' - - '; - } -} - -if ( $out != '' ) { -?> -

- - -
-
- \ No newline at end of file diff --git a/wp-admin/network/themes.php b/wp-admin/network/themes.php index f64b5addaf..1b87fc84b0 100644 --- a/wp-admin/network/themes.php +++ b/wp-admin/network/themes.php @@ -17,24 +17,24 @@ $action = $wp_list_table->current_action(); $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']); +$_SERVER['REQUEST_URI'] = remove_query_arg(array('enable', 'disable', 'enable-selected', 'disable-selected'), $_SERVER['REQUEST_URI']); if ( $action ) { $allowed_themes = get_site_option( 'allowedthemes' ); switch ( $action ) { - case 'network-enable': + case 'enable': $allowed_themes[ $_GET['theme'] ] = true; update_site_option( 'allowedthemes', $allowed_themes ); wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message exit; break; - case 'network-disable': + case 'disable': unset( $allowed_themes[ $_GET['theme'] ] ); update_site_option( 'allowedthemes', $allowed_themes ); wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message exit; break; - case 'network-enable-selected': + case 'enable-selected': $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); if ( empty($themes) ) { wp_redirect( wp_get_referer() ); @@ -44,7 +44,7 @@ if ( $action ) { $allowed_themes[ $theme ] = true; update_site_option( 'allowedthemes', $allowed_themes ); break; - case 'network-disable-selected': + case 'disable-selected': $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); if ( empty($themes) ) { wp_redirect( wp_get_referer() ); @@ -81,7 +81,6 @@ require_once(ABSPATH . 'wp-admin/admin-header.php');

-