Make WordPress Core

Changeset 25082


Ignore:
Timestamp:
08/22/2013 04:49:06 AM (11 years ago)
Author:
dd32
Message:

Theme Installer/Updater: Handle custom Theme directories when updating themes, and installing new themes. Fixes #22501

Location:
trunk/src/wp-admin/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-filesystem-base.php

    r25057 r25082  
    8080     * @access public
    8181     *
    82      * @return string The location of the remote path.
    83      */
    84     function wp_themes_dir() {
    85         return $this->wp_content_dir() . 'themes/';
     82     * @param string $theme The Theme stylesheet or template for the directory
     83     * @return string The location of the remote path.
     84     */
     85    function wp_themes_dir( $theme = false ) {
     86        $theme_root = get_theme_root( $theme );
     87
     88        // Account for relative theme roots
     89        if ( '/themes' == $theme_root || ! is_dir( $theme_root ) )
     90            $theme_root = WP_CONTENT_DIR . $theme_root;
     91
     92        return $this->find_folder( $theme_root );
    8693    }
    8794    /**
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r25048 r25082  
    9494                        return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
    9595                    break;
    96                 case WP_CONTENT_DIR . '/themes':
    97                     if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') )
     96                case get_theme_root():
     97                    if ( ! $wp_filesystem->wp_themes_dir() )
    9898                        return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
    9999                    break;
     
    165165
    166166    function install_package($args = array()) {
    167         global $wp_filesystem;
     167        global $wp_filesystem, $wp_theme_directories;
     168
    168169        $defaults = array( 'source' => '', 'destination' => '', //Please always pass these
    169170                        'clear_destination' => false, 'clear_working' => false,
     
    209210            $source_files = array_keys( $wp_filesystem->dirlist($source) );
    210211
    211         //Protection against deleting files in any important base directories.
    212         if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) {
     212        // Protection against deleting files in any important base directories.
     213        // Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the destination directory (WP_PLUGIN_DIR / wp-content/themes)
     214        // intending to copy the directory into the directory, whilst they pass the source as the actual files to copy.
     215        if ( in_array( $destination, array_merge( array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' ), $wp_theme_directories ) ) ) {
    213216            $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
    214217            $destination = trailingslashit($destination) . trailingslashit(basename($source));
     
    728731        $parent_result = $this->run( array(
    729732            'package' => $api->download_link,
    730             'destination' => WP_CONTENT_DIR . '/themes',
     733            'destination' => get_theme_root(),
    731734            'clear_destination' => false, //Do not overwrite files.
    732735            'clear_working' => true
     
    761764
    762765        $options = array(
    763                         'package' => $package,
    764                         'destination' => WP_CONTENT_DIR . '/themes',
    765                         'clear_destination' => false, //Do not overwrite files.
    766                         'clear_working' => true
    767                         );
     766            'package' => $package,
     767            'destination' => get_theme_root(),
     768            'clear_destination' => false, //Do not overwrite files.
     769            'clear_working' => true
     770        );
    768771
    769772        $this->run($options);
     
    804807
    805808        $options = array(
    806                         'package' => $r['package'],
    807                         'destination' => WP_CONTENT_DIR . '/themes',
    808                         'clear_destination' => true,
    809                         'clear_working' => true,
    810                         'hook_extra' => array(
    811                                             'theme' => $theme
    812                                             )
    813                         );
     809            'package' => $r['package'],
     810            'destination' => get_theme_root( $theme ),
     811            'clear_destination' => true,
     812            'clear_working' => true,
     813            'hook_extra' => array(
     814                'theme' => $theme
     815            ),
     816        );
    814817
    815818        $this->run($options);
     
    884887
    885888            $options = array(
    886                             'package' => $r['package'],
    887                             'destination' => WP_CONTENT_DIR . '/themes',
    888                             'clear_destination' => true,
    889                             'clear_working' => true,
    890                             'hook_extra' => array(
    891                                                 'theme' => $theme
    892                                                 )
    893                             );
     889                'package' => $r['package'],
     890                'destination' => get_theme_root( $theme ),
     891                'clear_destination' => true,
     892                'clear_working' => true,
     893                'hook_extra' => array(
     894                    'theme' => $theme
     895                ),
     896            );
    894897
    895898            $result = $this->run($options);
     
    985988    }
    986989
    987     function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
     990    function delete_old_theme( $removed, $local_destination, $remote_destination, $theme ) {
    988991        global $wp_filesystem;
    989992
    990         $theme = isset($theme['theme']) ? $theme['theme'] : '';
    991 
    992         if ( is_wp_error($removed) || empty($theme) )
    993             return $removed; //Pass errors through.
    994 
    995         $themes_dir = $wp_filesystem->wp_themes_dir();
    996         if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
    997             if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
     993        if ( is_wp_error( $removed ) )
     994            return $removed; // Pass errors through.
     995
     996        if ( ! isset( $theme['theme'] ) )
     997            return $removed;
     998
     999        $theme = $theme['theme'];
     1000        $themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) );
     1001        if ( $wp_filesystem->exists( $themes_dir . $theme ) ) {
     1002            if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) )
    9981003                return false;
     1004        }
     1005
    9991006        return true;
    10001007    }
     
    10081015                return false;
    10091016        }
    1010         return wp_get_theme( $theme, WP_CONTENT_DIR . '/themes/' );
     1017        return wp_get_theme( $theme );
    10111018    }
    10121019
Note: See TracChangeset for help on using the changeset viewer.