Created
February 3, 2016 23:58
-
-
Save georgestephanis/0f12661dbbb5eac1cfcb to your computer and use it in GitHub Desktop.
This is a tester for wp rest api authentication. You can call against unsecured and it'll always work, but change to secured and it'll only work for authed admins.
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', 'myhacks_init' ); | |
function myhacks_init() { | |
register_rest_route( 'myhacks', '/unsecured', array( | |
'methods' => 'GET', | |
'callback' => 'myhacks_response', | |
) ); | |
register_rest_route( 'myhacks', '/secured', array( | |
'methods' => 'GET', | |
'callback' => 'myhacks_response', | |
'permission_callback' => 'myhacks_permission_callback', | |
) ); | |
} | |
function myhacks_response() { | |
return array( 'doowop' => 'Data wants to be free, yo?' ); | |
} | |
function myhacks_permission_callback() { | |
return current_user_can( 'manage_options' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! Worked well 👍