Automattic\WooCommerce\Admin\API

Plugins::install_plugins()publicWC 1.0

Installs the requested plugins.

{} Это метод класса: Plugins{}

Хуков нет.

Возвращает

WP_Error|Массив. Plugin Status

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

$Plugins = new Plugins();
$Plugins->install_plugins( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Код Plugins::install_plugins() WC 6.9.1

public function install_plugins( $request ) {
	$plugins = explode( ',', $request['plugins'] );

	if ( empty( $request['plugins'] ) || ! is_array( $plugins ) ) {
		return new \WP_Error( 'woocommerce_rest_invalid_plugins', __( 'Plugins must be a non-empty array.', 'woocommerce' ), 404 );
	}

	if ( isset( $request['async'] ) && $request['async'] ) {
		$job_id = PluginsHelper::schedule_install_plugins( $plugins );

		return array(
			'data'    => array(
				'job_id'  => $job_id,
				'plugins' => $plugins,
			),
			'message' => __( 'Plugin installation has been scheduled.', 'woocommerce' ),
		);
	}

	$data = PluginsHelper::install_plugins( $plugins );

	return array(
		'data'    => array(
			'installed'    => $data['installed'],
			'results'      => $data['results'],
			'install_time' => $data['time'],
		),
		'errors'  => $data['errors'],
		'success' => count( $data['errors']->errors ) === 0,
		'message' => count( $data['errors']->errors ) === 0
			? __( 'Plugins were successfully installed.', 'woocommerce' )
			: __( 'There was a problem installing some of the requested plugins.', 'woocommerce' ),
	);
}