WordPress.org

Make WordPress Core

Changeset 10715


Ignore:
Timestamp:
03/05/09 19:15:56 (7 years ago)
Author:
ryan
Message:

delete_theme(). see #8678

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/plugin.php

    r10627 r10715  
    472472 
    473473    // Force refresh of plugin update information 
    474     delete_option('update_plugins'); 
     474    delete_transient('update_plugins'); 
    475475 
    476476    return true; 
  • trunk/wp-admin/includes/theme.php

    r10706 r10715  
    3030    $ct->tags = $themes[$current_theme]['Tags']; 
    3131    return $ct; 
     32} 
     33 
     34/** 
     35 * Remove a theme 
     36 * 
     37 * @since 2.8.0 
     38 * 
     39 * @param string $template Template directory of the theme to delete 
     40 * @return mixed 
     41 */ 
     42function delete_theme($template) { 
     43    global $wp_filesystem; 
     44 
     45    if ( empty($template) ) 
     46        return false; 
     47 
     48    ob_start(); 
     49    $url = wp_nonce_url('themes.php?action=delete&template=' . $template, 'delete-theme_' . $template); 
     50    if ( false === ($credentials = request_filesystem_credentials($url)) ) { 
     51        $data = ob_get_contents(); 
     52        ob_end_clean(); 
     53        if ( ! empty($data) ){ 
     54            include_once( ABSPATH . 'wp-admin/admin-header.php'); 
     55            echo $data; 
     56            include( ABSPATH . 'wp-admin/admin-footer.php'); 
     57            exit; 
     58        } 
     59        return; 
     60    } 
     61 
     62    if ( ! WP_Filesystem($credentials) ) { 
     63        request_filesystem_credentials($url, '', true); // Failed to connect, Error and request again 
     64        $data = ob_get_contents(); 
     65        ob_end_clean(); 
     66        if( ! empty($data) ){ 
     67            include_once( ABSPATH . 'wp-admin/admin-header.php'); 
     68            echo $data; 
     69            include( ABSPATH . 'wp-admin/admin-footer.php'); 
     70            exit; 
     71        } 
     72        return; 
     73    } 
     74 
     75    if ( $wp_filesystem->errors->get_error_code() ) { 
     76        return $wp_filesystem->errors; 
     77    } 
     78 
     79    if ( ! is_object($wp_filesystem) ) 
     80        return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 
     81 
     82    if ( $wp_filesystem->errors->get_error_code() ) 
     83        return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); 
     84 
     85    //Get the base plugin folder 
     86    $themes_dir = $wp_filesystem->wp_themes_dir(); 
     87    if ( empty($themes_dir) ) 
     88        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.')); 
     89 
     90    $themes_dir = trailingslashit( $themes_dir ); 
     91 
     92    $errors = array(); 
     93 
     94    $theme_dir = trailingslashit($themes_dir . $template); 
     95    $deleted = $wp_filesystem->delete($theme_dir, true); 
     96 
     97    if ( ! $deleted ) 
     98        return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s'), $template) ); 
     99 
     100    // Force refresh of theme update information 
     101    delete_transient('update_themes'); 
     102 
     103    return true; 
    32104} 
    33105 
  • trunk/wp-admin/themes.php

    r10714 r10715  
    1818    } else if ( 'delete' == $_GET['action'] ) { 
    1919        check_admin_referer('delete-theme_' . $_GET['template']); 
    20         die('Not implemented'); 
     20        if ( !current_user_can('update_themes') ) 
     21            wp_die( __( 'Cheatin’ uh?' ) ); 
     22        delete_theme($_GET['template']); 
     23        wp_redirect('themes.php?deleted=true'); 
     24        exit; 
    2125    } 
    2226} 
     
    3539<?php elseif ( isset($_GET['activated']) ) : ?> 
    3640<div id="message2" class="updated fade"><p><?php printf(__('New theme activated. <a href="%s">Visit site</a>'), get_bloginfo('url') . '/'); ?></p></div> 
     41<?php elseif ( isset($_GET['deleted']) ) : ?> 
     42<div id="message3" class="updated fade"><p><?php _e('Theme deleted.') ?></p></div> 
    3743<?php endif; ?> 
    3844 
Note: See TracChangeset for help on using the changeset viewer.