From a1d8c65604180ba802da5712381991b12d7a3e4a Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 21 Dec 2010 16:50:16 +0000 Subject: [PATCH] Add delete support to network themes. Props PeteMall. fixes #15707 git-svn-id: http://svn.automattic.com/wordpress/trunk@17101 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-ms-themes-list-table.php | 27 ++++-- wp-admin/network/themes.php | 94 +++++++++++++++++++ 2 files changed, 111 insertions(+), 10 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 29c09f9b0..6720cefd5 100644 --- a/wp-admin/includes/class-wp-ms-themes-list-table.php +++ b/wp-admin/includes/class-wp-ms-themes-list-table.php @@ -231,9 +231,12 @@ class WP_MS_Themes_List_Table extends WP_List_Table { $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ); if ( 'disabled' != $status ) $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ); - if ( current_user_can( 'update_themes' ) && !$this->is_site_themes ) - $actions['update-selected'] = __( 'Update' ); - + if ( ! $this->is_site_themes ) { + if ( current_user_can( 'delete_themes' ) ) + $actions['delete-selected'] = __( 'Delete' ); + if ( current_user_can( 'update_themes' ) ) + $actions['update-selected'] = __( 'Update' ); + } return $actions; } @@ -265,22 +268,26 @@ class WP_MS_Themes_List_Table extends WP_List_Table { $actions = array( 'enable' => '', 'disable' => '', - 'edit' => '' + 'edit' => '', + 'delete' => '' ); $theme_key = esc_html( $theme['Stylesheet'] ); if ( empty( $theme['enabled'] ) ) - $actions['enable'] = '' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . ''; + $actions['enable'] = '' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . ''; else - $actions['disable'] = '' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . ''; + $actions['disable'] = '' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . ''; if ( current_user_can('edit_themes') ) - $actions['edit'] = '' . __('Edit') . ''; + $actions['edit'] = '' . __('Edit') . ''; + + if ( empty( $theme['enabled'] ) && current_user_can( 'delete_themes' ) && ! $this->is_site_themes ) + $actions['delete'] = '' . __( 'Delete' ) . ''; $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context ); $actions = apply_filters( "theme_action_links_$theme_key", $actions, $theme_key, $theme, $context ); - + $class = empty( $theme['enabled'] ) ? 'inactive' : 'active'; $checkbox_id = md5($theme['Name']) . "_checkbox"; $checkbox = ""; @@ -319,11 +326,11 @@ class WP_MS_Themes_List_Table extends WP_List_Table { if ( !empty( $theme['Author'] ) ) { $author = $theme['Author']; if ( !empty( $theme['Author URI'] ) ) - $author = '' . $theme['Author'] . ''; + $author = '' . $theme['Author'] . ''; $theme_meta[] = sprintf( __( 'By %s' ), $author ); } if ( !empty( $theme['Theme URI'] ) ) - $theme_meta[] = '' . __( 'Visit Theme Site' ) . ''; + $theme_meta[] = '' . __( 'Visit Theme Site' ) . ''; $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status ); echo implode( ' | ', $theme_meta ); diff --git a/wp-admin/network/themes.php b/wp-admin/network/themes.php index a798e2706..dd7b6e699 100644 --- a/wp-admin/network/themes.php +++ b/wp-admin/network/themes.php @@ -65,6 +65,95 @@ if ( $action ) { unset( $allowed_themes[ $theme ] ); update_site_option( 'allowedthemes', $allowed_themes ); break; + case 'delete': + check_admin_referer('delete-theme_' . $_GET['template']); + if ( !current_user_can('delete_themes') ) + wp_die( __( 'Cheatin’ uh?' ) ); + delete_theme($_GET['template']); + wp_redirect( network_admin_url('themes.php?deleted=true') ); + exit; + break; + case 'delete-selected': + if ( ! current_user_can( 'delete_themes' ) ) + wp_die( __('You do not have sufficient permissions to delete themes for this site.') ); + + $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array(); + if ( empty( $themes ) ) { + wp_redirect( wp_get_referer() ); + exit; + } + + $main_theme = get_current_theme(); + $files_to_delete = $theme_info = array(); + foreach( $themes as $key => $theme ) { + $data = get_theme_data( WP_CONTENT_DIR . '/themes/' . $theme . '/style.css' ); + if ( $data['Name'] == $main_theme ) { + unset( $themes[$key] ); + } else { + $files_to_delete = array_merge( $files_to_delete, list_files( WP_CONTENT_DIR . "/themes/$theme" ) ); + $theme_info[ $theme ] = $data; + } + } + + if ( empty( $themes ) ) { + wp_redirect( add_query_arg( 'error', 'main', wp_get_referer() ) ); + exit; + } + + include(ABSPATH . 'wp-admin/update.php'); + + $parent_file = 'themes.php'; + + if ( ! isset( $_REQUEST['verify-delete'] ) ) { + wp_enqueue_script( 'jquery' ); + require_once( ABSPATH . 'wp-admin/admin-header.php' ); + ?> +
+ ' . _n( 'Delete Theme', 'Delete Themes', $themes_to_delete ) . ''; + ?> +

+

+ +

+
+ + + '; + ?> + + +
+
+ +
+ +

+ +
+ +

+