Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*** JSON API ***/
- function myplugin_api_init() {
- global $myplugin_api_mytype;
- $myplugin_api_mytype = new MyPlugin_API_MyType();
- add_filter( 'json_endpoints', array( $myplugin_api_mytype, 'register_routes' ) );
- }
- add_action( 'wp_json_server_before_serve', 'myplugin_api_init' );
- class MyPlugin_API_MyType {
- public function register_routes( $routes ) {
- $routes['/json/test'] = array(
- array( array( $this, 'get_posts'), WP_JSON_Server::READABLE ),
- array( array( $this, 'new_post'), WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON ),
- );
- $routes['/json/test/(?P<id>\d+)'] = array(
- array( array( $this, 'get_post'), WP_JSON_Server::READABLE ),
- array( array( $this, 'edit_post'), WP_JSON_Server::EDITABLE | WP_JSON_Server::ACCEPT_JSON ),
- array( array( $this, 'delete_post'), WP_JSON_Server::DELETABLE ),
- );
- // Add more custom routes here
- return $routes;
- }
- function get_posts() {
- return(
- array(
- 'id' => 9,
- 'name'=> 'Member\'s Apothecary'
- )
- );
- }
- function new_post() {
- }
- // ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement