хук-действие since 3.6.0

upgrader_process_complete

Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.

Сигнатура

do_action( 'upgrader_process_complete', WP_Upgrader $upgrader, array $hook_extra )

Описание

См. также 'upgrader_package_options'.

Оригинал (английский)

Параметры

$upgrader WP_Upgrader обязательный
Экземпляр WP_Upgrader. В других контекстах это может быть экземпляр Theme_Upgrader, Plugin_Upgrader, Core_Upgrade или Language_Pack_Upgrader.
$hook_extra array обязательный
Array of bulk item update data.
  • action stringType of action. Default 'update'.
  • type stringType of update process. Accepts 'plugin', 'theme', 'translation', or 'core'.
  • bulk boolWhether the update process is a bulk update. Default true.
  • plugins arrayArray of the basename paths of the plugins’ main files.
  • themes arrayThe theme slugs.
  • translations array Array of translations update data.
    • language stringThe locale the translation is for.
    • type stringType of translation. Accepts 'plugin', 'theme', or 'core'.
    • slug stringText domain the translation is for. The slug of a theme/plugin or 'default' for core translations.
    • version stringThe version of a theme, plugin, or core.
    More Information

    The upgrader_process_complete action hook is run when the download process for a plugin install or update finishes.

    Use with caution: When you use the upgrader_process_complete action hook in your plugin and your plugin is the one which under upgrade, then this action will run the old version of your plugin.

    Source
    do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );
    

    View all references View on Trac View on GitHub

    Related
    Used byDescription
    Core_Upgrader::upgrade()wp-admin/includes/class-core-upgrader.php

    Upgrades WordPress core.

    Language_Pack_Upgrader::bulk_upgrade()wp-admin/includes/class-language-pack-upgrader.php

    Upgrades several language packs at once.

    Plugin_Upgrader::bulk_upgrade()wp-admin/includes/class-plugin-upgrader.php

    Upgrades several plugins at once.

    Theme_Upgrader::bulk_upgrade()wp-admin/includes/class-theme-upgrader.php

    Upgrades several themes at once.

    WP_Upgrader::run()wp-admin/includes/class-wp-upgrader.php

    Runs an upgrade/installation.

    Changelog
    VersionDescription
    4.6.0$translations was added as a possible argument to $hook_extra.
    3.7.0Added to WP_Upgrader::run().
    3.6.0Introduced.
    User Contributed Notes
    1. Skip to note 5 content Steven Lin 6 years ago You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

      Example migrated from Codex:

      Do stuff if the current plug-in is being updated.

      add_action( 'upgrader_process_complete', 'my_upgrade_function',10, 2);
      
      function my_upgrade_function( $upgrader_object, $options ) {
          $current_plugin_path_name = plugin_basename( __FILE__ );
      
          if ($options['action'] == 'update' && $options['type'] == 'plugin' ) {
             foreach($options['plugins'] as $each_plugin) {
                if ($each_plugin==$current_plugin_path_name) {
                   // .......................... YOUR CODES .............
      
                }
             }
          }
      }
      Log in to add feedback
    2. Skip to note 6 content Steven Lin 6 years ago You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

      Example migrated from Codex:

      This short plugin demonstrates how to display a notice to the user when they update the plugin. It displays a different notice when they first install the plugin:

      <?php
      /*Plugin Name: Upgrader Process Example
      Plugin URI: https://catapultthemes.com/wordpress-plugin-update-hook-upgrader_process_complete/
      Description: Just an example of using upgrader_process_complete
      Version: 1.0.0
      Author: Catapult Themes
      Author URI: https://catapultthemes.com/
      Text Domain: wp-upe
      Domain Path: /languages*/
      
      // Exit if accessed directly
      if ( ! defined( 'ABSPATH' ) ) {
       exit;
      }
      
      /**
       * This function runs when WordPress completes its upgrade process
       * It iterates through each plugin updated to see if ours is included
       * @param $upgrader_object Array
       * @param $options Array
       */
      function wp_upe_upgrade_completed( $upgrader_object, $options ) {
       // The path to our plugin's main file
       $our_plugin = plugin_basename( __FILE__ );
       // If an update has taken place and the updated type is plugins and the plugins element exists
       if( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) {
        // Iterate through the plugins being updated and check if ours is there
        foreach( $options['plugins'] as $plugin ) {
         if( $plugin == $our_plugin ) {
          // Set a transient to record that our plugin has just been updated
          set_transient( 'wp_upe_updated', 1 );
         }
        }
       }
      }
      add_action( 'upgrader_process_complete', 'wp_upe_upgrade_completed', 10, 2 );
      
      /**
       * Show a notice to anyone who has just updated this plugin
       * This notice shouldn't display to anyone who has just installed the plugin for the first time
       */
      function wp_upe_display_update_notice() {
       // Check the transient to see if we've just updated the plugin
       if( get_transient( 'wp_upe_updated' ) ) {
        echo '<div class="notice notice-success">' . __( 'Thanks for updating', 'wp-upe' ) . '</div>';
        delete_transient( 'wp_upe_updated' );
       }
      }
      add_action( 'admin_notices', 'wp_upe_display_update_notice' );
      
      /**
       * Show a notice to anyone who has just installed the plugin for the first time
       * This notice shouldn't display to anyone who has just updated this plugin
       */
      function wp_upe_display_install_notice() {
       // Check the transient to see if we've just activated the plugin
       if( get_transient( 'wp_upe_activated' ) ) {
        echo '<div class="notice notice-success">' . __( 'Thanks for installing', 'wp-upe' ) . '</div>';
        // Delete the transient so we don't keep displaying the activation message
       delete_transient( 'wp_upe_activated' );
       }
      }
      add_action( 'admin_notices', 'wp_upe_display_install_notice' );
      
      /**
       * Run this on activation
       * Set a transient so that we know we've just activated the plugin
       */
      function wp_upe_activate() {
       set_transient( 'wp_upe_activated', 1 );
      }
      register_activation_hook( __FILE__, 'wp_upe_activate' );
      Log in to add feedback
    3. Skip to note 7 content Steven Lin 6 years ago You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

      Example migrated from Codex:

      The following is example data of the $hook_extra parameter passed to this hook (as of v4.8.1):

      Array
      (
          [action] => update
          [type] => plugin
          [bulk] => 1
          [plugins] => Array
              (
                  [0] => wordpress-beta-tester/wp-beta-tester.php
              )
      )
      Log in to add feedback
    4. Skip to note 8 content gnowland 6 years ago You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

      In Parameters > $this “Core_Upgrade” should be “Core_Upgrader” and link to https://developer.wordpress.org/reference/classes/core_upgrader/

      Log in to add feedback

Исходный код

wp-admin/includes/class-wp-upgrader.php:988

do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );

История изменений

ВерсияОписание
4.6.0 $translations was added as a possible argument to $hook_extra.
3.7.0 Added to WP_Upgrader::run().
3.6.0 Introduced.

Что будем искать? Например,Продвижение

Этот сайт использует куки-файлы. Оставаясь на сайте, Вы соглашаетесь на их использование. Для получения дополнительной информации, пожалуйста, ознакомьтесь с политикой в отношении персональных данных.