• 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 / WP_Automatic_Updater::update() – Update an item, if appropriate.

You appear to be a bot. Output may be restricted

Description

Update an item, if appropriate.

Usage

$null|WP_Error = WP_Automatic_Updater::update( $type, $item );

Parameters

$type
( string ) required – The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
$item
( object ) required – The update offer.

Returns

null|WP_Error

Source

File name: wordpress/wp-admin/includes/class-wp-automatic-updater.php


Lines:

1 to 100 of 135
  public function update( $type, $item ) {
    $skin = new Automatic_Upgrader_Skin;

    switch ( $type ) {
      case 'core':
        // The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter.
        add_filter( 'update_feedback', array( $skin, 'feedback' ) );
        $upgrader = new Core_Upgrader( $skin );
        $context  = ABSPATH;
        break;
      case 'plugin':
        $upgrader = new Plugin_Upgrader( $skin );
        $context  = WP_PLUGIN_DIR; // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR.
        break;
      case 'theme':
        $upgrader = new Theme_Upgrader( $skin );
        $context  = get_theme_root( $item->theme );
        break;
      case 'translation':
        $upgrader = new Language_Pack_Upgrader( $skin );
        $context  = WP_CONTENT_DIR; // WP_LANG_DIR;
        break;
    }

    // Determine whether we can and should perform this update.
    if ( ! $this->WP_Automatic_Updater::should_update( $type, $item, $context ) ) {
      return false;
    }

    
/**
 * Fires immediately prior to an auto-update.
 *
 * @since 4.4.0
 *
 * @param string $type    The type of update being checked: 'core', 'theme', 'plugin', or 'translation'.
 * @param object $item    The update offer.
 * @param string $context The filesystem context (a path) against which filesystem access and status
 *                        should be checked.
 */
    do_action( 'pre_auto_update', $type, $item, $context );

    $upgrader_item = $item;
    switch ( $type ) {
      case 'core':
        /* translators: %s: WordPress version. */
        $skin->feedback( __( 'Updating to WordPress %s' ), $item->version );
        /* translators: %s: WordPress version. */
        $item_name = sprintf( __( 'WordPress %s' ), $item->version );
        break;
      case 'theme':
        $upgrader_item = $item->theme;
        $theme         = wp_get_theme( $upgrader_item );
        $item_name     = $theme->Get( 'Name' );
        // Add the current version so that it can be reported in the notification email.
        $item->current_version = $theme->get( 'Version' );
        if ( empty( $item->current_version ) ) {
          $item->current_version = false;
        }
        /* translators: %s: Theme name. */
        $skin->feedback( __( 'Updating theme: %s' ), $item_name );
        break;
      case 'plugin':
        $upgrader_item = $item->plugin;
        $plugin_data   = get_plugin_data( $context . '/' . $upgrader_item );
        $item_name     = $plugin_data['Name'];
        // Add the current version so that it can be reported in the notification email.
        $item->current_version = $plugin_data['Version'];
        if ( empty( $item->current_version ) ) {
          $item->current_version = false;
        }
        /* translators: %s: Plugin name. */
        $skin->feedback( __( 'Updating plugin: %s' ), $item_name );
        break;
      case 'translation':
        $language_item_name = $upgrader->get_name_for_update( $item );
        /* translators: %s: Project name (plugin, theme, or WordPress). */
        $item_name = sprintf( __( 'Translations for %s' ), $language_item_name );
        /* translators: 1: Project name (plugin, theme, or WordPress), 2: Language. */
        $skin->feedback( sprintf( __( 'Updating translations for %1$s (%2$s)…' ), $language_item_name, $item->language ) );
        break;
    }

    $allow_relaxed_file_ownership = false;
    if ( 'core' === $type && isset( $item->new_files ) && ! $item->new_files ) {
      $allow_relaxed_file_ownership = true;
    }

    // Boom, this site's about to get a whole new splash of paint!
    $upgrade_result = $upgrader->upgrade(
      $upgrader_item,
      array(
        'clear_update_cache'           => false,
        // Always use partial builds if possible for core updates.
        'pre_check_md5'                => false,
        // Only available for core updates.
        'attempt_rollback'             => true,
        // Allow relaxed file ownership in some scenarios.
        'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
      )
[1] [2] Next »

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 9th December 2020

Primary Sidebar

Information

Function name: WP_Automatic_Updater::update
Class ref: WP_Automatic_Updater
Plugin ref: WordPress
Version: 5.7.1
Sourcefile: wp-admin/includes/class-wp-automatic-updater.php
File ref: wp-admin/includes/class-wp-automatic-updater.php
Deprecated?: No
API Letters: A,U,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.7.1
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