Last active
May 2, 2018 14:23
-
-
Save gdarko/3c0dc7083eb55ae3f642b9be02da7d95 to your computer and use it in GitHub Desktop.
WordPress REST Route Example
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 | |
function dg_get_data() { | |
return array( | |
'name' => 'Darko Gjorgjijoski', | |
'age' => 23 | |
); | |
} |
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 | |
define('API_VERSION', 'v1'); | |
include 'methods.php' | |
add_filter( 'rest_url_prefix', function() { | |
return 'api'; | |
}); | |
add_action( 'rest_api_init', function () { | |
register_rest_route( API_VERSION, '/data', array( | |
'methods' => 'GET', | |
'callback' => 'dg_get_data', //See api.php | |
) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment