Skip to content

Instantly share code, notes, and snippets.

View pinalj's full-sized avatar

Pinal pinalj

  • Tyche Softwares
  • Mumbai
View GitHub Profile
@pinalj
pinalj / permission_check.php
Last active December 1, 2017 06:49
Check for permissions for API
<?php
add_action( 'rest_api_init', 'my_register_route' );
function my_register_route() {
register_rest_route( 'my-route', 'my-phrase', array(
'methods' => 'GET',
'callback' => 'custom_phrase',
'permission_callback' => function() {
return current_user_can( 'edit_posts' );
},
@pinalj
pinalj / my-posts.php
Created December 1, 2017 06:33
Display all posts using REST API
<?php
add_action( 'rest_api_init', 'my_register_route');
function my_register_route() {
register_rest_route( 'my-route', 'my-posts', array(
'methods' => 'GET',
'callback' => 'my_posts',
'permission_callback' => function() {
return current_user_can( 'edit_others_posts' );
@pinalj
pinalj / my-posts-filter.php
Last active March 31, 2023 07:20
Filtering Posts based on Author ID - REST API
<?php
add_action( 'rest_api_init', 'my_register_route');
function my_register_route() {
register_rest_route( 'my-route', 'my-posts/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => 'my_posts',
'args' => array(
'id' => array(
'validate_callback' => function( $param, $request, $key ) {