wp/wp-admin/includes/class-plugin-upgrader.php
author ymh <ymh.work@gmail.com>
Fri, 05 Sep 2025 18:52:52 +0200
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
permissions -rw-r--r--
Update WordPress to latest version (6.7) - Sync WordPress core files from latest release - Updated admin interface, blocks, and core functionality - Enhanced block editor features and performance - Security updates and bug fixes - Preserved custom wp-content directory and configuration 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Upgrade API: Plugin_Upgrader class
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Upgrader
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * Core class used for upgrading/installing plugins.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * It is designed to upgrade/install plugins from a local zip, remote zip URL,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * or uploaded zip file.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * @see WP_Upgrader
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
class Plugin_Upgrader extends WP_Upgrader {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	 * Plugin upgrade result.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	 * @var array|WP_Error $result
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	 * @see WP_Upgrader::$result
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	public $result;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	 * Whether a bulk upgrade/installation is being performed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	 * @since 2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	 * @var bool $bulk
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	public $bulk = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    42
	 * New plugin info.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    43
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    44
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    45
	 * @var array $new_plugin_data
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    46
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    47
	 * @see check_package()
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    48
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    49
	public $new_plugin_data = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    50
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    51
	/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    52
	 * Initializes the upgrade strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	public function upgrade_strings() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    57
		$this->strings['up_to_date'] = __( 'The plugin is at the latest version.' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    58
		$this->strings['no_package'] = __( 'Update package not available.' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    59
		/* translators: %s: Package URL. */
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    60
		$this->strings['downloading_package']  = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code pre">%s</span>' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    61
		$this->strings['unpack_package']       = __( 'Unpacking the update&#8230;' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    62
		$this->strings['remove_old']           = __( 'Removing the old version of the plugin&#8230;' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    63
		$this->strings['remove_old_failed']    = __( 'Could not remove the old plugin.' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    64
		$this->strings['process_failed']       = __( 'Plugin update failed.' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    65
		$this->strings['process_success']      = __( 'Plugin updated successfully.' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    66
		$this->strings['process_bulk_success'] = __( 'Plugins updated successfully.' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    70
	 * Initializes the installation strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	public function install_strings() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    75
		$this->strings['no_package'] = __( 'Installation package not available.' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    76
		/* translators: %s: Package URL. */
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    77
		$this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s&#8230;' ), '<span class="code pre">%s</span>' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    78
		$this->strings['unpack_package']      = __( 'Unpacking the package&#8230;' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    79
		$this->strings['installing_package']  = __( 'Installing the plugin&#8230;' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    80
		$this->strings['remove_old']          = __( 'Removing the current plugin&#8230;' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    81
		$this->strings['remove_old_failed']   = __( 'Could not remove the current plugin.' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    82
		$this->strings['no_files']            = __( 'The plugin contains no files.' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    83
		$this->strings['process_failed']      = __( 'Plugin installation failed.' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    84
		$this->strings['process_success']     = __( 'Plugin installed successfully.' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    85
		/* translators: 1: Plugin name, 2: Plugin version. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    86
		$this->strings['process_success_specific'] = __( 'Successfully installed the plugin <strong>%1$s %2$s</strong>.' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    87
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    88
		if ( ! empty( $this->skin->overwrite ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    89
			if ( 'update-plugin' === $this->skin->overwrite ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    90
				$this->strings['installing_package'] = __( 'Updating the plugin&#8230;' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    91
				$this->strings['process_failed']     = __( 'Plugin update failed.' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    92
				$this->strings['process_success']    = __( 'Plugin updated successfully.' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    93
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    94
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    95
			if ( 'downgrade-plugin' === $this->skin->overwrite ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    96
				$this->strings['installing_package'] = __( 'Downgrading the plugin&#8230;' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    97
				$this->strings['process_failed']     = __( 'Plugin downgrade failed.' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    98
				$this->strings['process_success']    = __( 'Plugin downgraded successfully.' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    99
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   100
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
	 * Install a plugin package.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	 * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
	 * @param string $package The full local path or URI of the package.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	 * @param array  $args {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	 *     Optional. Other arguments for installing a plugin package. Default empty array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
	 *     @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	 *                                    Default true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	 * @return bool|WP_Error True if the installation was successful, false or a WP_Error otherwise.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	public function install( $package, $args = array() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   119
		$defaults    = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
			'clear_update_cache' => true,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   121
			'overwrite_package'  => false, // Do not overwrite files.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
		$parsed_args = wp_parse_args( $args, $defaults );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
		$this->init();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
		$this->install_strings();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   128
		add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   129
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
		if ( $parsed_args['clear_update_cache'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
			// Clear cache so wp_update_plugins() knows about the new plugin.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
			add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   135
		$this->run(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   136
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   137
				'package'           => $package,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   138
				'destination'       => WP_PLUGIN_DIR,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   139
				'clear_destination' => $parsed_args['overwrite_package'],
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   140
				'clear_working'     => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   141
				'hook_extra'        => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   142
					'type'   => 'plugin',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   143
					'action' => 'install',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   144
				),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
			)
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   146
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
		remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   149
		remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   151
		if ( ! $this->result || is_wp_error( $this->result ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
			return $this->result;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   153
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   155
		// Force refresh of plugin update information.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
		wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   158
		if ( $parsed_args['overwrite_package'] ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   159
			/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   160
			 * Fires when the upgrader has successfully overwritten a currently installed
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   161
			 * plugin or theme with an uploaded zip package.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   162
			 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   163
			 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   164
			 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   165
			 * @param string  $package      The package file.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   166
			 * @param array   $data         The new plugin or theme data.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   167
			 * @param string  $package_type The package type ('plugin' or 'theme').
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   168
			 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   169
			do_action( 'upgrader_overwrote_package', $package, $this->new_plugin_data, 'plugin' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   170
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   171
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
		return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
	/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   176
	 * Upgrades a plugin.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
	 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	 * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
	 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   181
	 * @param string $plugin Path to the plugin file relative to the plugins directory.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	 * @param array  $args {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	 *     Optional. Other arguments for upgrading a plugin package. Default empty array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	 *     @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
	 *                                    Default true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
	 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
	 * @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
	public function upgrade( $plugin, $args = array() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   191
		$defaults    = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
			'clear_update_cache' => true,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
		$parsed_args = wp_parse_args( $args, $defaults );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
		$this->init();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		$this->upgrade_strings();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
		$current = get_site_transient( 'update_plugins' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   200
		if ( ! isset( $current->response[ $plugin ] ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
			$this->skin->before();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   202
			$this->skin->set_result( false );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   203
			$this->skin->error( 'up_to_date' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
			$this->skin->after();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   208
		// Get the URL to the zip file.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
		$r = $current->response[ $plugin ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   211
		add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   212
		add_filter( 'upgrader_pre_install', array( $this, 'active_before' ), 10, 2 );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   213
		add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   214
		add_filter( 'upgrader_post_install', array( $this, 'active_after' ), 10, 2 );
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   215
		/*
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   216
		 * There's a Trac ticket to move up the directory for zips which are made a bit differently, useful for non-.org plugins.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   217
		 * 'source_selection' => array( $this, 'source_selection' ),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   218
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
		if ( $parsed_args['clear_update_cache'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
			// Clear cache so wp_update_plugins() knows about the new plugin.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
			add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   224
		$this->run(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   225
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   226
				'package'           => $r->package,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   227
				'destination'       => WP_PLUGIN_DIR,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   228
				'clear_destination' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   229
				'clear_working'     => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   230
				'hook_extra'        => array(
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   231
					'plugin'      => $plugin,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   232
					'type'        => 'plugin',
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   233
					'action'      => 'update',
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   234
					'temp_backup' => array(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   235
						'slug' => dirname( $plugin ),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   236
						'src'  => WP_PLUGIN_DIR,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   237
						'dir'  => 'plugins',
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   238
					),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   239
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   240
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   241
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   243
		// Cleanup our hooks, in case something else does an upgrade on this connection.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
		remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   245
		remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   246
		remove_filter( 'upgrader_pre_install', array( $this, 'active_before' ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   247
		remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   248
		remove_filter( 'upgrader_post_install', array( $this, 'active_after' ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   250
		if ( ! $this->result || is_wp_error( $this->result ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
			return $this->result;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   252
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   254
		// Force refresh of plugin update information.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
		wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   257
		/*
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   258
		 * Ensure any future auto-update failures trigger a failure email by removing
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   259
		 * the last failure notification from the list when plugins update successfully.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   260
		 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   261
		$past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   262
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   263
		if ( isset( $past_failure_emails[ $plugin ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   264
			unset( $past_failure_emails[ $plugin ] );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   265
			update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   266
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   267
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
		return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
	/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   272
	 * Upgrades several plugins at once.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	 * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   277
	 * @param string[] $plugins Array of paths to plugin files relative to the plugins directory.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   278
	 * @param array    $args {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   279
	 *     Optional. Other arguments for upgrading several plugins at once.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
	 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   281
	 *     @type bool $clear_update_cache Whether to clear the plugin updates cache if successful. Default true.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
	 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
	 * @return array|false An array of results indexed by plugin file, or false if unable to connect to the filesystem.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
	public function bulk_upgrade( $plugins, $args = array() ) {
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   286
		$wp_version = wp_get_wp_version();
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   287
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   288
		$defaults    = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
			'clear_update_cache' => true,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
		$parsed_args = wp_parse_args( $args, $defaults );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
		$this->init();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
		$this->bulk = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
		$this->upgrade_strings();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
		$current = get_site_transient( 'update_plugins' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   299
		add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
		$this->skin->header();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   303
		// Connect to the filesystem first.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   304
		$res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
		if ( ! $res ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
			$this->skin->footer();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
		$this->skin->bulk_header();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
		/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		 * Only start maintenance mode if:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
		 * - running Multisite and there are one or more plugins specified, OR
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
		 * - a plugin with an update available is currently active.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   316
		 * @todo For multisite, maintenance mode should only kick in for individual sites if at all possible.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
		$maintenance = ( is_multisite() && ! empty( $plugins ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   319
		foreach ( $plugins as $plugin ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   320
			$maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin ] ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   321
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   322
		if ( $maintenance ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   323
			$this->maintenance_mode( true );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   324
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		$results = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   328
		$this->update_count   = count( $plugins );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
		$this->update_current = 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
		foreach ( $plugins as $plugin ) {
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   331
			++$this->update_current;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   332
			$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   334
			if ( ! isset( $current->response[ $plugin ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   335
				$this->skin->set_result( 'up_to_date' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
				$this->skin->before();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   337
				$this->skin->feedback( 'up_to_date' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
				$this->skin->after();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   339
				$results[ $plugin ] = true;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
				continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
			// Get the URL to the zip file.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
			$r = $current->response[ $plugin ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   346
			$this->skin->plugin_active = is_plugin_active( $plugin );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   348
			if ( isset( $r->requires ) && ! is_wp_version_compatible( $r->requires ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   349
				$result = new WP_Error(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   350
					'incompatible_wp_required_version',
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   351
					sprintf(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   352
						/* translators: 1: Current WordPress version, 2: WordPress version required by the new plugin version. */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   353
						__( 'Your WordPress version is %1$s, however the new plugin version requires %2$s.' ),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   354
						$wp_version,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   355
						$r->requires
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   356
					)
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   357
				);
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   358
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   359
				$this->skin->before( $result );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   360
				$this->skin->error( $result );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   361
				$this->skin->after();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   362
			} elseif ( isset( $r->requires_php ) && ! is_php_version_compatible( $r->requires_php ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   363
				$result = new WP_Error(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   364
					'incompatible_php_required_version',
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   365
					sprintf(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   366
						/* translators: 1: Current PHP version, 2: PHP version required by the new plugin version. */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   367
						__( 'The PHP version on your server is %1$s, however the new plugin version requires %2$s.' ),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   368
						PHP_VERSION,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   369
						$r->requires_php
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   370
					)
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   371
				);
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   372
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   373
				$this->skin->before( $result );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   374
				$this->skin->error( $result );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   375
				$this->skin->after();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   376
			} else {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   377
				add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   378
				$result = $this->run(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   379
					array(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   380
						'package'           => $r->package,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   381
						'destination'       => WP_PLUGIN_DIR,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   382
						'clear_destination' => true,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   383
						'clear_working'     => true,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   384
						'is_multi'          => true,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   385
						'hook_extra'        => array(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   386
							'plugin'      => $plugin,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   387
							'temp_backup' => array(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   388
								'slug' => dirname( $plugin ),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   389
								'src'  => WP_PLUGIN_DIR,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   390
								'dir'  => 'plugins',
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   391
							),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   392
						),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   393
					)
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   394
				);
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   395
				remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   396
			}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   398
			$results[ $plugin ] = $result;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   400
			// Prevent credentials auth screen from displaying multiple times.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   401
			if ( false === $result ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
				break;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   403
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   404
		} // End foreach $plugins.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   406
		$this->maintenance_mode( false );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
		// Force refresh of plugin update information.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
		wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
		/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   412
		do_action(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   413
			'upgrader_process_complete',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   414
			$this,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   415
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   416
				'action'  => 'update',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   417
				'type'    => 'plugin',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   418
				'bulk'    => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   419
				'plugins' => $plugins,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   420
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   421
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
		$this->skin->bulk_footer();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
		$this->skin->footer();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   427
		// Cleanup our hooks, in case something else does an upgrade on this connection.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   428
		remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   430
		/*
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   431
		 * Ensure any future auto-update failures trigger a failure email by removing
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   432
		 * the last failure notification from the list when plugins update successfully.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   433
		 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   434
		$past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   435
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   436
		foreach ( $results as $plugin => $result ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   437
			// Maintain last failure notification when plugins failed to update manually.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   438
			if ( ! $result || is_wp_error( $result ) || ! isset( $past_failure_emails[ $plugin ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   439
				continue;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   440
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   441
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   442
			unset( $past_failure_emails[ $plugin ] );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   443
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   444
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   445
		update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   446
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
		return $results;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   451
	 * Checks that the source package contains a valid plugin.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   453
	 * Hooked to the {@see 'upgrader_source_selection'} filter by Plugin_Upgrader::install().
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	 * @since 3.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   457
	 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
	 * @param string $source The path to the downloaded package source.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   460
	 * @return string|WP_Error The source as passed, or a WP_Error object on failure.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   462
	public function check_package( $source ) {
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   463
		global $wp_filesystem;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   465
		$wp_version            = wp_get_wp_version();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   466
		$this->new_plugin_data = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   467
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   468
		if ( is_wp_error( $source ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
			return $source;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   470
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   472
		$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   473
		if ( ! is_dir( $working_directory ) ) { // Confidence check, if the above fails, let's not prevent installation.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
			return $source;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   475
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   477
		// Check that the folder contains at least 1 valid plugin.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   478
		$files = glob( $working_directory . '*.php' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
		if ( $files ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
			foreach ( $files as $file ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
				$info = get_plugin_data( $file, false, false );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
				if ( ! empty( $info['Name'] ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   483
					$this->new_plugin_data = $info;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
					break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   489
		if ( empty( $this->new_plugin_data ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
			return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   491
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   493
		$requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   494
		$requires_wp  = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   495
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   496
		if ( ! is_php_version_compatible( $requires_php ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   497
			$error = sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   498
				/* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   499
				__( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   500
				PHP_VERSION,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   501
				$requires_php
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   502
			);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   503
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   504
			return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   505
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   506
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   507
		if ( ! is_wp_version_compatible( $requires_wp ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   508
			$error = sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   509
				/* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   510
				__( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   511
				$wp_version,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   512
				$requires_wp
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   513
			);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   514
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   515
			return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   516
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   517
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
		return $source;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
	/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   522
	 * Retrieves the path to the file that contains the plugin info.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
	 * This isn't used internally in the class, but is called by the skins.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	 * @return string|false The full path to the main plugin file, or false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
	public function plugin_info() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   531
		if ( ! is_array( $this->result ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   533
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   534
		if ( empty( $this->result['destination_name'] ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   536
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   538
		// Ensure to pass with leading slash.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   539
		$plugin = get_plugins( '/' . $this->result['destination_name'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   540
		if ( empty( $plugin ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   542
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   544
		// Assume the requested plugin is the first in the list.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   545
		$pluginfiles = array_keys( $plugin );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
		return $this->result['destination_name'] . '/' . $pluginfiles[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	 * Deactivates a plugin before it is upgraded.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	 * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
	 * @since 4.1.0 Added a return value.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   558
	 * @param bool|WP_Error $response The installation response before the installation has started.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   559
	 * @param array         $plugin   Plugin package arguments.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   560
	 * @return bool|WP_Error The original `$response` parameter or WP_Error.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   562
	public function deactivate_plugin_before_upgrade( $response, $plugin ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   564
		if ( is_wp_error( $response ) ) { // Bypass.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   565
			return $response;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   566
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   568
		// When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   569
		if ( wp_doing_cron() ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   570
			return $response;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   571
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   573
		$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   574
		if ( empty( $plugin ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   575
			return new WP_Error( 'bad_request', $this->strings['bad_request'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   576
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   578
		if ( is_plugin_active( $plugin ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   579
			// Deactivate the plugin silently, Prevent deactivation hooks from running.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   580
			deactivate_plugins( $plugin, true );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   583
		return $response;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   587
	 * Turns on maintenance mode before attempting to background update an active plugin.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   588
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   589
	 * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade().
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   590
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   591
	 * @since 5.4.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   592
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   593
	 * @param bool|WP_Error $response The installation response before the installation has started.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   594
	 * @param array         $plugin   Plugin package arguments.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   595
	 * @return bool|WP_Error The original `$response` parameter or WP_Error.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   596
	 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   597
	public function active_before( $response, $plugin ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   598
		if ( is_wp_error( $response ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   599
			return $response;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   600
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   601
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   602
		// Only enable maintenance mode when in cron (background update).
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   603
		if ( ! wp_doing_cron() ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   604
			return $response;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   605
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   606
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   607
		$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   608
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   609
		// Only run if plugin is active.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   610
		if ( ! is_plugin_active( $plugin ) ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   611
			return $response;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   612
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   613
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   614
		// Change to maintenance mode. Bulk edit handles this separately.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   615
		if ( ! $this->bulk ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   616
			$this->maintenance_mode( true );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   617
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   618
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   619
		return $response;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   620
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   621
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   622
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   623
	 * Turns off maintenance mode after upgrading an active plugin.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   624
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   625
	 * Hooked to the {@see 'upgrader_post_install'} filter by Plugin_Upgrader::upgrade().
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   626
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   627
	 * @since 5.4.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   628
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   629
	 * @param bool|WP_Error $response The installation response after the installation has finished.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   630
	 * @param array         $plugin   Plugin package arguments.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   631
	 * @return bool|WP_Error The original `$response` parameter or WP_Error.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   632
	 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   633
	public function active_after( $response, $plugin ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   634
		if ( is_wp_error( $response ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   635
			return $response;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   636
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   637
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   638
		// Only disable maintenance mode when in cron (background update).
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   639
		if ( ! wp_doing_cron() ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   640
			return $response;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   641
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   642
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   643
		$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   644
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   645
		// Only run if plugin is active.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   646
		if ( ! is_plugin_active( $plugin ) ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   647
			return $response;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   648
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   649
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   650
		// Time to remove maintenance mode. Bulk edit handles this separately.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   651
		if ( ! $this->bulk ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   652
			$this->maintenance_mode( false );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   653
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   654
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   655
		return $response;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   656
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   657
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   658
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   659
	 * Deletes the old plugin during an upgrade.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	 * Hooked to the {@see 'upgrader_clear_destination'} filter by
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	 * Plugin_Upgrader::upgrade() and Plugin_Upgrader::bulk_upgrade().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
	 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   666
	 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   667
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   668
	 * @param bool|WP_Error $removed            Whether the destination was cleared.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   669
	 *                                          True on success, WP_Error on failure.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   670
	 * @param string        $local_destination  The local package destination.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   671
	 * @param string        $remote_destination The remote package destination.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   672
	 * @param array         $plugin             Extra arguments passed to hooked filters.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   673
	 * @return bool|WP_Error
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   675
	public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
		global $wp_filesystem;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   678
		if ( is_wp_error( $removed ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   679
			return $removed; // Pass errors through.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   680
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   682
		$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   683
		if ( empty( $plugin ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   684
			return new WP_Error( 'bad_request', $this->strings['bad_request'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   685
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   687
		$plugins_dir     = $wp_filesystem->wp_plugins_dir();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   688
		$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   690
		if ( ! $wp_filesystem->exists( $this_plugin_dir ) ) { // If it's already vanished.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
			return $removed;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   692
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   694
		/*
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   695
		 * If plugin is in its own directory, recursively delete the directory.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   696
		 * Base check on if plugin includes directory separator AND that it's not the root plugin folder.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   697
		 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   698
		if ( strpos( $plugin, '/' ) && $this_plugin_dir !== $plugins_dir ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   699
			$deleted = $wp_filesystem->delete( $this_plugin_dir, true );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   700
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   701
			$deleted = $wp_filesystem->delete( $plugins_dir . $plugin );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   702
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   704
		if ( ! $deleted ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   705
			return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   706
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
		return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
}