PHP code example of cuberis / wp-rest-endpoints
1. Go to this page and download the library: Download cuberis/wp-rest-endpoints library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cuberis / wp-rest-endpoints example snippets
function my_register_rest_routes() {
new Cuberis\REST_API\Post_Type_Controller('my_post_type_slug', [
'namespace' => 'cuberis',
'version' => 1,
'endpoint' => 'my-post-type'
]);
}
add_action( 'rest_api_init', 'my_register_rest_routes' );
class My_Custom_Controller extends Cuberis\REST_API\Base_Controller {
public function __construct() {
parent::__construct([
'namespace' => 'cuberis',
'version' => 1,
'endpoint' => 'whatever'
]);
}
public function get_items( $request ) {
return rest_ensure_response(['Testing']);
}
}
function my_register_rest_routes() {
new My_Custom_Controller();
}
add_action( 'rest_api_init', 'my_register_rest_routes' );
function cuberis_filter_api_result( $result, $post_id ) {
return [
'pageID' => $post_id,
'testing' => 'yep!'
];
}
add_filter('cuberis_rest_cpt_result', 'cuberis_filter_api_result', 10, 2);
function cuberis_filter_api_args( $args, $params ) {
$args['order'] = 'ASC';
return $args;
}
add_filter('cuberis_rest_api_query_args', 'cuberis_filter_api_args', 10, 2);