Skip to content

Instantly share code, notes, and snippets.

@terrylinooo
Created October 3, 2023 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrylinooo/84dadaea1845a6ad978bd638d09ac1b8 to your computer and use it in GitHub Desktop.
Save terrylinooo/84dadaea1845a6ad978bd638d09ac1b8 to your computer and use it in GitHub Desktop.
rest
/**
* 示範 REST API 回傳
*
* @return WP_REST_Response
*/
function ironman_api_say_hello() {
$data = array(
'data' => '這是鐵人賽的範例唷!',
);
return new WP_REST_Response( $data, 200 );
}
/**
* 示範註冊客製化 REST API
*
* @return void
*/
function ironman_rest_init() {
$namespace = 'ironman/v1';
register_rest_route(
$namespace,
'/say_hello/',
array(
'methods' => 'GET',
'callback' => 'ironman_api_say_hello',
)
);
}
add_action( 'rest_api_init', 'ironman_rest_init' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment