Created
January 26, 2017 17:18
-
-
Save justingreerbbi/cee7b2c5dd8b415c473d99f0c58d1e82 to your computer and use it in GitHub Desktop.
WP REST API OAUTH2 - WP OAUTH SERVER EXAMPLE - AUTHENTICATION
This file contains hidden or 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', function () { | |
| register_rest_route( 'myplugin/v1', '/author/(?P<id>\d+)', array( | |
| 'methods' => 'GET', | |
| 'callback' => 'my_awesome_func', | |
| 'permission_callback' => function () { | |
| return current_user_can( 'manage_options' ); | |
| } | |
| ) ); | |
| } ); | |
| function my_awesome_func() { | |
| $user_id = get_current_user_id(); | |
| return array( | |
| 'status' => true, | |
| 'message' => 'Congrats! You successfully made an authenticated request to a protected endpoint', | |
| 'user_id' => $user_id | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment