Ticket #15920: 15920.diff

File 15920.diff, 7.4 KB (added by nacin, 2 years ago)
  • wp-admin/includes/class-wp-ms-themes-list-table.php

     
    7878                $current = get_site_transient( 'update_themes' ); 
    7979 
    8080                foreach ( (array) $themes['all'] as $key => $theme ) { 
    81                         $theme_key = esc_html( $theme['Stylesheet'] ); 
     81                        $theme_key = $theme['Stylesheet']; 
    8282 
    8383                        if ( isset( $allowed_themes [ $theme_key ] ) )  { 
    8484                                $themes['all'][$key]['enabled'] = true; 
     
    276276                        'delete' => '' 
    277277                ); 
    278278 
    279                 $theme_key = esc_html( $theme['Stylesheet'] ); 
     279                $theme_key = $theme['Stylesheet']; 
    280280 
    281281                if ( empty( $theme['enabled'] ) ) 
    282282                        $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>'; 
     
    285285 
    286286                if ( current_user_can('edit_themes') ) 
    287287                        $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>'; 
    288                          
    289                 if ( empty( $theme['enabled'] ) && current_user_can( 'delete_themes' ) && ! $this->is_site_themes ) 
     288 
     289                if ( empty( $theme['enabled'] ) && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $theme_key != get_option( 'stylesheet' ) && $theme_key != get_option( 'template' ) ) 
    290290                        $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>'; 
    291291 
    292292                $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context ); 
  • wp-admin/network/themes.php

     
    2828$s = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; 
    2929 
    3030// Clean up request URI from temporary args for screen options/paging uri's to work as expected. 
    31 $_SERVER['REQUEST_URI'] = remove_query_arg(array('enable', 'disable', 'enable-selected', 'disable-selected'), $_SERVER['REQUEST_URI']); 
     31$referer = remove_query_arg( array( 'enable', 'disable', 'enable-selected', 'disable-selected', 
     32        'enabled', 'disabled', 'deleted', 'error'), wp_get_referer() ); 
    3233 
    3334if ( $action ) { 
    3435        $allowed_themes = get_site_option( 'allowedthemes' );    
     
    3738                        check_admin_referer('enable-theme_' . $_GET['theme']); 
    3839                        $allowed_themes[ $_GET['theme'] ] = true; 
    3940                        update_site_option( 'allowedthemes', $allowed_themes ); 
    40                         wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message 
    41                         exit;                    
     41                        wp_redirect( add_query_arg( 'enabled', '1', $referer ) ); 
     42                        exit; 
    4243                        break; 
    4344                case 'disable': 
    4445                        check_admin_referer('disable-theme_' . $_GET['theme']); 
    4546                        unset( $allowed_themes[ $_GET['theme'] ] ); 
    4647                        update_site_option( 'allowedthemes', $allowed_themes ); 
    47                         wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message 
     48                        wp_redirect( add_query_arg( 'disabled', '1', $referer ) ); 
    4849                        exit; 
    4950                        break; 
    5051                case 'enable-selected': 
    5152                        check_admin_referer('bulk-themes'); 
    5253                        $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 
    5354                        if ( empty($themes) ) { 
    54                                 wp_redirect( wp_get_referer() ); 
     55                                wp_redirect( add_query_arg( 'error', 'none', $referer ) ); 
    5556                                exit; 
    56                         }                                                
     57                        } 
    5758                        foreach( (array) $themes as $theme ) 
    5859                                $allowed_themes[ $theme ] = true; 
    5960                        update_site_option( 'allowedthemes', $allowed_themes ); 
     61                        wp_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) ); 
     62                        exit; 
    6063                        break; 
    6164                case 'disable-selected': 
    6265                        check_admin_referer('bulk-themes'); 
    6366                        $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 
    6467                        if ( empty($themes) ) { 
    65                                 wp_redirect( wp_get_referer() ); 
     68                                wp_redirect( add_query_arg( 'error', 'none', $referer ) ); 
    6669                                exit; 
    67                         }                                                
     70                        } 
    6871                        foreach( (array) $themes as $theme ) 
    6972                                unset( $allowed_themes[ $theme ] ); 
    7073                        update_site_option( 'allowedthemes', $allowed_themes ); 
     74                        wp_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) ); 
     75                        exit; 
    7176                        break; 
    7277                case 'delete-selected': 
    7378                        if ( ! current_user_can( 'delete_themes' ) ) 
     
    7580                        check_admin_referer( 'bulk-themes' ); 
    7681 
    7782                        $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array(); 
     83 
     84                        if ( isset( $themes[ get_option( 'template' ) ] ) ) 
     85                                unset( $themes[ get_option( 'template' ) ] ); 
     86                        if ( isset( $themes[ get_option( 'stylesheet' ) ] ) ) 
     87                                unset( $themes[ get_option( 'stylesheet' ) ] ); 
     88 
    7889                        if ( empty( $themes ) ) { 
    79                                 wp_redirect( wp_get_referer() ); 
     90                                wp_redirect( add_query_arg( 'error', 'none', $referer ) ); 
    8091                                exit; 
    8192                        } 
    8293 
     
    93104                        } 
    94105                         
    95106                        if ( empty( $themes ) ) { 
    96                                 wp_redirect( add_query_arg( 'error', 'main', wp_get_referer() ) ); 
     107                                wp_redirect( add_query_arg( 'error', 'main', $referer ) ); 
    97108                                exit; 
    98109                        } 
    99110 
     
    149160 
    150161                        foreach ( $themes as $theme ) 
    151162                                $delete_result = delete_theme( $theme ); 
    152                         wp_redirect( network_admin_url( 'themes.php?deleted=true' ) ); 
     163                        wp_redirect( add_query_arg( 'deleted', count( $themes ), $referer ) ); 
    153164                        exit; 
    154165                        break; 
    155166        } 
     
    174185 
    175186require_once(ABSPATH . 'wp-admin/admin-header.php'); 
    176187 
    177 if ( isset( $_GET['deleted'] ) ) : ?> 
    178 <div class="updated"><p><?php _e('Theme deleted.') ?></p></div><?php 
    179 elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) : ?> 
    180 <div class="error"><p><?php _e( 'You cannot delete a theme while it is active on the main site.' ); ?></p></div><?php 
    181 endif; 
    182188?> 
    183189 
    184190<div class="wrap"> 
     
    188194        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?>  
    189195</h2> 
    190196 
     197<?php 
     198if ( isset( $_GET['enabled'] ) ) { 
     199        $_GET['enabled'] = absint( $_GET['enabled'] ); 
     200        echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme enabled.', '%s themes enabled.', $_GET['enabled'] ), number_format_i18n( $_GET['enabled'] ) ) . '</p></div>'; 
     201} elseif ( isset( $_GET['disabled'] ) ) { 
     202        $_GET['disabled'] = absint( $_GET['disabled'] ); 
     203        echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme disabled.', '%s themes disabled.', $_GET['disabled'] ), number_format_i18n( $_GET['disabled'] ) ) . '</p></div>'; 
     204} elseif ( isset( $_GET['deleted'] ) ) { 
     205        $_GET['disabled'] = absint( $_GET['deleted'] ); 
     206        echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme deleted.', '%s themes deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) ) . '</p></div>'; 
     207} elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) { 
     208        echo '<div id="message" class="error"><p>' . __( 'No theme selected.' ) . '</p></div>'; 
     209} elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) { 
     210        echo '<div class="error"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>'; 
     211} 
     212 
     213?> 
     214 
    191215<form method="get" action=""> 
    192216<?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?> 
    193217</form>