Automattic\WooCommerce\Admin

PluginsInstaller::possibly_install_activate_plugins()public staticWC 1.0

Check if an install or activation is being requested via URL query.

Method of the class: PluginsInstaller{}

No Hooks.

Return

null. Nothing.

Usage

$result = PluginsInstaller::possibly_install_activate_plugins();

PluginsInstaller::possibly_install_activate_plugins() code WC 7.1.0

public static function possibly_install_activate_plugins() {
	/* phpcs:disable WordPress.Security.NonceVerification.Recommended */
	if (
		! isset( $_GET['plugin_action'] ) ||
		! isset( $_GET['plugins'] ) ||
		! current_user_can( 'install_plugins' ) ||
		! isset( $_GET['nonce'] )
	) {
		return;
	}

	$nonce = sanitize_text_field( wp_unslash( $_GET['nonce'] ) );

	if ( ! wp_verify_nonce( $nonce, 'install-plugin' ) ) {
		wp_nonce_ays( 'install-plugin' );
	}

	$plugins       = sanitize_text_field( wp_unslash( $_GET['plugins'] ) );
	$plugin_action = sanitize_text_field( wp_unslash( $_GET['plugin_action'] ) );
	/* phpcs:enable WordPress.Security.NonceVerification.Recommended */

	$plugins_api     = new Plugins();
	$install_result  = null;
	$activate_result = null;

	switch ( $plugin_action ) {
		case 'install':
			$install_result = $plugins_api->install_plugins( array( 'plugins' => $plugins ) );
			break;
		case 'activate':
			$activate_result = $plugins_api->activate_plugins( array( 'plugins' => $plugins ) );
			break;
		case 'install-activate':
			$install_result  = $plugins_api->install_plugins( array( 'plugins' => $plugins ) );
			$activate_result = $plugins_api->activate_plugins( array( 'plugins' => implode( ',', $install_result['data']['installed'] ) ) );
			break;
	}

	self::cache_results( $plugins, $install_result, $activate_result );
	self::redirect_to_referer();
}