Theme Installer/Updater: Handle custom Theme directories when updating themes, and installing new themes. Fixes #22501
Built from https://develop.svn.wordpress.org/trunk@25082 git-svn-id: http://core.svn.wordpress.org/trunk@25067 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
46daa240b9
commit
8a70215404
|
@ -79,10 +79,17 @@ class WP_Filesystem_Base {
|
|||
* @since 2.7
|
||||
* @access public
|
||||
*
|
||||
* @param string $theme The Theme stylesheet or template for the directory
|
||||
* @return string The location of the remote path.
|
||||
*/
|
||||
function wp_themes_dir() {
|
||||
return $this->wp_content_dir() . 'themes/';
|
||||
function wp_themes_dir( $theme = false ) {
|
||||
$theme_root = get_theme_root( $theme );
|
||||
|
||||
// Account for relative theme roots
|
||||
if ( '/themes' == $theme_root || ! is_dir( $theme_root ) )
|
||||
$theme_root = WP_CONTENT_DIR . $theme_root;
|
||||
|
||||
return $this->find_folder( $theme_root );
|
||||
}
|
||||
/**
|
||||
* Returns the path on the remote filesystem of WP_LANG_DIR
|
||||
|
|
|
@ -93,8 +93,8 @@ class WP_Upgrader {
|
|||
if ( ! $wp_filesystem->wp_plugins_dir() )
|
||||
return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
|
||||
break;
|
||||
case WP_CONTENT_DIR . '/themes':
|
||||
if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') )
|
||||
case get_theme_root():
|
||||
if ( ! $wp_filesystem->wp_themes_dir() )
|
||||
return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
|
||||
break;
|
||||
default:
|
||||
|
@ -164,7 +164,8 @@ class WP_Upgrader {
|
|||
}
|
||||
|
||||
function install_package($args = array()) {
|
||||
global $wp_filesystem;
|
||||
global $wp_filesystem, $wp_theme_directories;
|
||||
|
||||
$defaults = array( 'source' => '', 'destination' => '', //Please always pass these
|
||||
'clear_destination' => false, 'clear_working' => false,
|
||||
'abort_if_destination_exists' => true,
|
||||
|
@ -208,8 +209,10 @@ class WP_Upgrader {
|
|||
if ( $source !== $remote_source )
|
||||
$source_files = array_keys( $wp_filesystem->dirlist($source) );
|
||||
|
||||
//Protection against deleting files in any important base directories.
|
||||
if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) {
|
||||
// Protection against deleting files in any important base directories.
|
||||
// Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the destination directory (WP_PLUGIN_DIR / wp-content/themes)
|
||||
// intending to copy the directory into the directory, whilst they pass the source as the actual files to copy.
|
||||
if ( in_array( $destination, array_merge( array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' ), $wp_theme_directories ) ) ) {
|
||||
$remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
|
||||
$destination = trailingslashit($destination) . trailingslashit(basename($source));
|
||||
}
|
||||
|
@ -727,7 +730,7 @@ class Theme_Upgrader extends WP_Upgrader {
|
|||
// Install the parent theme
|
||||
$parent_result = $this->run( array(
|
||||
'package' => $api->download_link,
|
||||
'destination' => WP_CONTENT_DIR . '/themes',
|
||||
'destination' => get_theme_root(),
|
||||
'clear_destination' => false, //Do not overwrite files.
|
||||
'clear_working' => true
|
||||
) );
|
||||
|
@ -761,7 +764,7 @@ class Theme_Upgrader extends WP_Upgrader {
|
|||
|
||||
$options = array(
|
||||
'package' => $package,
|
||||
'destination' => WP_CONTENT_DIR . '/themes',
|
||||
'destination' => get_theme_root(),
|
||||
'clear_destination' => false, //Do not overwrite files.
|
||||
'clear_working' => true
|
||||
);
|
||||
|
@ -804,12 +807,12 @@ class Theme_Upgrader extends WP_Upgrader {
|
|||
|
||||
$options = array(
|
||||
'package' => $r['package'],
|
||||
'destination' => WP_CONTENT_DIR . '/themes',
|
||||
'destination' => get_theme_root( $theme ),
|
||||
'clear_destination' => true,
|
||||
'clear_working' => true,
|
||||
'hook_extra' => array(
|
||||
'theme' => $theme
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
$this->run($options);
|
||||
|
@ -884,12 +887,12 @@ class Theme_Upgrader extends WP_Upgrader {
|
|||
|
||||
$options = array(
|
||||
'package' => $r['package'],
|
||||
'destination' => WP_CONTENT_DIR . '/themes',
|
||||
'destination' => get_theme_root( $theme ),
|
||||
'clear_destination' => true,
|
||||
'clear_working' => true,
|
||||
'hook_extra' => array(
|
||||
'theme' => $theme
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
$result = $this->run($options);
|
||||
|
@ -984,18 +987,22 @@ class Theme_Upgrader extends WP_Upgrader {
|
|||
return $return;
|
||||
}
|
||||
|
||||
function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
|
||||
function delete_old_theme( $removed, $local_destination, $remote_destination, $theme ) {
|
||||
global $wp_filesystem;
|
||||
|
||||
$theme = isset($theme['theme']) ? $theme['theme'] : '';
|
||||
if ( is_wp_error( $removed ) )
|
||||
return $removed; // Pass errors through.
|
||||
|
||||
if ( is_wp_error($removed) || empty($theme) )
|
||||
return $removed; //Pass errors through.
|
||||
if ( ! isset( $theme['theme'] ) )
|
||||
return $removed;
|
||||
|
||||
$themes_dir = $wp_filesystem->wp_themes_dir();
|
||||
if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
|
||||
if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
|
||||
$theme = $theme['theme'];
|
||||
$themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) );
|
||||
if ( $wp_filesystem->exists( $themes_dir . $theme ) ) {
|
||||
if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1007,7 +1014,7 @@ class Theme_Upgrader extends WP_Upgrader {
|
|||
else
|
||||
return false;
|
||||
}
|
||||
return wp_get_theme( $theme, WP_CONTENT_DIR . '/themes/' );
|
||||
return wp_get_theme( $theme );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue