Last active
December 1, 2017 06:49
-
-
Save pinalj/cb9f72bcb6a6e9867b067fc7575ac8ac to your computer and use it in GitHub Desktop.
Check for permissions for API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
}, | |
) | |
); | |
} | |
function custom_phrase() { | |
return rest_ensure_response( 'Hello World! This is my first REST API' ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment