Make WordPress Core

Ticket #22501: 22501.diff

File 22501.diff, 6.0 KB (added by dd32, 12 years ago)
  • src/wp-admin/includes/class-wp-filesystem-base.php

     
    7979         * @since 2.7
    8080         * @access public
    8181         *
     82         * @param string $theme The Theme stylesheet or template for the directory
    8283         * @return string The location of the remote path.
    8384         */
    84         function wp_themes_dir() {
    85                 return $this->wp_content_dir() . 'themes/';
     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        /**
    8895         * Returns the path on the remote filesystem of WP_LANG_DIR
  • src/wp-admin/includes/class-wp-upgrader.php

     
    9393                                        if ( ! $wp_filesystem->wp_plugins_dir() )
    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;
    100100                                default:
     
    164164        }
    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,
    170171                                                'abort_if_destination_exists' => true,
     
    208209                if ( $source !== $remote_source )
    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));
    215218                }
     
    724727                // Install the parent theme
    725728                $parent_result = $this->run( array(
    726729                        'package' => $api->download_link,
    727                         'destination' => WP_CONTENT_DIR . '/themes',
     730                        'destination' => get_theme_root(),
    728731                        'clear_destination' => false, //Do not overwrite files.
    729732                        'clear_working' => true
    730733                ) );
     
    757760                add_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
    758761
    759762                $options = array(
    760                                                 'package' => $package,
    761                                                 'destination' => WP_CONTENT_DIR . '/themes',
    762                                                 'clear_destination' => false, //Do not overwrite files.
    763                                                 'clear_working' => true
    764                                                 );
     763                        'package' => $package,
     764                        'destination' => get_theme_root(),
     765                        'clear_destination' => false, //Do not overwrite files.
     766                        'clear_working' => true
     767                );
    765768
    766769                $this->run($options);
    767770
     
    800803                add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
    801804
    802805                $options = array(
    803                                                 'package' => $r['package'],
    804                                                 'destination' => WP_CONTENT_DIR . '/themes',
    805                                                 'clear_destination' => true,
    806                                                 'clear_working' => true,
    807                                                 'hook_extra' => array(
    808                                                                                         'theme' => $theme
    809                                                                                         )
    810                                                 );
     806                        'package' => $r['package'],
     807                        'destination' => get_theme_root( $theme ),
     808                        'clear_destination' => true,
     809                        'clear_working' => true,
     810                        'hook_extra' => array(
     811                                'theme' => $theme
     812                        ),
     813                );
    811814
    812815                $this->run($options);
    813816
     
    877880                        $r = $current->response[ $theme ];
    878881
    879882                        $options = array(
    880                                                         'package' => $r['package'],
    881                                                         'destination' => WP_CONTENT_DIR . '/themes',
    882                                                         'clear_destination' => true,
    883                                                         'clear_working' => true,
    884                                                         'hook_extra' => array(
    885                                                                                                 'theme' => $theme
    886                                                                                                 )
    887                                                         );
     883                                'package' => $r['package'],
     884                                'destination' => get_theme_root( $theme ),
     885                                'clear_destination' => true,
     886                                'clear_working' => true,
     887                                'hook_extra' => array(
     888                                        'theme' => $theme
     889                                ),
     890                        );
    888891
    889892                        $result = $this->run($options);
    890893
     
    978981                return $return;
    979982        }
    980983
    981         function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
     984        function delete_old_theme( $removed, $local_destination, $remote_destination, $theme ) {
    982985                global $wp_filesystem;
    983986
    984                 $theme = isset($theme['theme']) ? $theme['theme'] : '';
     987                if ( is_wp_error( $removed ) )
     988                        return $removed; // Pass errors through.
    985989
    986                 if ( is_wp_error($removed) || empty($theme) )
    987                         return $removed; //Pass errors through.
     990                if ( ! isset( $theme['theme'] ) )
     991                        return $removed;
    988992
    989                 $themes_dir = $wp_filesystem->wp_themes_dir();
    990                 if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
    991                         if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
     993                $theme = $theme['theme'];
     994                $themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) );
     995                if ( $wp_filesystem->exists( $themes_dir . $theme ) ) {
     996                        if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) )
    992997                                return false;
     998                }
     999
    9931000                return true;
    9941001        }
    9951002
     
    10011008                        else
    10021009                                return false;
    10031010                }
    1004                 return wp_get_theme( $theme, WP_CONTENT_DIR . '/themes/' );
     1011                return wp_get_theme( $theme );
    10051012        }
    10061013
    10071014}