Last active
November 3, 2021 05:24
-
-
Save mishterk/cdb241c1deda8afb6bd73efdfcc9da50 to your computer and use it in GitHub Desktop.
WordPress REST API examples
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', function () { | |
register_rest_route( 'my-namespace/v1', 'some/route', [ | |
'methods' => [ 'GET' ], | |
'permission_callback' => '__return_true', | |
'callback' => function () { | |
// You can return arrays or objects here — WordPress will | |
// format them for output as JSON. | |
return [ | |
'some' => 'custom', | |
'data' => 'can', | |
'go' => 'here', | |
]; | |
}, | |
] | |
); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment