Make WordPress Core


Ignore:
Timestamp:
03/05/2009 07:15:56 PM (18 years ago)
Author:
ryan
Message:

delete_theme(). see #8678

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.