Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. /*** JSON API ***/
  2. function myplugin_api_init() {
  3. global $myplugin_api_mytype;
  4.  
  5. $myplugin_api_mytype = new MyPlugin_API_MyType();
  6. add_filter( 'json_endpoints', array( $myplugin_api_mytype, 'register_routes' ) );
  7. }
  8. add_action( 'wp_json_server_before_serve', 'myplugin_api_init' );
  9.  
  10. class MyPlugin_API_MyType {
  11. public function register_routes( $routes ) {
  12. $routes['/json/test'] = array(
  13. array( array( $this, 'get_posts'), WP_JSON_Server::READABLE ),
  14. array( array( $this, 'new_post'), WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON ),
  15. );
  16. $routes['/json/test/(?P<id>\d+)'] = array(
  17. array( array( $this, 'get_post'), WP_JSON_Server::READABLE ),
  18. array( array( $this, 'edit_post'), WP_JSON_Server::EDITABLE | WP_JSON_Server::ACCEPT_JSON ),
  19. array( array( $this, 'delete_post'), WP_JSON_Server::DELETABLE ),
  20. );
  21.  
  22. // Add more custom routes here
  23.  
  24. return $routes;
  25. }
  26.  
  27.  
  28. function get_posts() {
  29. return(
  30. array(
  31. 'id' => 9,
  32. 'name'=> 'Member\'s Apothecary'
  33. )
  34. );
  35. }
  36.  
  37. function new_post() {
  38.  
  39. }
  40.  
  41. // ...
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement