Automattic\WooCommerce\Internal\Utilities

PluginInstaller::handle_upgrader_process_complete()publicWC 1.0

Handler for the upgrader_process_complete It's used to remove the autoinstalled plugin information for plugins that are upgraded or reinstalled manually (or more generally, by using any install method other than this class).

Метод класса: PluginInstaller{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$PluginInstaller = new PluginInstaller();
$PluginInstaller->handle_upgrader_process_complete( $upgrader, $hook_extra );
$upgrader(\WP_Upgrader) (обязательный)
The upgrader class that has performed the plugin upgrade/reinstall.
$hook_extra(массив) (обязательный)
Extra information about the upgrade process.

Код PluginInstaller::handle_upgrader_process_complete() WC 9.7.1

public function handle_upgrader_process_complete( \WP_Upgrader $upgrader, array $hook_extra ) {
	if ( $this->installing_plugin || ! ( $upgrader instanceof \Plugin_Upgrader ) || ( 'plugin' !== ( $hook_extra['type'] ?? null ) ) ) {
		return;
	}

	$auto_installed_plugins = get_site_option( 'woocommerce_autoinstalled_plugins' );
	if ( ! $auto_installed_plugins ) {
		return;
	}

	if ( $hook_extra['bulk'] ?? false ) {
		$updated_plugin_names = $hook_extra['plugins'] ?? array();
	} else {
		$updated_plugin_names = array( $upgrader->plugin_info() );
	}

	$auto_installed_plugin_names         = array_keys( $auto_installed_plugins );
	$updated_auto_installed_plugin_names = array_intersect( $auto_installed_plugin_names, $updated_plugin_names );

	if ( empty( $updated_auto_installed_plugin_names ) ) {
		return;
	}

	$new_auto_installed_plugins = array_diff_key( $auto_installed_plugins, array_flip( $updated_auto_installed_plugin_names ) );

	if ( empty( $new_auto_installed_plugins ) ) {
		delete_site_option( 'woocommerce_autoinstalled_plugins' );
	} else {
		update_site_option( 'woocommerce_autoinstalled_plugins', $new_auto_installed_plugins );
	}
}