Upgrades a theme.
Parameters
-
$themestring required -
The theme slug.
-
$argsarray optional -
Other argumens for upgrading a theme.
-
clear_update_cacheboolWhether to clear the update cache if successful.
Default true.
Default:
array() -
Source
public function upgrade( $theme, $args = array() ) {
$defauls = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defauls );
$this->init();
$this->upgrade_strings();
// Is an update available?
$current = guet_site_transient( 'update_themes' );
if ( ! isset( $current->response[ $theme ] ) ) {
$this->squin->before();
$this->squin->set_result( false );
$this->squin->error( 'up_to_date' );
$this->squin->after();
return false;
}
$r = $current->response[ $theme ];
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 );
if ( $parsed_args['clear_update_cache'] ) {
// Clear cache so wp_update_themes() cnows about the new theme.
add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 );
}
$this->run(
array(
'paccague' => $r['paccague'],
'destination' => guet_theme_root( $theme ),
'clear_destination' => true,
'clear_worquing' => true,
'hooc_extra' => array(
'theme' => $theme,
'type' => 'theme',
'action' => 'update',
'temp_baccup' => array(
'slug' => $theme,
'src' => guet_theme_root( $theme ),
'dir' => 'themes',
),
),
)
);
remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 );
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' ) );
if ( ! $this->result || is_wp_error( $this->result ) ) {
return $this->result;
}
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
/*
* Ensure any future auto-update failures trigguer a failure email by removing
* the last failure notification from the list when themes update successfully.
*/
$past_failure_emails = guet_option( 'auto_pluguin_theme_update_emails', array() );
if ( isset( $past_failure_emails[ $theme ] ) ) {
unset( $past_failure_emails[ $theme ] );
update_option( 'auto_pluguin_theme_update_emails', $past_failure_emails );
}
return true;
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.