mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
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
This commit is contained in:
parent
b7838c5f34
commit
a1d8c65604
@ -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 )
|
||||
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,18 +268,22 @@ 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'] = '<a href="' . wp_nonce_url($url . 'action=enable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'enable-theme_' . $theme_key) . '" title="' . __('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&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'enable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Enable this theme') . '" class="edit">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>';
|
||||
else
|
||||
$actions['disable'] = '<a href="' . wp_nonce_url($url . 'action=disable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'disable-theme_' . $theme_key) . '" title="' . __('Disable this theme') . '">' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '</a>';
|
||||
$actions['disable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=disable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'disable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Disable this theme') . '">' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '</a>';
|
||||
|
||||
if ( current_user_can('edit_themes') )
|
||||
$actions['edit'] = '<a href="theme-editor.php?theme=' . $theme['Name'] . '" title="' . __('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 )
|
||||
$actions['delete'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=delete-selected&checked[]=' . $theme_key . '&theme_status=' . $context . '&paged=' . $page . '&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_$theme_key", $actions, $theme_key, $theme, $context );
|
||||
@ -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 = '<a href="' . $theme['Author URI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $theme['Author'] . '</a>';
|
||||
$author = '<a href="' . $theme['Author URI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $theme['Author'] . '</a>';
|
||||
$theme_meta[] = sprintf( __( 'By %s' ), $author );
|
||||
}
|
||||
if ( !empty( $theme['Theme URI'] ) )
|
||||
$theme_meta[] = '<a href="' . $theme['Theme URI'] . '" title="' . __( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
|
||||
$theme_meta[] = '<a href="' . $theme['Theme URI'] . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
|
||||
|
||||
$theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status );
|
||||
echo implode( ' | ', $theme_meta );
|
||||
|
@ -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' );
|
||||
?>
|
||||
<div class="wrap">
|
||||
<?php
|
||||
$themes_to_delete = count( $themes );
|
||||
screen_icon();
|
||||
echo '<h2>' . _n( 'Delete Theme', 'Delete Themes', $themes_to_delete ) . '</h2>';
|
||||
?>
|
||||
<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>
|
||||
<p><?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?></p>
|
||||
<ul class="ul-disc">
|
||||
<?php foreach ( $theme_info as $theme )
|
||||
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 */ ?>
|
||||
</ul>
|
||||
<p><?php _e('Are you sure you wish to delete these themes?'); ?></p>
|
||||
<form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
|
||||
<input type="hidden" name="verify-delete" value="1" />
|
||||
<input type="hidden" name="action" value="delete-selected" />
|
||||
<?php
|
||||
foreach ( (array) $themes as $theme )
|
||||
echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />';
|
||||
?>
|
||||
<?php wp_nonce_field('bulk-themes') ?>
|
||||
<?php submit_button( _n( 'Yes, Delete this theme', 'Yes, Delete these themes', $themes_to_delete ), 'button', 'submit', false ); ?>
|
||||
</form>
|
||||
<form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;">
|
||||
<?php submit_button( __( 'No, Return me to the theme list' ), 'button', 'submit', false ); ?>
|
||||
</form>
|
||||
|
||||
<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>
|
||||
<div id="files-list" style="display:none;">
|
||||
<ul class="code">
|
||||
<?php
|
||||
foreach ( (array) $files_to_delete as $file )
|
||||
echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . "/themes", '', $file) ) . '</li>';
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
require_once(ABSPATH . 'wp-admin/admin-footer.php');
|
||||
exit;
|
||||
} //Endif verify-delete
|
||||
foreach( $themes as $theme )
|
||||
$delete_result = delete_theme( $theme );
|
||||
wp_redirect( network_admin_url( 'themes.php?deleted=true' ) );
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,6 +176,11 @@ $parent_file = 'themes.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">
|
||||
|
Loading…
Reference in New Issue
Block a user