WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\Domain\Services

ExtendRestApi::register_endpoint_data() public WC 1.0

An endpoint that validates registration method call

{} It's a method of the class: ExtendRestApi{}

No Hooks.

Return

true|false. True on success.

Usage

$ExtendRestApi = new ExtendRestApi();
$ExtendRestApi->register_endpoint_data( $args );
$args(array) (required)

An array of elements that make up a post to update or insert.

  • endpoint(string)
    The endpoint to extend.

  • namespace(string)
    Plugin namespace.

  • schema_callback(callable)
    Callback executed to add schema data.

  • data_callback(callable)
    Callback executed to add endpoint data.

  • data_type(string)
    The type of data, object or array.

Code of ExtendRestApi::register_endpoint_data() WC 5.6.0

public function register_endpoint_data( $args ) {
	if ( ! is_string( $args['namespace'] ) ) {
		$this->throw_exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' );
	}

	if ( ! is_string( $args['endpoint'] ) || ! in_array( $args['endpoint'], $this->endpoints, true ) ) {
		$this->throw_exception(
			sprintf( 'You must provide a valid Store REST endpoint to extend, valid endpoints are: %1$s. You provided %2$s.', implode( ', ', $this->endpoints ), $args['endpoint'] )
		);
	}

	if ( ! is_callable( $args['schema_callback'] ) ) {
		$this->throw_exception( '$schema_callback must be a callable function.' );
	}

	if ( ! is_callable( $args['data_callback'] ) ) {
		$this->throw_exception( '$data_callback must be a callable function.' );
	}

	if ( isset( $args['data_type'] ) && ! in_array( $args['data_type'], [ ARRAY_N, ARRAY_A ], true ) ) {
		$this->throw_exception(
			sprintf( 'Data type must be either ARRAY_N for a numeric array or ARRAY_A for an object like array. You provided %1$s.', $args['data_type'] )
		);
	}

	$this->extend_data[ $args['endpoint'] ][ $args['namespace'] ] = [
		'schema_callback' => $args['schema_callback'],
		'data_callback'   => $args['data_callback'],
		'data_type'       => isset( $args['data_type'] ) ? $args['data_type'] : ARRAY_A,
	];

	return true;
}