WordPress.org

Make WordPress Core

Changeset 17101


Ignore:
Timestamp:
12/21/10 16:50:16 (5 years ago)
Author:
ryan
Message:

Add delete support to network themes. Props PeteMall. fixes #15707

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-ms-themes-list-table.php

    r17050 r17101  
    232232        if ( 'disabled' != $status ) 
    233233            $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ); 
    234         if ( current_user_can( 'update_themes' ) && !$this->is_site_themes ) 
    235             $actions['update-selected'] = __( 'Update' ); 
    236  
     234        if ( ! $this->is_site_themes ) { 
     235            if ( current_user_can( 'delete_themes' ) ) 
     236                $actions['delete-selected'] = __( 'Delete' ); 
     237            if ( current_user_can( 'update_themes' ) ) 
     238                $actions['update-selected'] = __( 'Update' ); 
     239        } 
    237240        return $actions; 
    238241    } 
     
    266269            'enable' => '', 
    267270            'disable' => '', 
    268             'edit' => '' 
     271            'edit' => '', 
     272            'delete' => '' 
    269273        ); 
    270274 
     
    272276 
    273277        if ( empty( $theme['enabled'] ) ) 
    274             $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">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>'; 
     278            $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>'; 
    275279        else 
    276             $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') . '">' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '</a>'; 
     280            $actions['disable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=disable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'disable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Disable this theme') . '">' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '</a>'; 
    277281 
    278282        if ( current_user_can('edit_themes') ) 
    279             $actions['edit'] = '<a href="theme-editor.php?theme=' . $theme['Name'] . '" title="' . __('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>'; 
     283            $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>'; 
     284             
     285        if ( empty( $theme['enabled'] ) && current_user_can( 'delete_themes' ) && ! $this->is_site_themes ) 
     286            $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>'; 
    280287 
    281288        $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context ); 
    282289        $actions = apply_filters( "theme_action_links_$theme_key", $actions, $theme_key, $theme, $context ); 
    283  
     290  
    284291        $class = empty( $theme['enabled'] ) ? 'inactive' : 'active'; 
    285292        $checkbox_id = md5($theme['Name']) . "_checkbox"; 
     
    320327                        $author = $theme['Author']; 
    321328                        if ( !empty( $theme['Author URI'] ) ) 
    322                             $author = '<a href="' . $theme['Author URI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $theme['Author'] . '</a>'; 
     329                            $author = '<a href="' . $theme['Author URI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $theme['Author'] . '</a>'; 
    323330                        $theme_meta[] = sprintf( __( 'By %s' ), $author ); 
    324331                    } 
    325332                    if ( !empty( $theme['Theme URI'] ) ) 
    326                         $theme_meta[] = '<a href="' . $theme['Theme URI'] . '" title="' . __( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>'; 
     333                        $theme_meta[] = '<a href="' . $theme['Theme URI'] . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>'; 
    327334 
    328335                    $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status ); 
  • trunk/wp-admin/network/themes.php

    r17050 r17101  
    6666            update_site_option( 'allowedthemes', $allowed_themes ); 
    6767            break; 
     68        case 'delete': 
     69            check_admin_referer('delete-theme_' . $_GET['template']); 
     70            if ( !current_user_can('delete_themes') ) 
     71                wp_die( __( 'Cheatin&#8217; uh?' ) ); 
     72            delete_theme($_GET['template']); 
     73            wp_redirect( network_admin_url('themes.php?deleted=true') ); 
     74            exit; 
     75            break; 
     76        case 'delete-selected': 
     77            if ( ! current_user_can( 'delete_themes' ) ) 
     78                wp_die( __('You do not have sufficient permissions to delete themes for this site.') ); 
     79 
     80            $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array(); 
     81            if ( empty( $themes ) ) { 
     82                wp_redirect( wp_get_referer() ); 
     83                exit; 
     84            } 
     85 
     86            $main_theme = get_current_theme(); 
     87            $files_to_delete = $theme_info = array(); 
     88            foreach( $themes as $key => $theme ) { 
     89                $data = get_theme_data( WP_CONTENT_DIR . '/themes/' . $theme . '/style.css' ); 
     90                if ( $data['Name'] == $main_theme ) { 
     91                    unset( $themes[$key] ); 
     92                } else { 
     93                    $files_to_delete = array_merge( $files_to_delete, list_files( WP_CONTENT_DIR . "/themes/$theme" ) );                     
     94                    $theme_info[ $theme ] = $data; 
     95                } 
     96            } 
     97             
     98            if ( empty( $themes ) ) { 
     99                wp_redirect( add_query_arg( 'error', 'main', wp_get_referer() ) ); 
     100                exit; 
     101            } 
     102             
     103            include(ABSPATH . 'wp-admin/update.php'); 
     104 
     105            $parent_file = 'themes.php'; 
     106 
     107            if ( ! isset( $_REQUEST['verify-delete'] ) ) { 
     108                wp_enqueue_script( 'jquery' ); 
     109                require_once( ABSPATH . 'wp-admin/admin-header.php' ); 
     110                ?> 
     111            <div class="wrap"> 
     112                <?php 
     113                    $themes_to_delete = count( $themes ); 
     114                    screen_icon(); 
     115                    echo '<h2>' . _n( 'Delete Theme', 'Delete Themes', $themes_to_delete ) . '</h2>'; 
     116                ?> 
     117                <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo _n( 'This theme may be active on other sites in the network.', 'These themes may be active on other sites in the network.', $themes_to_delete ); ?></p></div> 
     118                <p><?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?></p> 
     119                    <ul class="ul-disc"> 
     120                        <?php foreach ( $theme_info as $theme ) 
     121                            echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), esc_html( $theme['Name'] ), esc_html( $theme['AuthorName'] ) ), '</li>'; /* translators: 1: theme name, 2: theme author */ ?> 
     122                    </ul> 
     123                <p><?php _e('Are you sure you wish to delete these themes?'); ?></p> 
     124                <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;"> 
     125                    <input type="hidden" name="verify-delete" value="1" /> 
     126                    <input type="hidden" name="action" value="delete-selected" /> 
     127                    <?php 
     128                        foreach ( (array) $themes as $theme ) 
     129                            echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />'; 
     130                    ?> 
     131                    <?php wp_nonce_field('bulk-themes') ?> 
     132                    <?php submit_button( _n( 'Yes, Delete this theme', 'Yes, Delete these themes', $themes_to_delete ), 'button', 'submit', false ); ?> 
     133                </form> 
     134                <form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;"> 
     135                    <?php submit_button( __( 'No, Return me to the theme list' ), 'button', 'submit', false ); ?> 
     136                </form> 
     137 
     138                <p><a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php _e('Click to view entire list of files which will be deleted'); ?></a></p> 
     139                <div id="files-list" style="display:none;"> 
     140                    <ul class="code"> 
     141                    <?php 
     142                        foreach ( (array) $files_to_delete as $file ) 
     143                            echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . "/themes", '', $file) ) . '</li>'; 
     144                    ?> 
     145                    </ul> 
     146                </div> 
     147            </div> 
     148                <?php 
     149                require_once(ABSPATH . 'wp-admin/admin-footer.php'); 
     150                exit; 
     151            } //Endif verify-delete 
     152            foreach( $themes as $theme ) 
     153                $delete_result = delete_theme( $theme ); 
     154            wp_redirect( network_admin_url( 'themes.php?deleted=true' ) ); 
     155            exit; 
     156            break; 
    68157    } 
    69158} 
     
    88177require_once(ABSPATH . 'wp-admin/admin-header.php'); 
    89178 
     179if ( isset( $_GET['deleted'] ) ) : ?> 
     180<div class="updated"><p><?php _e('Theme deleted.') ?></p></div><?php 
     181elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) : ?> 
     182<div class="error"><p><?php _e( 'You cannot delete a theme while it is active on the main site.' ); ?></p></div><?php 
     183endif; 
    90184?> 
    91185 
Note: See TracChangeset for help on using the changeset viewer.