Theme_Upgrader::upgrade

Advertisement

Summery Summery

Upgrade a theme.

Syntax Syntax

Theme_Upgrader::upgrade( string $theme, array $args = array() )

Parameters Parameters

$theme

(Required) The theme slug.

$args

(Optional) Other arguments for upgrading a theme.

  • 'clear_update_cache'
    (bool) Whether to clear the update cache if successful. Default true.

Default value: array()

Return Return

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

Source Source

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

		remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 );
		remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
		remove_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ) );

		if ( ! $this->result || is_wp_error( $this->result ) ) {
			return $this->result;
		}

		// Refresh the Theme Update information.
		wp_clean_themes_cache( $parsed_args['clear_update_cache'] );

		if ( $parsed_args['overwrite_package'] ) {
			/**
			 * Fires when the upgrader has successfully overwritten a currently installed
			 * plugin or theme with an uploaded zip package.
			 *
			 * @since 5.5.0
			 *
			 * @param string  $package        The package file.
			 * @param array   $new_theme_data The new theme data.
			 * @param string  $package_type   The package type (plugin or theme).
			 */
			do_action( 'upgrader_overwrote_package', $package, $this->new_theme_data, 'theme' );
		}

		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() ) {
		$defaults    = array(
			'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' );
		if ( ! isset( $current->response[ $theme ] ) ) {
			$this->skin->before();
			$this->skin->set_result( false );

Advertisement

Changelog Changelog

Changelog
Version Description
3.7.0 The $args parameter was added, making clearing the update cache optional.
2.8.0 Introduced.

Advertisement

Leave a Reply