MS themes fixes. Fix bulk actions when no items selected. Props SergeyBiryukov, nacin. fixes #15920

git-svn-id: http://svn.automattic.com/wordpress/trunk@17130 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-12-24 17:41:36 +00:00
parent b0be8cd9f4
commit 625a229313
2 changed files with 45 additions and 20 deletions

View File

@ -78,7 +78,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$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 = $theme['Stylesheet'];
if ( isset( $allowed_themes [ $theme_key ] ) ) { if ( isset( $allowed_themes [ $theme_key ] ) ) {
$themes['all'][$key]['enabled'] = true; $themes['all'][$key]['enabled'] = true;
@ -276,7 +276,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
'delete' => '' 'delete' => ''
); );
$theme_key = esc_html( $theme['Stylesheet'] ); $theme_key = $theme['Stylesheet'];
if ( empty( $theme['enabled'] ) ) if ( empty( $theme['enabled'] ) )
$actions['enable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=enable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'enable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Enable this theme') . '" class="edit">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>'; $actions['enable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=enable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'enable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Enable this theme') . '" class="edit">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>';
@ -285,8 +285,8 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
if ( current_user_can('edit_themes') ) if ( current_user_can('edit_themes') )
$actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' . $theme['Name'] ) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>'; $actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' . $theme['Name'] ) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
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'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=delete-selected&amp;checked[]=' . $theme_key . '&amp;theme_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-themes' ) ) . '" title="' . esc_attr__( 'Delete this theme' ) . '" class="delete">' . __( 'Delete' ) . '</a>'; $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=delete-selected&amp;checked[]=' . $theme_key . '&amp;theme_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-themes' ) ) . '" title="' . esc_attr__( 'Delete this theme' ) . '" class="delete">' . __( 'Delete' ) . '</a>';
$actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context ); $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context );

View File

@ -28,7 +28,9 @@ $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('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 ) { if ( $action ) {
$allowed_themes = get_site_option( 'allowedthemes' ); $allowed_themes = get_site_option( 'allowedthemes' );
@ -37,37 +39,41 @@ if ( $action ) {
check_admin_referer('enable-theme_' . $_GET['theme']); check_admin_referer('enable-theme_' . $_GET['theme']);
$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( add_query_arg( 'enabled', '1', $referer ) );
exit; exit;
break; break;
case 'disable': case 'disable':
check_admin_referer('disable-theme_' . $_GET['theme']); check_admin_referer('disable-theme_' . $_GET['theme']);
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( add_query_arg( 'disabled', '1', $referer ) );
exit; exit;
break; break;
case 'enable-selected': case 'enable-selected':
check_admin_referer('bulk-themes'); check_admin_referer('bulk-themes');
$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( add_query_arg( 'error', 'none', $referer ) );
exit; exit;
} }
foreach( (array) $themes as $theme ) foreach( (array) $themes as $theme )
$allowed_themes[ $theme ] = true; $allowed_themes[ $theme ] = true;
update_site_option( 'allowedthemes', $allowed_themes ); update_site_option( 'allowedthemes', $allowed_themes );
wp_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
exit;
break; break;
case 'disable-selected': case 'disable-selected':
check_admin_referer('bulk-themes'); check_admin_referer('bulk-themes');
$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( add_query_arg( 'error', 'none', $referer ) );
exit; exit;
} }
foreach( (array) $themes as $theme ) foreach( (array) $themes as $theme )
unset( $allowed_themes[ $theme ] ); unset( $allowed_themes[ $theme ] );
update_site_option( 'allowedthemes', $allowed_themes ); update_site_option( 'allowedthemes', $allowed_themes );
wp_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
exit;
break; break;
case 'delete-selected': case 'delete-selected':
if ( ! current_user_can( 'delete_themes' ) ) if ( ! current_user_can( 'delete_themes' ) )
@ -75,8 +81,14 @@ if ( $action ) {
check_admin_referer( 'bulk-themes' ); check_admin_referer( 'bulk-themes' );
$themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array(); $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 ) ) { if ( empty( $themes ) ) {
wp_redirect( wp_get_referer() ); wp_redirect( add_query_arg( 'error', 'none', $referer ) );
exit; exit;
} }
@ -93,7 +105,7 @@ if ( $action ) {
} }
if ( empty( $themes ) ) { if ( empty( $themes ) ) {
wp_redirect( add_query_arg( 'error', 'main', wp_get_referer() ) ); wp_redirect( add_query_arg( 'error', 'main', $referer ) );
exit; exit;
} }
@ -149,7 +161,7 @@ if ( $action ) {
foreach ( $themes as $theme ) foreach ( $themes as $theme )
$delete_result = delete_theme( $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; exit;
break; break;
} }
@ -174,11 +186,6 @@ $parent_file = 'themes.php';
require_once(ABSPATH . 'wp-admin/admin-header.php'); require_once(ABSPATH . 'wp-admin/admin-header.php');
if ( isset( $_GET['deleted'] ) ) : ?>
<div class="updated"><p><?php _e('Theme deleted.') ?></p></div><?php
elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) : ?>
<div class="error"><p><?php _e( 'You cannot delete a theme while it is active on the main site.' ); ?></p></div><?php
endif;
?> ?>
<div class="wrap"> <div class="wrap">
@ -188,6 +195,24 @@ if ( $s )
printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?> printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?>
</h2> </h2>
<?php
if ( isset( $_GET['enabled'] ) ) {
$_GET['enabled'] = absint( $_GET['enabled'] );
echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme enabled.', '%s themes enabled.', $_GET['enabled'] ), number_format_i18n( $_GET['enabled'] ) ) . '</p></div>';
} elseif ( isset( $_GET['disabled'] ) ) {
$_GET['disabled'] = absint( $_GET['disabled'] );
echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme disabled.', '%s themes disabled.', $_GET['disabled'] ), number_format_i18n( $_GET['disabled'] ) ) . '</p></div>';
} elseif ( isset( $_GET['deleted'] ) ) {
$_GET['disabled'] = absint( $_GET['deleted'] );
echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme deleted.', '%s themes deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) ) . '</p></div>';
} elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
echo '<div id="message" class="error"><p>' . __( 'No theme selected.' ) . '</p></div>';
} elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) {
echo '<div class="error"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
}
?>
<form method="get" action=""> <form method="get" action="">
<?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?> <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
</form> </form>