• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Theme_Upgrader::upgrade() – Upgrade a theme.

You appear to be a bot. Output may be restricted

Description

Upgrade a theme.

Usage

$bool|WP_Error = Theme_Upgrader::upgrade( $theme, $args );

Parameters

$theme
( string ) required – The theme slug.
$args
( array ) optional – { Optional. Other arguments for upgrading a theme. Default empty array.
$clear_update_cache
( bool ) optional – Whether to clear the update cache if successful. Default true. }

Returns

bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise.

Source

File name: wordpress/wp-admin/includes/class-theme-upgrader.php
Lines:

1 to 65 of 65
  public function upgrade( $theme, $args = array() ) {
    $defaults    = array(
      'clear_update_cache' => true,
    );
    $parsed_args = wp_parse_args( $args, $defaults );

    $this->init();
    $this->Theme_Upgrader::upgrade_strings();

    // Is an update available?
    $current = get_site_transient( 'update_themes' );
    if ( ! isset( $current->response[ $theme ] ) ) {
      $this->skin->before();
      $this->skin->set_result( false );
      $this->skin->error( 'up_to_date' );
      $this->skin->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() knows about the new theme.
      add_action( 'upgrader_process_complete', 'wp_clean_themes_cache',  < 9, 0 );
    }

    $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',
        ),
      )
    );

    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 trigger a failure email by removing
    // the last failure notification from the list when themes update successfully.
    $past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() );

    if ( isset( $past_failure_emails[ $theme ] ) ) {
      unset( $past_failure_emails[ $theme ] );
      update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
    }

    return true;
  }
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 21st August 2020

Primary Sidebar

Information

Function name: Theme_Upgrader::upgrade
Class ref: Theme_Upgrader
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-admin/includes/class-theme-upgrader.php
File ref: wp-admin/includes/class-theme-upgrader.php
Deprecated?: No
API Letters: T,U

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites