14 if ( ! defined(
'GRAVITYVIEW_DIR' ) ) {
18 abstract class Route extends \WP_REST_Controller {
43 $output_buffer = ob_get_clean();
48 register_rest_route( $namespace,
'/' . $base, array(
50 'methods' => \WP_REST_Server::READABLE,
51 'callback' => array( $this,
'get_items' ),
52 'permission_callback' => array( $this,
'get_items_permissions_check' ),
56 'sanitize_callback' =>
'absint' 60 'sanitize_callback' =>
'absint' 64 'sanitize_callback' =>
'absint' 69 'methods' => \WP_REST_Server::CREATABLE,
70 'callback' => array( $this,
'create_item' ),
71 'permission_callback' => array( $this,
'create_item_permissions_check' ),
72 'args' => $this->create_item_args()
76 register_rest_route( $namespace,
'/' . $base .
'/(?P<id>[\d]+)', array(
78 'methods' => \WP_REST_Server::READABLE,
79 'callback' => array( $this,
'get_item' ),
80 'permission_callback' => array( $this,
'get_item_permissions_check' ),
88 'methods' => \WP_REST_Server::EDITABLE,
89 'callback' => array( $this,
'update_item' ),
90 'permission_callback' => array( $this,
'update_item_permissions_check' ),
91 'args' => $this->update_item_args(),
94 'methods' => \WP_REST_Server::DELETABLE,
95 'callback' => array( $this,
'delete_item' ),
96 'permission_callback' => array( $this,
'delete_item_permissions_check' ),
107 $format =
'(?:\.(?P<format>html|json|csv|tsv))?';
109 register_rest_route( $namespace,
'/' . $base .
'/(?P<id>[\d]+)' .
'/' .
$sub_type .
$format, array(
111 'methods' => \WP_REST_Server::READABLE,
112 'callback' => array( $this,
'get_sub_items' ),
113 'permission_callback' => array( $this,
'get_sub_items_permissions_check' ),
117 'sanitize_callback' =>
'absint' 121 'sanitize_callback' =>
'absint' 125 'sanitize_callback' =>
'absint' 130 'methods' => \WP_REST_Server::CREATABLE,
131 'callback' => array( $this,
'create_sub_item' ),
132 'permission_callback' => array( $this,
'create_sub_item_permissions_check' ),
133 'args' => $this->create_sub_item_args()
137 $format =
'(?:\.(?P<format>html|json))?';
139 register_rest_route( $namespace, sprintf(
'/%s/(?P<id>[\d]+)/%s/(?P<s_id>[\w-]+)%s', $base,
$sub_type, $format ) , array(
141 'methods' => \WP_REST_Server::READABLE,
142 'callback' => array( $this,
'get_sub_item' ),
143 'permission_callback' => array( $this,
'get_sub_item_permissions_check' ),
151 'methods' => \WP_REST_Server::EDITABLE,
152 'callback' => array( $this,
'update_sub_item' ),
153 'permission_callback' => array( $this,
'update_sub_item_permissions_check' ),
154 'args' => $this->update_sub_item_args()
157 'methods' => \WP_REST_Server::DELETABLE,
158 'callback' => array( $this,
'delete_sub_item' ),
159 'permission_callback' => array( $this,
'delete_sub_item_permissions_check' ),
181 if ( is_string( $this->route_name ) ) {
184 _doing_it_wrong( __METHOD__, __(
'Must set route name in subclass.',
'gk-gravityview' ),
'2.0' );
199 if ( is_string( $this->sub_type ) ) {
202 _doing_it_wrong( __METHOD__, __(
'Must set route sub type in subclass.',
'gk-gravityview' ),
'2.0' );
391 $error = new \WP_Error(
'not-implemented-yet', __(
'Endpoint Not Yet Implemented.',
'gk-gravityview' ) );
392 return new \WP_REST_Response( $error, 501 );
405 if ( in_array( $method, array(
408 'create_sub_item_args',
409 'update_sub_item_args' create_item( $request)
Create one item from the collection.
get_item( $request)
Get one item from the collection.
update_sub_item( $request)
Update one item from the collection for sub items.
get_route_name()
Get route name.
create_item_permissions_check( $request)
Check if a given request has access to create items.
update_item_permissions_check( $request)
Check if a given request has access to update a specific item.
if(gv_empty( $field['value'], false, false)) $format
register_routes()
Register the routes for the objects of the controller.
prepare_item_for_response( $item, $request)
Prepare the item for the REST response.
If this file is called directly, abort.
get_sub_type()
Get sub_type.
update_item( $request)
Update one item from the collection.
delete_item_permissions_check( $request)
Check if a given request has access to delete a specific item.
not_implemented()
Generic response for routes not yet implemented.
prepare_item_for_database( $request)
Prepare the item for create or update operation.
get_sub_item( $request)
Get one item from the collection.
static get_namespace()
Get namespace for GravityView REST API endpoints.
get_sub_items( $request)
Get a collection of items.
__call( $method, $args)
Fallback if subclass doesn't define routes.
get_items( $request)
Get a collection of items.
delete_sub_item( $request)
Delete one item from the collection for sub items.
delete_item( $request)
Delete one item from the collection.
get_item_permissions_check( $request)
Check if a given request has access to get a specific item.
get_items_permissions_check( $request)
Check if a given request has access to get items.
create_sub_item( $request)
Create one item from the collection.