Class WC_API_Resource
Methods summary
public
WC_API_Resource
|
|
protected
integer|WP_Error
|
#
validate_request( string|integer $id, string $type, string $context )
Validate the request by checking:
Validate the request by checking:
- the ID is a valid integer
- the ID returns a valid post object and matches the provided post type
- the current user has the proper permissions to read/edit/delete the
post
Parameters
- $id
string|integer $id the post ID
- $type
string $type the post type, either shop_order , shop_coupon ,
or product
- $context
string $context the context of the request, either read , edit
or delete
Returns
integer|WP_Error valid post ID or WP_Error if any of the checks fails
Since
2.1
|
protected
array
|
#
merge_query_args( array $base_args, array $request_args )
Add common request arguments to argument list before WP_Query is run
Add common request arguments to argument list before WP_Query is run
Parameters
- $base_args
array $base_args required arguments for the query (e.g. post_type , etc)
- $request_args
array $request_args arguments provided in the request
Returns
array
Since
2.1
|
public
mixed
|
#
maybe_add_meta( array $data, object $resource )
Add meta to resources when requested by the client. Meta is added as a
top-level <resource_name>_meta attribute (e.g.
order_meta ) as a list of key/value pairs
Add meta to resources when requested by the client. Meta is added as a
top-level <resource_name>_meta attribute (e.g.
order_meta ) as a list of key/value pairs
Parameters
- $data
array $data the resource data
- $resource
object $resource the resource object (e.g WC_Order)
Returns
mixed
Since
2.1
|
public
array
|
#
filter_response_fields( array $data, object $resource, array|string $fields )
Restrict the fields included in the response if the request specified certain
only certain fields should be returned
Restrict the fields included in the response if the request specified certain
only certain fields should be returned
Parameters
- $data
array $data the response data
- $resource
object $resource the object that provided the response data, e.g. WC_Coupon or WC_Order
- $fields
array|string the requested list of fields to include in the response
Returns
array response data
Since
2.1
|
protected
array|WP_Error
|
#
delete( integer $id, string $type, boolean $force = false )
Delete a given resource
Parameters
- $id
integer $id the resource ID
- $type
string $type the resource post type, or customer
- $force
boolean $force true to permanently delete resource, false to move to trash (not
supported for customer )
Returns
array|WP_Error
Since
2.1
|
protected
boolean
|
#
is_readable( WP_Post|integer $post )
Checks if the given post is readable by the current user
Checks if the given post is readable by the current user
Parameters
- $post
WP_Post|integer $post
Returns
boolean
Since
2.1
See
WC_API_Resource::check_permission()
|
protected
boolean
|
#
is_editable( WP_Post|integer $post )
Checks if the given post is editable by the current user
Checks if the given post is editable by the current user
Parameters
- $post
WP_Post|integer $post
Returns
boolean
Since
2.1
See
WC_API_Resource::check_permission()
|
protected
boolean
|
#
is_deletable( WP_Post|integer $post )
Checks if the given post is deletable by the current user
Checks if the given post is deletable by the current user
Parameters
- $post
WP_Post|integer $post
Returns
boolean
Since
2.1
See
WC_API_Resource::check_permission()
|
Magic methods summary
Properties summary
protected
WC_API_Server
|
$server
|
|
protected
string
|
$base
|
#
sub-classes override this to set a resource-specific base route
sub-classes override this to set a resource-specific base route
|