Skip to content

Instantly share code, notes, and snippets.

@fumikito
Last active March 25, 2016 10:26
Show Gist options
  • Save fumikito/01672919f290aa83911f to your computer and use it in GitHub Desktop.
Save fumikito/01672919f290aa83911f to your computer and use it in GitHub Desktop.
エンドポイント
<?php
//
// ここから書いていく
//
add_action( 'rest_api_init', function(){
register_rest_route( 'tweeter/v1', '/friends/(?P<user_id>[0-9]+)/?', [
[
'methods' => 'POST',
'callback' => function($params){
 $user = new WP_User($params['user_id']);
if ( ! $user->ID ) {
return new WP_Error(404, 'そんなユーザーはいないよ');
}
return new WP_REST_Response( [
'message' => 'フォローしました。',
] );
},
'args' => [
'user_id' => [
'required' => true,
'validate_callback' => function($var){
return is_numeric( $var );
}
]
],
],
[
'methods' => 'DELETE',
'callback' => function(){
},
],
] );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment