Automattic\WooCommerce\Admin\Features\Blueprint
RestApi::import_step
Import a single step.
Method of the class: RestApi{}
No Hooks.
Returns
\WP_REST_Response|Array.
Usage
$RestApi = new RestApi(); $RestApi->import_step( $request );
- $request(WP_REST_Request) (required)
- The request object.
RestApi::import_step() RestApi::import step code WC 10.6.2
public function import_step( \WP_REST_Request $request ) {
$session_token = $request->get_header( 'X-Blueprint-Import-Session' );
// If no session token, this is the first step: generate and store a new token.
if ( ! $session_token ) {
$session_token = function_exists( 'wp_generate_uuid4' ) ? wp_generate_uuid4() : uniqid( 'bp_', true );
}
if ( ! $this->can_import_blueprint( $session_token ) ) {
return array(
'success' => false,
'messages' => array(
array(
'message' => __( 'Blueprint imports are disabled', 'woocommerce' ),
'type' => 'error',
),
),
);
}
if ( false === get_transient( 'blueprint_import_session_' . $session_token ) ) {
set_transient( 'blueprint_import_session_' . $session_token, true, 10 * MINUTE_IN_SECONDS );
}
// Get the raw body size.
$body_size = strlen( $request->get_body() );
if ( $body_size > $this->get_max_file_size() ) {
return array(
'success' => false,
'messages' => array(
array(
'message' => sprintf(
// Translators: %s is the maximum file size in megabytes.
__( 'Blueprint step definition size exceeds maximum limit of %s MB', 'woocommerce' ),
( $this->get_max_file_size() / ( 1024 * 1024 ) )
),
'type' => 'error',
),
),
);
}
// Make sure we're dealing with object.
$step_definition = json_decode( wp_json_encode( $request->get_param( 'step_definition' ) ) );
$step_importer = new ImportStep( $step_definition );
$result = $step_importer->import();
$response = new \WP_REST_Response(
array(
'success' => $result->is_success(),
'messages' => $result->get_messages(),
)
);
$response->header( 'X-Blueprint-Import-Session', $session_token );
return $response;
}