Automattic\WooCommerce\StoreApi\Schemas
ExtendSchema::register_endpoint_data()
Register endpoint data under a specified namespace
Метод класса: ExtendSchema{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$ExtendSchema = new ExtendSchema(); $ExtendSchema->register_endpoint_data( $args );
- $args(массив) (обязательный)
An array of elements that make up a post to update or insert.
-
endpoint(строка)
Required. The endpoint to extend. -
namespace(строка)
Required. Plugin namespace. -
schema_callback(callable)
Callback executed to add schema data. -
data_callback(callable)
Callback executed to add endpoint data. - schema_type(строка)
The type of data, object or array.
-
Код ExtendSchema::register_endpoint_data() ExtendSchema::register endpoint data WC 9.8.1
public function register_endpoint_data( $args ) { $args = wp_parse_args( $args, [ 'endpoint' => '', 'namespace' => '', 'schema_callback' => null, 'data_callback' => null, 'schema_type' => ARRAY_A, ] ); if ( ! is_string( $args['namespace'] ) || empty( $args['namespace'] ) ) { $this->throw_exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' ); } if ( ! 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_null( $args['schema_callback'] ) && ! is_callable( $args['schema_callback'] ) ) { $this->throw_exception( '$schema_callback must be a callable function.' ); } if ( ! is_null( $args['data_callback'] ) && ! is_callable( $args['data_callback'] ) ) { $this->throw_exception( '$data_callback must be a callable function.' ); } if ( ! in_array( $args['schema_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['schema_type'] ) ); } $this->extend_data[ $args['endpoint'] ][ $args['namespace'] ] = [ 'schema_callback' => $args['schema_callback'], 'data_callback' => $args['data_callback'], 'schema_type' => $args['schema_type'], ]; }