Automattic\WooCommerce\Internal\Orders
OrderAttributionBlocksController::get_schema_callback
Get the schema callback.
Method of the class: OrderAttributionBlocksController{}
No Hooks.
Returns
callable.
Usage
// private - for code of main (parent) class only $result = $this->get_schema_callback();
OrderAttributionBlocksController::get_schema_callback() OrderAttributionBlocksController::get schema callback code WC 10.3.3
private function get_schema_callback() {
return function() {
$schema = array();
$field_names = $this->order_attribution_controller->get_field_names();
$validate_callback = function( $value ) {
if ( ! is_string( $value ) && null !== $value ) {
return new WP_Error(
'api-error',
sprintf(
/* translators: %s is the property type */
esc_html__( 'Value of type %s was posted to the order attribution callback', 'woocommerce' ),
gettype( $value )
)
);
}
return true;
};
$sanitize_callback = function( $value ) {
return sanitize_text_field( $value );
};
foreach ( $field_names as $field_name ) {
$schema[ $field_name ] = array(
'description' => sprintf(
/* translators: %s is the field name */
__( 'Order attribution field: %s', 'woocommerce' ),
esc_html( $field_name )
),
'type' => array( 'string', 'null' ),
'context' => array(),
'arg_options' => array(
'validate_callback' => $validate_callback,
'sanitize_callback' => $sanitize_callback,
),
);
}
return $schema;
};
}