Created
October 3, 2023 15:46
-
-
Save terrylinooo/84dadaea1845a6ad978bd638d09ac1b8 to your computer and use it in GitHub Desktop.
rest
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
/** | |
* 示範 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