Automattic\WooCommerce\Admin\API

Plugins::activate_plugins()publicWC 1.0

Activate the requested plugin.

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

Хуков нет.

Возвращает

WP_Error|Массив. Plugin Status

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

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

Код Plugins::activate_plugins() WC 6.9.4

public function activate_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_activate_plugins( $plugins );

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

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

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