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
|
* @since 2.7
|
||||||
* @access public
|
* @access public
|
||||||
*
|
*
|
||||||
|
* @param string $theme The Theme stylesheet or template for the directory
|
||||||
* @return string The location of the remote path.
|
* @return string The location of the remote path.
|
||||||
*/
|
*/
|
||||||
function wp_themes_dir() {
|
function wp_themes_dir( $theme = false ) {
|
||||||
return $this->wp_content_dir() . 'themes/';
|
$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
|
* Returns the path on the remote filesystem of WP_LANG_DIR
|
||||||
|
|
|
@ -93,8 +93,8 @@ class WP_Upgrader {
|
||||||
if ( ! $wp_filesystem->wp_plugins_dir() )
|
if ( ! $wp_filesystem->wp_plugins_dir() )
|
||||||
return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
|
return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
|
||||||
break;
|
break;
|
||||||
case WP_CONTENT_DIR . '/themes':
|
case get_theme_root():
|
||||||
if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') )
|
if ( ! $wp_filesystem->wp_themes_dir() )
|
||||||
return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
|
return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -164,7 +164,8 @@ class WP_Upgrader {
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_package($args = array()) {
|
function install_package($args = array()) {
|
||||||
global $wp_filesystem;
|
global $wp_filesystem, $wp_theme_directories;
|
||||||
|
|
||||||
$defaults = array( 'source' => '', 'destination' => '', //Please always pass these
|
$defaults = array( 'source' => '', 'destination' => '', //Please always pass these
|
||||||
'clear_destination' => false, 'clear_working' => false,
|
'clear_destination' => false, 'clear_working' => false,
|
||||||
'abort_if_destination_exists' => true,
|
'abort_if_destination_exists' => true,
|
||||||
|
@ -208,8 +209,10 @@ class WP_Upgrader {
|
||||||
if ( $source !== $remote_source )
|
if ( $source !== $remote_source )
|
||||||
$source_files = array_keys( $wp_filesystem->dirlist($source) );
|
$source_files = array_keys( $wp_filesystem->dirlist($source) );
|
||||||
|
|
||||||
//Protection against deleting files in any important base directories.
|
// 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') ) ) {
|
// 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));
|
$remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
|
||||||
$destination = trailingslashit($destination) . trailingslashit(basename($source));
|
$destination = trailingslashit($destination) . trailingslashit(basename($source));
|
||||||
}
|
}
|
||||||
|
@ -727,7 +730,7 @@ class Theme_Upgrader extends WP_Upgrader {
|
||||||
// Install the parent theme
|
// Install the parent theme
|
||||||
$parent_result = $this->run( array(
|
$parent_result = $this->run( array(
|
||||||
'package' => $api->download_link,
|
'package' => $api->download_link,
|
||||||
'destination' => WP_CONTENT_DIR . '/themes',
|
'destination' => get_theme_root(),
|
||||||
'clear_destination' => false, //Do not overwrite files.
|
'clear_destination' => false, //Do not overwrite files.
|
||||||
'clear_working' => true
|
'clear_working' => true
|
||||||
) );
|
) );
|
||||||
|
@ -760,11 +763,11 @@ class Theme_Upgrader extends WP_Upgrader {
|
||||||
add_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
|
add_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
'package' => $package,
|
'package' => $package,
|
||||||
'destination' => WP_CONTENT_DIR . '/themes',
|
'destination' => get_theme_root(),
|
||||||
'clear_destination' => false, //Do not overwrite files.
|
'clear_destination' => false, //Do not overwrite files.
|
||||||
'clear_working' => true
|
'clear_working' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->run($options);
|
$this->run($options);
|
||||||
|
|
||||||
|
@ -803,14 +806,14 @@ class Theme_Upgrader extends WP_Upgrader {
|
||||||
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
|
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
'package' => $r['package'],
|
'package' => $r['package'],
|
||||||
'destination' => WP_CONTENT_DIR . '/themes',
|
'destination' => get_theme_root( $theme ),
|
||||||
'clear_destination' => true,
|
'clear_destination' => true,
|
||||||
'clear_working' => true,
|
'clear_working' => true,
|
||||||
'hook_extra' => array(
|
'hook_extra' => array(
|
||||||
'theme' => $theme
|
'theme' => $theme
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->run($options);
|
$this->run($options);
|
||||||
|
|
||||||
|
@ -883,14 +886,14 @@ class Theme_Upgrader extends WP_Upgrader {
|
||||||
$r = $current->response[ $theme ];
|
$r = $current->response[ $theme ];
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
'package' => $r['package'],
|
'package' => $r['package'],
|
||||||
'destination' => WP_CONTENT_DIR . '/themes',
|
'destination' => get_theme_root( $theme ),
|
||||||
'clear_destination' => true,
|
'clear_destination' => true,
|
||||||
'clear_working' => true,
|
'clear_working' => true,
|
||||||
'hook_extra' => array(
|
'hook_extra' => array(
|
||||||
'theme' => $theme
|
'theme' => $theme
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $this->run($options);
|
$result = $this->run($options);
|
||||||
|
|
||||||
|
@ -984,18 +987,22 @@ class Theme_Upgrader extends WP_Upgrader {
|
||||||
return $return;
|
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;
|
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) )
|
if ( ! isset( $theme['theme'] ) )
|
||||||
return $removed; //Pass errors through.
|
return $removed;
|
||||||
|
|
||||||
$themes_dir = $wp_filesystem->wp_themes_dir();
|
$theme = $theme['theme'];
|
||||||
if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
|
$themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) );
|
||||||
if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
|
if ( $wp_filesystem->exists( $themes_dir . $theme ) ) {
|
||||||
|
if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) )
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1007,7 +1014,7 @@ class Theme_Upgrader extends WP_Upgrader {
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return wp_get_theme( $theme, WP_CONTENT_DIR . '/themes/' );
|
return wp_get_theme( $theme );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue