Automattic\WooCommerce\Admin\API

OnboardingPlugins::get_scheduled_installs()publicWC 1.0

Returns current status of given job.

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

Хуков нет.

Возвращает

Массив|WP_REST_Response.

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

$OnboardingPlugins = new OnboardingPlugins();
$OnboardingPlugins->get_scheduled_installs( $request );
$request(WP_REST_Request) (обязательный)
WP_REST_Request object.

Код OnboardingPlugins::get_scheduled_installs() WC 9.3.1

public function get_scheduled_installs( WP_REST_Request $request ) {
	$job_id = $request->get_param( 'job_id' );

	$actions = WC()->queue()->search(
		array(
			'hook'    => 'woocommerce_plugins_install_and_activate_async_callback',
			'search'  => $job_id,
			'orderby' => 'date',
			'order'   => 'DESC',
		)
	);

	$actions = array_filter(
		PluginsHelper::get_action_data( $actions ),
		function( $action ) use ( $job_id ) {
			return $action['job_id'] === $job_id;
		}
	);

	if ( empty( $actions ) ) {
		return new WP_REST_Response( null, 404 );
	}

	$response = array(
		'job_id' => $actions[0]['job_id'],
		'status' => $actions[0]['status'],
	);

	$option = get_option( 'woocommerce_onboarding_plugins_install_and_activate_async_' . $job_id );
	if ( isset( $option['plugins'] ) ) {
		$response['plugins'] = $option['plugins'];
	}

	return $response;
}