2016-05-10 07:45:42 -04:00
< ? php
/**
2016-05-10 07:52:28 -04:00
* Upgrade API : Theme_Upgrader class
2016-05-10 07:45:42 -04:00
*
* @ package WordPress
* @ subpackage Upgrader
2016-05-10 07:52:28 -04:00
* @ since 4.6 . 0
2016-05-10 07:45:42 -04:00
*/
/**
* Core class used for upgrading / installing themes .
*
* It is designed to upgrade / install themes from a local zip , remote zip URL ,
* or uploaded zip file .
*
* @ since 2.8 . 0
2016-05-13 16:59:27 -04:00
* @ since 4.6 . 0 Moved to its own file from wp - admin / includes / class - wp - upgrader . php .
2016-05-10 07:45:42 -04:00
*
* @ see WP_Upgrader
*/
class Theme_Upgrader extends WP_Upgrader {
/**
* Result of the theme upgrade offer .
*
* @ since 2.8 . 0
* @ var array | WP_Error $result
* @ see WP_Upgrader :: $result
*/
public $result ;
/**
* Whether multiple themes are being upgraded / installed in bulk .
*
* @ since 2.9 . 0
* @ var bool $bulk
*/
public $bulk = false ;
/**
* Initialize the upgrade strings .
*
* @ since 2.8 . 0
*/
public function upgrade_strings () {
2017-11-30 18:11:00 -05:00
$this -> strings [ 'up_to_date' ] = __ ( 'The theme is at the latest version.' );
$this -> strings [ 'no_package' ] = __ ( 'Update package not available.' );
2017-10-18 13:15:47 -04:00
/* translators: %s: package URL */
$this -> strings [ 'downloading_package' ] = sprintf ( __ ( 'Downloading update from %s…' ), '<span class="code">%s</span>' );
2017-11-30 18:11:00 -05:00
$this -> strings [ 'unpack_package' ] = __ ( 'Unpacking the update…' );
$this -> strings [ 'remove_old' ] = __ ( 'Removing the old version of the theme…' );
$this -> strings [ 'remove_old_failed' ] = __ ( 'Could not remove the old theme.' );
$this -> strings [ 'process_failed' ] = __ ( 'Theme update failed.' );
$this -> strings [ 'process_success' ] = __ ( 'Theme updated successfully.' );
2016-05-10 07:45:42 -04:00
}
/**
2017-08-22 07:52:48 -04:00
* Initialize the installation strings .
2016-05-10 07:45:42 -04:00
*
* @ since 2.8 . 0
*/
public function install_strings () {
2017-11-30 18:11:00 -05:00
$this -> strings [ 'no_package' ] = __ ( 'Installation package not available.' );
2017-10-18 13:15:47 -04:00
/* translators: %s: package URL */
$this -> strings [ 'downloading_package' ] = sprintf ( __ ( 'Downloading installation package from %s…' ), '<span class="code">%s</span>' );
2017-11-30 18:11:00 -05:00
$this -> strings [ 'unpack_package' ] = __ ( 'Unpacking the package…' );
$this -> strings [ 'installing_package' ] = __ ( 'Installing the theme…' );
$this -> strings [ 'no_files' ] = __ ( 'The theme contains no files.' );
$this -> strings [ 'process_failed' ] = __ ( 'Theme installation failed.' );
$this -> strings [ 'process_success' ] = __ ( 'Theme installed successfully.' );
2016-05-10 07:45:42 -04:00
/* translators: 1: theme name, 2: version */
2017-11-30 18:11:00 -05:00
$this -> strings [ 'process_success_specific' ] = __ ( 'Successfully installed the theme <strong>%1$s %2$s</strong>.' );
$this -> strings [ 'parent_theme_search' ] = __ ( 'This theme requires a parent theme. Checking if it is installed…' );
2016-05-10 07:45:42 -04:00
/* translators: 1: theme name, 2: version */
2017-11-30 18:11:00 -05:00
$this -> strings [ 'parent_theme_prepare_install' ] = __ ( 'Preparing to install <strong>%1$s %2$s</strong>…' );
2016-05-10 07:45:42 -04:00
/* translators: 1: theme name, 2: version */
2017-11-30 18:11:00 -05:00
$this -> strings [ 'parent_theme_currently_installed' ] = __ ( 'The parent theme, <strong>%1$s %2$s</strong>, is currently installed.' );
2016-05-10 07:45:42 -04:00
/* translators: 1: theme name, 2: version */
2017-11-30 18:11:00 -05:00
$this -> strings [ 'parent_theme_install_success' ] = __ ( 'Successfully installed the parent theme, <strong>%1$s %2$s</strong>.' );
2017-10-18 13:20:48 -04:00
/* translators: %s: theme name */
$this -> strings [ 'parent_theme_not_found' ] = sprintf ( __ ( '<strong>The parent theme could not be found.</strong> You will need to install the parent theme, %s, before you can use this child theme.' ), '<strong>%s</strong>' );
2016-05-10 07:45:42 -04:00
}
/**
* Check if a child theme is being installed and we need to install its parent .
*
* Hooked to the { @ see 'upgrader_post_install' } filter by Theme_Upgrader :: install () .
*
* @ since 3.4 . 0
*
* @ param bool $install_result
* @ param array $hook_extra
* @ param array $child_result
* @ return type
*/
public function check_parent_theme_filter ( $install_result , $hook_extra , $child_result ) {
// Check to see if we need to install a parent theme
$theme_info = $this -> theme_info ();
2017-11-30 18:11:00 -05:00
if ( ! $theme_info -> parent () ) {
2016-05-10 07:45:42 -04:00
return $install_result ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
$this -> skin -> feedback ( 'parent_theme_search' );
if ( ! $theme_info -> parent () -> errors () ) {
2017-11-30 18:11:00 -05:00
$this -> skin -> feedback ( 'parent_theme_currently_installed' , $theme_info -> parent () -> display ( 'Name' ), $theme_info -> parent () -> display ( 'Version' ) );
2016-05-10 07:45:42 -04:00
// We already have the theme, fall through.
return $install_result ;
}
// We don't have the parent theme, let's install it.
2017-11-30 18:11:00 -05:00
$api = themes_api (
'theme_information' , array (
'slug' => $theme_info -> get ( 'Template' ),
'fields' => array (
'sections' => false ,
'tags' => false ,
),
)
); //Save on a bit of bandwidth.
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $api || is_wp_error ( $api ) ) {
$this -> skin -> feedback ( 'parent_theme_not_found' , $theme_info -> get ( 'Template' ) );
2017-08-22 07:52:48 -04:00
// Don't show activate or preview actions after installation
2017-11-30 18:11:00 -05:00
add_filter ( 'install_theme_complete_actions' , array ( $this , 'hide_activate_preview_actions' ) );
2016-05-10 07:45:42 -04:00
return $install_result ;
}
// Backup required data we're going to override:
2017-11-30 18:11:00 -05:00
$child_api = $this -> skin -> api ;
2016-05-10 07:45:42 -04:00
$child_success_message = $this -> strings [ 'process_success' ];
// Override them
2017-11-30 18:11:00 -05:00
$this -> skin -> api = $api ;
2016-05-10 07:45:42 -04:00
$this -> strings [ 'process_success_specific' ] = $this -> strings [ 'parent_theme_install_success' ]; //, $api->name, $api->version);
2017-11-30 18:11:00 -05:00
$this -> skin -> feedback ( 'parent_theme_prepare_install' , $api -> name , $api -> version );
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
add_filter ( 'install_theme_complete_actions' , '__return_false' , 999 ); // Don't show any actions after installing the theme.
2016-05-10 07:45:42 -04:00
// Install the parent theme
2017-11-30 18:11:00 -05:00
$parent_result = $this -> run (
array (
'package' => $api -> download_link ,
'destination' => get_theme_root (),
'clear_destination' => false , //Do not overwrite files.
'clear_working' => true ,
)
);
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( is_wp_error ( $parent_result ) ) {
add_filter ( 'install_theme_complete_actions' , array ( $this , 'hide_activate_preview_actions' ) );
}
2016-05-10 07:45:42 -04:00
// Start cleaning up after the parents installation
2017-11-30 18:11:00 -05:00
remove_filter ( 'install_theme_complete_actions' , '__return_false' , 999 );
2016-05-10 07:45:42 -04:00
// Reset child's result and data
2017-11-30 18:11:00 -05:00
$this -> result = $child_result ;
$this -> skin -> api = $child_api ;
2016-05-10 07:45:42 -04:00
$this -> strings [ 'process_success' ] = $child_success_message ;
return $install_result ;
}
/**
* Don ' t display the activate and preview actions to the user .
*
* Hooked to the { @ see 'install_theme_complete_actions' } filter by
* Theme_Upgrader :: check_parent_theme_filter () when installing
* a child theme and installing the parent theme fails .
*
* @ since 3.4 . 0
*
* @ param array $actions Preview actions .
* @ return array
*/
public function hide_activate_preview_actions ( $actions ) {
2017-11-30 18:11:00 -05:00
unset ( $actions [ 'activate' ], $actions [ 'preview' ] );
2016-05-10 07:45:42 -04:00
return $actions ;
}
/**
* Install a theme package .
*
* @ since 2.8 . 0
* @ since 3.7 . 0 The `$args` parameter was added , making clearing the update cache optional .
*
* @ param string $package The full local path or URI of the package .
* @ param array $args {
* Optional . Other arguments for installing a theme package . Default empty array .
*
* @ type bool $clear_update_cache Whether to clear the updates cache if successful .
* Default true .
* }
*
2017-08-22 07:52:48 -04:00
* @ return bool | WP_Error True if the installation was successful , false or a WP_Error object otherwise .
2016-05-10 07:45:42 -04:00
*/
public function install ( $package , $args = array () ) {
2017-11-30 18:11:00 -05:00
$defaults = array (
2016-05-10 07:45:42 -04:00
'clear_update_cache' => true ,
);
$parsed_args = wp_parse_args ( $args , $defaults );
$this -> init ();
$this -> install_strings ();
2017-11-30 18:11:00 -05:00
add_filter ( 'upgrader_source_selection' , array ( $this , 'check_package' ) );
add_filter ( 'upgrader_post_install' , array ( $this , 'check_parent_theme_filter' ), 10 , 3 );
2016-11-13 04:53:32 -05:00
if ( $parsed_args [ 'clear_update_cache' ] ) {
// Clear cache so wp_update_themes() knows about the new theme.
add_action ( 'upgrader_process_complete' , 'wp_clean_themes_cache' , 9 , 0 );
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$this -> run (
array (
'package' => $package ,
'destination' => get_theme_root (),
'clear_destination' => false , //Do not overwrite files.
'clear_working' => true ,
'hook_extra' => array (
'type' => 'theme' ,
'action' => 'install' ,
),
)
);
2016-05-10 07:45:42 -04:00
remove_action ( 'upgrader_process_complete' , 'wp_clean_themes_cache' , 9 );
2017-11-30 18:11:00 -05:00
remove_filter ( 'upgrader_source_selection' , array ( $this , 'check_package' ) );
remove_filter ( 'upgrader_post_install' , array ( $this , 'check_parent_theme_filter' ) );
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $this -> result || is_wp_error ( $this -> result ) ) {
2016-05-10 07:45:42 -04:00
return $this -> result ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
// Refresh the Theme Update information
wp_clean_themes_cache ( $parsed_args [ 'clear_update_cache' ] );
return true ;
}
/**
* Upgrade a theme .
*
* @ since 2.8 . 0
* @ since 3.7 . 0 The `$args` parameter was added , making clearing the update cache optional .
*
* @ param string $theme The theme slug .
* @ param array $args {
* Optional . Other arguments for upgrading a theme . Default empty array .
*
* @ type bool $clear_update_cache Whether to clear the update cache if successful .
* Default true .
* }
* @ return bool | WP_Error True if the upgrade was successful , false or a WP_Error object otherwise .
*/
public function upgrade ( $theme , $args = array () ) {
2017-11-30 18:11:00 -05:00
$defaults = array (
2016-05-10 07:45:42 -04:00
'clear_update_cache' => true ,
);
$parsed_args = wp_parse_args ( $args , $defaults );
$this -> init ();
$this -> upgrade_strings ();
// Is an update available?
$current = get_site_transient ( 'update_themes' );
2017-11-30 18:11:00 -05:00
if ( ! isset ( $current -> response [ $theme ] ) ) {
2016-05-10 07:45:42 -04:00
$this -> skin -> before ();
2017-11-30 18:11:00 -05:00
$this -> skin -> set_result ( false );
2016-05-10 07:45:42 -04:00
$this -> skin -> error ( 'up_to_date' );
$this -> skin -> after ();
return false ;
}
$r = $current -> response [ $theme ];
2017-11-30 18:11:00 -05:00
add_filter ( 'upgrader_pre_install' , array ( $this , 'current_before' ), 10 , 2 );
add_filter ( 'upgrader_post_install' , array ( $this , 'current_after' ), 10 , 2 );
add_filter ( 'upgrader_clear_destination' , array ( $this , 'delete_old_theme' ), 10 , 4 );
2016-11-13 04:53:32 -05:00
if ( $parsed_args [ 'clear_update_cache' ] ) {
// Clear cache so wp_update_themes() knows about the new theme.
add_action ( 'upgrader_process_complete' , 'wp_clean_themes_cache' , 9 , 0 );
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$this -> run (
array (
'package' => $r [ 'package' ],
'destination' => get_theme_root ( $theme ),
'clear_destination' => true ,
'clear_working' => true ,
'hook_extra' => array (
'theme' => $theme ,
'type' => 'theme' ,
'action' => 'update' ,
),
)
);
2016-05-10 07:45:42 -04:00
remove_action ( 'upgrader_process_complete' , 'wp_clean_themes_cache' , 9 );
2017-11-30 18:11:00 -05:00
remove_filter ( 'upgrader_pre_install' , array ( $this , 'current_before' ) );
remove_filter ( 'upgrader_post_install' , array ( $this , 'current_after' ) );
remove_filter ( 'upgrader_clear_destination' , array ( $this , 'delete_old_theme' ) );
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $this -> result || is_wp_error ( $this -> result ) ) {
2016-05-10 07:45:42 -04:00
return $this -> result ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
wp_clean_themes_cache ( $parsed_args [ 'clear_update_cache' ] );
return true ;
}
/**
* Upgrade several themes at once .
*
* @ since 3.0 . 0
* @ since 3.7 . 0 The `$args` parameter was added , making clearing the update cache optional .
*
2018-03-22 16:27:32 -04:00
* @ param string [] $themes Array of the theme slugs .
* @ param array $args {
2016-05-10 07:45:42 -04:00
* Optional . Other arguments for upgrading several themes at once . Default empty array .
*
* @ type bool $clear_update_cache Whether to clear the update cache if successful .
* Default true .
* }
* @ return array [] | false An array of results , or false if unable to connect to the filesystem .
*/
public function bulk_upgrade ( $themes , $args = array () ) {
2017-11-30 18:11:00 -05:00
$defaults = array (
2016-05-10 07:45:42 -04:00
'clear_update_cache' => true ,
);
$parsed_args = wp_parse_args ( $args , $defaults );
$this -> init ();
$this -> bulk = true ;
$this -> upgrade_strings ();
$current = get_site_transient ( 'update_themes' );
2017-11-30 18:11:00 -05:00
add_filter ( 'upgrader_pre_install' , array ( $this , 'current_before' ), 10 , 2 );
add_filter ( 'upgrader_post_install' , array ( $this , 'current_after' ), 10 , 2 );
add_filter ( 'upgrader_clear_destination' , array ( $this , 'delete_old_theme' ), 10 , 4 );
2016-05-10 07:45:42 -04:00
$this -> skin -> header ();
// Connect to the Filesystem first.
2017-11-30 18:11:00 -05:00
$res = $this -> fs_connect ( array ( WP_CONTENT_DIR ) );
2016-05-10 07:45:42 -04:00
if ( ! $res ) {
$this -> skin -> footer ();
return false ;
}
$this -> skin -> bulk_header ();
// Only start maintenance mode if:
// - running Multisite and there are one or more themes specified, OR
// - a theme with an update available is currently in use.
// @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
$maintenance = ( is_multisite () && ! empty ( $themes ) );
2017-11-30 18:11:00 -05:00
foreach ( $themes as $theme ) {
2016-05-10 07:45:42 -04:00
$maintenance = $maintenance || $theme == get_stylesheet () || $theme == get_template ();
2017-11-30 18:11:00 -05:00
}
if ( $maintenance ) {
$this -> maintenance_mode ( true );
}
2016-05-10 07:45:42 -04:00
$results = array ();
2017-11-30 18:11:00 -05:00
$this -> update_count = count ( $themes );
2016-05-10 07:45:42 -04:00
$this -> update_current = 0 ;
foreach ( $themes as $theme ) {
$this -> update_current ++ ;
2017-11-30 18:11:00 -05:00
$this -> skin -> theme_info = $this -> theme_info ( $theme );
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( ! isset ( $current -> response [ $theme ] ) ) {
$this -> skin -> set_result ( true );
2016-05-10 07:45:42 -04:00
$this -> skin -> before ();
$this -> skin -> feedback ( 'up_to_date' );
$this -> skin -> after ();
2017-11-30 18:11:00 -05:00
$results [ $theme ] = true ;
2016-05-10 07:45:42 -04:00
continue ;
}
// Get the URL to the zip file
$r = $current -> response [ $theme ];
2017-11-30 18:11:00 -05:00
$result = $this -> run (
array (
'package' => $r [ 'package' ],
'destination' => get_theme_root ( $theme ),
'clear_destination' => true ,
'clear_working' => true ,
'is_multi' => true ,
'hook_extra' => array (
'theme' => $theme ,
),
)
);
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$results [ $theme ] = $this -> result ;
2016-05-10 07:45:42 -04:00
// Prevent credentials auth screen from displaying multiple times
2017-11-30 18:11:00 -05:00
if ( false === $result ) {
2016-05-10 07:45:42 -04:00
break ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
} //end foreach $plugins
2017-11-30 18:11:00 -05:00
$this -> maintenance_mode ( false );
2016-05-10 07:45:42 -04:00
2016-11-13 04:53:32 -05:00
// Refresh the Theme Update information
wp_clean_themes_cache ( $parsed_args [ 'clear_update_cache' ] );
2016-05-10 07:45:42 -04:00
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
2017-11-30 18:11:00 -05:00
do_action (
'upgrader_process_complete' , $this , array (
'action' => 'update' ,
'type' => 'theme' ,
'bulk' => true ,
'themes' => $themes ,
)
);
2016-05-10 07:45:42 -04:00
$this -> skin -> bulk_footer ();
$this -> skin -> footer ();
// Cleanup our hooks, in case something else does a upgrade on this connection.
2017-11-30 18:11:00 -05:00
remove_filter ( 'upgrader_pre_install' , array ( $this , 'current_before' ) );
remove_filter ( 'upgrader_post_install' , array ( $this , 'current_after' ) );
remove_filter ( 'upgrader_clear_destination' , array ( $this , 'delete_old_theme' ) );
2016-05-10 07:45:42 -04:00
return $results ;
}
/**
* Check that the package source contains a valid theme .
*
* Hooked to the { @ see 'upgrader_source_selection' } filter by Theme_Upgrader :: install () .
* It will return an error if the theme doesn ' t have style . css or index . php
* files .
*
* @ since 3.3 . 0
*
2018-03-04 16:58:30 -05:00
* @ global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass .
2016-05-10 07:45:42 -04:00
*
* @ param string $source The full path to the package source .
* @ return string | WP_Error The source or a WP_Error .
*/
public function check_package ( $source ) {
global $wp_filesystem ;
2017-11-30 18:11:00 -05:00
if ( is_wp_error ( $source ) ) {
2016-05-10 07:45:42 -04:00
return $source ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
// Check the folder contains a valid theme
2017-11-30 18:11:00 -05:00
$working_directory = str_replace ( $wp_filesystem -> wp_content_dir (), trailingslashit ( WP_CONTENT_DIR ), $source );
if ( ! is_dir ( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation.
2016-05-10 07:45:42 -04:00
return $source ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
// A proper archive should have a style.css file in the single subdirectory
if ( ! file_exists ( $working_directory . 'style.css' ) ) {
2017-11-30 18:11:00 -05:00
return new WP_Error (
'incompatible_archive_theme_no_style' , $this -> strings [ 'incompatible_archive' ],
2016-05-10 07:45:42 -04:00
/* translators: %s: style.css */
2017-11-30 18:11:00 -05:00
sprintf (
__ ( 'The theme is missing the %s stylesheet.' ),
2016-05-10 07:45:42 -04:00
'<code>style.css</code>'
)
);
}
2017-11-30 18:11:00 -05:00
$info = get_file_data (
$working_directory . 'style.css' , array (
'Name' => 'Theme Name' ,
'Template' => 'Template' ,
)
);
2016-05-10 07:45:42 -04:00
if ( empty ( $info [ 'Name' ] ) ) {
2017-11-30 18:11:00 -05:00
return new WP_Error (
'incompatible_archive_theme_no_name' , $this -> strings [ 'incompatible_archive' ],
2016-05-10 07:45:42 -04:00
/* translators: %s: style.css */
2017-11-30 18:11:00 -05:00
sprintf (
__ ( 'The %s stylesheet doesn’t contain a valid theme header.' ),
2016-05-10 07:45:42 -04:00
'<code>style.css</code>'
)
);
}
// If it's not a child theme, it must have at least an index.php to be legit.
if ( empty ( $info [ 'Template' ] ) && ! file_exists ( $working_directory . 'index.php' ) ) {
2017-11-30 18:11:00 -05:00
return new WP_Error (
'incompatible_archive_theme_no_index' , $this -> strings [ 'incompatible_archive' ],
2016-05-10 07:45:42 -04:00
/* translators: %s: index.php */
2017-11-30 18:11:00 -05:00
sprintf (
__ ( 'The theme is missing the %s file.' ),
2016-05-10 07:45:42 -04:00
'<code>index.php</code>'
)
);
}
return $source ;
}
/**
* Turn on maintenance mode before attempting to upgrade the current theme .
*
* Hooked to the { @ see 'upgrader_pre_install' } filter by Theme_Upgrader :: upgrade () and
* Theme_Upgrader :: bulk_upgrade () .
*
* @ since 2.8 . 0
*
* @ param bool | WP_Error $return
* @ param array $theme
* @ return bool | WP_Error
*/
2017-11-30 18:11:00 -05:00
public function current_before ( $return , $theme ) {
if ( is_wp_error ( $return ) ) {
2016-05-10 07:45:42 -04:00
return $return ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$theme = isset ( $theme [ 'theme' ] ) ? $theme [ 'theme' ] : '' ;
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( $theme != get_stylesheet () ) { //If not current
2016-05-10 07:45:42 -04:00
return $return ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
//Change to maintenance mode now.
2017-11-30 18:11:00 -05:00
if ( ! $this -> bulk ) {
$this -> maintenance_mode ( true );
}
2016-05-10 07:45:42 -04:00
return $return ;
}
/**
* Turn off maintenance mode after upgrading the current theme .
*
* Hooked to the { @ see 'upgrader_post_install' } filter by Theme_Upgrader :: upgrade ()
* and Theme_Upgrader :: bulk_upgrade () .
*
* @ since 2.8 . 0
*
* @ param bool | WP_Error $return
* @ param array $theme
* @ return bool | WP_Error
*/
2017-11-30 18:11:00 -05:00
public function current_after ( $return , $theme ) {
if ( is_wp_error ( $return ) ) {
2016-05-10 07:45:42 -04:00
return $return ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$theme = isset ( $theme [ 'theme' ] ) ? $theme [ 'theme' ] : '' ;
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( $theme != get_stylesheet () ) { // If not current
2016-05-10 07:45:42 -04:00
return $return ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
// Ensure stylesheet name hasn't changed after the upgrade:
if ( $theme == get_stylesheet () && $theme != $this -> result [ 'destination_name' ] ) {
wp_clean_themes_cache ();
$stylesheet = $this -> result [ 'destination_name' ];
switch_theme ( $stylesheet );
}
//Time to remove maintenance mode
2017-11-30 18:11:00 -05:00
if ( ! $this -> bulk ) {
$this -> maintenance_mode ( false );
}
2016-05-10 07:45:42 -04:00
return $return ;
}
/**
* Delete the old theme during an upgrade .
*
* Hooked to the { @ see 'upgrader_clear_destination' } filter by Theme_Upgrader :: upgrade ()
* and Theme_Upgrader :: bulk_upgrade () .
*
* @ since 2.8 . 0
*
* @ global WP_Filesystem_Base $wp_filesystem Subclass
*
* @ param bool $removed
* @ param string $local_destination
* @ param string $remote_destination
* @ param array $theme
* @ return bool
*/
public function delete_old_theme ( $removed , $local_destination , $remote_destination , $theme ) {
global $wp_filesystem ;
2017-11-30 18:11:00 -05:00
if ( is_wp_error ( $removed ) ) {
2016-05-10 07:45:42 -04:00
return $removed ; // Pass errors through.
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( ! isset ( $theme [ 'theme' ] ) ) {
2016-05-10 07:45:42 -04:00
return $removed ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$theme = $theme [ 'theme' ];
2016-05-10 07:45:42 -04:00
$themes_dir = trailingslashit ( $wp_filesystem -> wp_themes_dir ( $theme ) );
if ( $wp_filesystem -> exists ( $themes_dir . $theme ) ) {
2017-11-30 18:11:00 -05:00
if ( ! $wp_filesystem -> delete ( $themes_dir . $theme , true ) ) {
2016-05-10 07:45:42 -04:00
return false ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
}
return true ;
}
/**
* Get the WP_Theme object for a theme .
*
* @ since 2.8 . 0
* @ since 3.0 . 0 The `$theme` argument was added .
*
* @ param string $theme The directory name of the theme . This is optional , and if not supplied ,
* the directory name from the last result will be used .
* @ return WP_Theme | false The theme ' s info object , or false `$theme` is not supplied
* and the last result isn ' t set .
*/
2017-11-30 18:11:00 -05:00
public function theme_info ( $theme = null ) {
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $theme ) ) {
if ( ! empty ( $this -> result [ 'destination_name' ] ) ) {
2016-05-10 07:45:42 -04:00
$theme = $this -> result [ 'destination_name' ];
2017-11-30 18:11:00 -05:00
} else {
2016-05-10 07:45:42 -04:00
return false ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
}
return wp_get_theme ( $theme );
}
}