wordpress create REST Api
Example 1
Example 2 – Passing parameter
Example 3 – Passing multiple parameters
Example 3- permission check
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
add_action( 'rest_api_init', function () {
register_rest_route( 'api', '/v1/get/sitemap', array(
'methods' => 'GET',
'callback' => 'api_function_to_get_sitemap',
'permission_callback' => function () {
return permissions_check();
}
));
register_rest_route( 'api', '/v1/get/page/(?P<page_slug>[a-z0-9\-]+)', array(
'methods' => 'GET',
'callback' => 'api_function_to_get_page_by_slug',
'permission_callback' => array( $this, 'permissions_check' )
));
});
function permissions_check(){
//permission check will perform here
return true;
}
|
0 comments:
Post a Comment
Don't Forget to comment