From b58a795627116fbc322ab9e5f0c1eb546f06ec90 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 24 Dec 2010 17:41:36 +0000 Subject: [PATCH] MS themes fixes. Fix bulk actions when no items selected. Props SergeyBiryukov, nacin. fixes #15920 git-svn-id: https://develop.svn.wordpress.org/trunk@17130 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-ms-themes-list-table.php | 8 +-- wp-admin/network/themes.php | 57 +++++++++++++------ 2 files changed, 45 insertions(+), 20 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 e64d226d9f..e0f3378626 100644 --- a/wp-admin/includes/class-wp-ms-themes-list-table.php +++ b/wp-admin/includes/class-wp-ms-themes-list-table.php @@ -78,7 +78,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table { $current = get_site_transient( 'update_themes' ); foreach ( (array) $themes['all'] as $key => $theme ) { - $theme_key = esc_html( $theme['Stylesheet'] ); + $theme_key = $theme['Stylesheet']; if ( isset( $allowed_themes [ $theme_key ] ) ) { $themes['all'][$key]['enabled'] = true; @@ -276,7 +276,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table { 'delete' => '' ); - $theme_key = esc_html( $theme['Stylesheet'] ); + $theme_key = $theme['Stylesheet']; if ( empty( $theme['enabled'] ) ) $actions['enable'] = '' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . ''; @@ -285,8 +285,8 @@ class WP_MS_Themes_List_Table extends WP_List_Table { if ( current_user_can('edit_themes') ) $actions['edit'] = '' . __('Edit') . ''; - - if ( empty( $theme['enabled'] ) && current_user_can( 'delete_themes' ) && ! $this->is_site_themes ) + + if ( empty( $theme['enabled'] ) && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $theme_key != get_option( 'stylesheet' ) && $theme_key != get_option( 'template' ) ) $actions['delete'] = '' . __( 'Delete' ) . ''; $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context ); diff --git a/wp-admin/network/themes.php b/wp-admin/network/themes.php index f3ee6bc676..825ddb8a74 100644 --- a/wp-admin/network/themes.php +++ b/wp-admin/network/themes.php @@ -28,7 +28,9 @@ $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('enable', 'disable', 'enable-selected', 'disable-selected'), $_SERVER['REQUEST_URI']); +$temp_args = array( 'enabled', 'disabled', 'deleted', 'error', 'enabled', 'disabled', 'deleted', 'error' ); +$_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] ); +$referer = remove_query_arg( $temp_args, wp_get_referer() ); if ( $action ) { $allowed_themes = get_site_option( 'allowedthemes' ); @@ -37,37 +39,41 @@ if ( $action ) { check_admin_referer('enable-theme_' . $_GET['theme']); $allowed_themes[ $_GET['theme'] ] = true; update_site_option( 'allowedthemes', $allowed_themes ); - wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message - exit; + wp_redirect( add_query_arg( 'enabled', '1', $referer ) ); + exit; break; case 'disable': check_admin_referer('disable-theme_' . $_GET['theme']); unset( $allowed_themes[ $_GET['theme'] ] ); update_site_option( 'allowedthemes', $allowed_themes ); - wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message + wp_redirect( add_query_arg( 'disabled', '1', $referer ) ); exit; break; case 'enable-selected': check_admin_referer('bulk-themes'); $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); if ( empty($themes) ) { - wp_redirect( wp_get_referer() ); + wp_redirect( add_query_arg( 'error', 'none', $referer ) ); exit; - } + } foreach( (array) $themes as $theme ) $allowed_themes[ $theme ] = true; update_site_option( 'allowedthemes', $allowed_themes ); + wp_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) ); + exit; break; case 'disable-selected': check_admin_referer('bulk-themes'); $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); if ( empty($themes) ) { - wp_redirect( wp_get_referer() ); + wp_redirect( add_query_arg( 'error', 'none', $referer ) ); exit; - } + } foreach( (array) $themes as $theme ) unset( $allowed_themes[ $theme ] ); update_site_option( 'allowedthemes', $allowed_themes ); + wp_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) ); + exit; break; case 'delete-selected': if ( ! current_user_can( 'delete_themes' ) ) @@ -75,8 +81,14 @@ if ( $action ) { check_admin_referer( 'bulk-themes' ); $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array(); + + if ( isset( $themes[ get_option( 'template' ) ] ) ) + unset( $themes[ get_option( 'template' ) ] ); + if ( isset( $themes[ get_option( 'stylesheet' ) ] ) ) + unset( $themes[ get_option( 'stylesheet' ) ] ); + if ( empty( $themes ) ) { - wp_redirect( wp_get_referer() ); + wp_redirect( add_query_arg( 'error', 'none', $referer ) ); exit; } @@ -93,7 +105,7 @@ if ( $action ) { } if ( empty( $themes ) ) { - wp_redirect( add_query_arg( 'error', 'main', wp_get_referer() ) ); + wp_redirect( add_query_arg( 'error', 'main', $referer ) ); exit; } @@ -149,7 +161,7 @@ if ( $action ) { foreach ( $themes as $theme ) $delete_result = delete_theme( $theme ); - wp_redirect( network_admin_url( 'themes.php?deleted=true' ) ); + wp_redirect( add_query_arg( 'deleted', count( $themes ), $referer ) ); exit; break; } @@ -174,11 +186,6 @@ $parent_file = 'themes.php'; require_once(ABSPATH . 'wp-admin/admin-header.php'); -if ( isset( $_GET['deleted'] ) ) : ?> -

-

@@ -188,6 +195,24 @@ if ( $s ) printf( '' . __('Search results for “%s”') . '', esc_html( $s ) ); ?> +

' . sprintf( _n( 'Theme enabled.', '%s themes enabled.', $_GET['enabled'] ), number_format_i18n( $_GET['enabled'] ) ) . '

'; +} elseif ( isset( $_GET['disabled'] ) ) { + $_GET['disabled'] = absint( $_GET['disabled'] ); + echo '

' . sprintf( _n( 'Theme disabled.', '%s themes disabled.', $_GET['disabled'] ), number_format_i18n( $_GET['disabled'] ) ) . '

'; +} elseif ( isset( $_GET['deleted'] ) ) { + $_GET['disabled'] = absint( $_GET['deleted'] ); + echo '

' . sprintf( _n( 'Theme deleted.', '%s themes deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) ) . '

'; +} elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) { + echo '

' . __( 'No theme selected.' ) . '

'; +} elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) { + echo '

' . __( 'You cannot delete a theme while it is active on the main site.' ) . '

'; +} + +?> +
search_box( __( 'Search Installed Themes' ), 'theme' ); ?>