Controller
extends AbstractController
in package
OrdersNotes Controller.
Table of Contents
- CANNOT_CREATE = 'cannot_create'
- CANNOT_DELETE = 'cannot_delete'
- CANNOT_TRASH = 'cannot_trash'
- INVALID_ID = 'invalid_id'
- Shared error codes.
- RESOURCE_EXISTS = 'resource_exists'
- TRASH_NOT_SUPPORTED = 'trash_not_supported'
- $item_schema : OrderNoteSchema
- Schema class for this route.
- $namespace : string
- Route namespace.
- $query_utils : QueryUtils
- Query utils class.
- $rest_base : string
- Route base.
- $schema : array<string|int, mixed>
- Cache for the item schema populated after calling get_item_schema().
- create_item() : WP_Error|WP_REST_Response
- Create a single item.
- create_item_permissions_check() : WP_Error|bool
- Check if a given request has access to create an item.
- delete_item() : WP_REST_Response|WP_Error
- Delete a single item.
- delete_item_permissions_check() : bool|WP_Error
- Check if a given request has access to delete an item.
- get_collection_params() : array<string|int, mixed>
- Add default context collection params and filter the result. This does not inherit from WP_REST_Controller::get_collection_params because some endpoints do not paginate results.
- get_item() : WP_Error|WP_REST_Response
- Get a single item.
- get_item_permissions_check() : WP_Error|bool
- Check if a given request has access to read an item.
- get_item_schema() : array<string|int, mixed>
- Get item schema, conforming to JSON Schema. Extended by routes.
- get_items() : WP_Error|WP_REST_Response
- Get collection of orders.
- get_items_permissions_check() : WP_Error|bool
- Check if a given request has access to read items.
- prepare_item_for_response() : WP_REST_Response|WP_Error
- Prepares the item for the REST response. Controllers do not need to override this method as they can define a get_item_response method to prepare items. This method will take care of filter hooks.
- register_routes() : mixed
- Register the routes for orders.
- get_authentication_error_by_method() : WP_Error|false
- Returns an authentication error for a given HTTP verb.
- get_error_prefix() : string
- Get the error prefix for errors.
- get_hook_prefix() : string
- Get the hook prefix for actions and filters.
- get_item_response() : array<string|int, mixed>
- Prepare a single order note item for response.
- get_note_by_id() : WP_Comment|null
- Get a note by ID.
- get_order_by_id() : WC_Order|null
- Get an order by ID.
- get_order_by_note_id() : WC_Order|null
- Get the parent order of a note.
- get_query_schema() : array<string|int, mixed>
- Get the collection args schema.
- get_route_error_by_code() : WP_Error
- Get an error response for a given error code.
- get_route_error_response() : WP_Error
- Get route response when something went wrong.
- get_route_error_response_from_object() : WP_Error
- Get route response when something went wrong and the supplied error is a WP_Error.
- get_schema() : array<string|int, mixed>
- Get the schema for the current resource. This use consumed by the AbstractController to generate the item schema after running various hooks on the response.
- is_valid_order_id() : bool
- Check if an order is valid.
- prepare_links() : array<string|int, mixed>
- Prepare links for the request.
Constants
CANNOT_CREATE
public
mixed
CANNOT_CREATE
= 'cannot_create'
CANNOT_DELETE
public
mixed
CANNOT_DELETE
= 'cannot_delete'
CANNOT_TRASH
public
mixed
CANNOT_TRASH
= 'cannot_trash'
INVALID_ID
Shared error codes.
public
mixed
INVALID_ID
= 'invalid_id'
RESOURCE_EXISTS
public
mixed
RESOURCE_EXISTS
= 'resource_exists'
TRASH_NOT_SUPPORTED
public
mixed
TRASH_NOT_SUPPORTED
= 'trash_not_supported'
Properties
$item_schema
Schema class for this route.
protected
OrderNoteSchema
$item_schema
$namespace
Route namespace.
protected
string
$namespace
= 'wc/v4'
$query_utils
Query utils class.
protected
QueryUtils
$query_utils
$rest_base
Route base.
protected
string
$rest_base
= 'order-notes'
$schema
Cache for the item schema populated after calling get_item_schema().
protected
array<string|int, mixed>
$schema
Methods
create_item()
Create a single item.
public
create_item(WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_Error|WP_REST_Response —create_item_permissions_check()
Check if a given request has access to create an item.
public
create_item_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
- $request : WP_REST_Request
-
The request object.
Return values
WP_Error|bool —delete_item()
Delete a single item.
public
delete_item(WP_REST_Request $request) : WP_REST_Response|WP_Error
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_REST_Response|WP_Error —delete_item_permissions_check()
Check if a given request has access to delete an item.
public
delete_item_permissions_check(WP_REST_Request $request) : bool|WP_Error
Parameters
- $request : WP_REST_Request
-
The request object.
Return values
bool|WP_Error —get_collection_params()
Add default context collection params and filter the result. This does not inherit from WP_REST_Controller::get_collection_params because some endpoints do not paginate results.
public
get_collection_params() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_item()
Get a single item.
public
get_item(WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_Error|WP_REST_Response —get_item_permissions_check()
Check if a given request has access to read an item.
public
get_item_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
- $request : WP_REST_Request
-
The request object.
Return values
WP_Error|bool —get_item_schema()
Get item schema, conforming to JSON Schema. Extended by routes.
public
get_item_schema() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — The item schema.get_items()
Get collection of orders.
public
get_items(WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_Error|WP_REST_Response —get_items_permissions_check()
Check if a given request has access to read items.
public
get_items_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_Error|bool —prepare_item_for_response()
Prepares the item for the REST response. Controllers do not need to override this method as they can define a get_item_response method to prepare items. This method will take care of filter hooks.
public
prepare_item_for_response(mixed $item, WP_REST_Request $request) : WP_REST_Response|WP_Error
Parameters
- $item : mixed
-
WordPress representation of the item.
- $request : WP_REST_Request
-
Request object.
Tags
Return values
WP_REST_Response|WP_Error — Response object on success, or WP_Error object on failure.register_routes()
Register the routes for orders.
public
register_routes() : mixed
Return values
mixed —get_authentication_error_by_method()
Returns an authentication error for a given HTTP verb.
protected
get_authentication_error_by_method(string $method) : WP_Error|false
Parameters
- $method : string
-
HTTP method.
Return values
WP_Error|false — WP Error object or false if no error is found.get_error_prefix()
Get the error prefix for errors.
protected
get_error_prefix() : string
Example: woocommerce_rest_api_v4_orders_
Tags
Return values
string — The error prefix.get_hook_prefix()
Get the hook prefix for actions and filters.
protected
get_hook_prefix() : string
Example: woocommerce_rest_api_v4_orders_
Tags
Return values
string — The hook prefix.get_item_response()
Prepare a single order note item for response.
protected
get_item_response(WP_Comment $note, WP_REST_Request $request) : array<string|int, mixed>
Parameters
- $note : WP_Comment
-
Note object.
- $request : WP_REST_Request
-
Request object.
Return values
array<string|int, mixed> —get_note_by_id()
Get a note by ID.
protected
get_note_by_id(int $note_id) : WP_Comment|null
Parameters
- $note_id : int
-
The note ID.
Return values
WP_Comment|null —get_order_by_id()
Get an order by ID.
protected
get_order_by_id(int $order_id) : WC_Order|null
Parameters
- $order_id : int
-
The order ID.
Return values
WC_Order|null —get_order_by_note_id()
Get the parent order of a note.
protected
get_order_by_note_id(int|WP_Comment $note_id) : WC_Order|null
Parameters
- $note_id : int|WP_Comment
-
The note ID or note object.
Return values
WC_Order|null —get_query_schema()
Get the collection args schema.
protected
get_query_schema() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_route_error_by_code()
Get an error response for a given error code.
protected
get_route_error_by_code(string $error_code) : WP_Error
Parameters
- $error_code : string
-
The error code.
Return values
WP_Error — WP Error object.get_route_error_response()
Get route response when something went wrong.
protected
get_route_error_response(string $error_code, string $error_message[, int $http_status_code = WP_Http::BAD_REQUEST ][, array<string|int, mixed> $additional_data = array() ]) : WP_Error
Parameters
- $error_code : string
-
String based error code.
- $error_message : string
-
User facing error message.
- $http_status_code : int = WP_Http::BAD_REQUEST
-
HTTP status. Defaults to 400.
- $additional_data : array<string|int, mixed> = array()
-
Extra data (key value pairs) to expose in the error response.
Tags
Return values
WP_Error — WP Error object.get_route_error_response_from_object()
Get route response when something went wrong and the supplied error is a WP_Error.
protected
get_route_error_response_from_object(WP_Error $error_object[, int $http_status_code = WP_Http::BAD_REQUEST ][, array<string|int, mixed> $additional_data = array() ]) : WP_Error
Parameters
- $error_object : WP_Error
-
The WP_Error object containing the error.
- $http_status_code : int = WP_Http::BAD_REQUEST
-
HTTP status. Defaults to 400.
- $additional_data : array<string|int, mixed> = array()
-
Extra data (key value pairs) to expose in the error response.
Tags
Return values
WP_Error — WP Error object.get_schema()
Get the schema for the current resource. This use consumed by the AbstractController to generate the item schema after running various hooks on the response.
protected
get_schema() : array<string|int, mixed>
Return values
array<string|int, mixed> — The full item schema.is_valid_order_id()
Check if an order is valid.
protected
is_valid_order_id(mixed $order_id) : bool
Parameters
- $order_id : mixed
-
The order ID.
Return values
bool — True if the order is valid, false otherwise.prepare_links()
Prepare links for the request.
protected
prepare_links(mixed $item, WP_REST_Request $request, WP_REST_Response $response) : array<string|int, mixed>
Parameters
- $item : mixed
-
WordPress representation of the item.
- $request : WP_REST_Request
-
Request object.
- $response : WP_REST_Response
-
Response object.
