我想举一个例子来说明马克·卡普伦的答案。您可以注册一个端点来使用register\\u rest\\u路由处理http post请求,如下所示:-
/** first create a function for processing your request*/
function process_my_request(WP_REST_Request $request){
$request_body = $request->get_body_params();
if(update_post_meta( $request_body[\'post_id\'], \'post_data\', $request_body )){
$response = new WP_REST_Response(array(\'message\'=>\'Successful\'));
$response->set_status(200);
return $response;
}
else{
return new WP_Error(\'invalid_request\', \'Something went wrong\', array(\'status\'=>403));
}
}
/** then create a register route callback function */
function register_my_route(){
register_rest_route(\'myplugin/v1\', \'/myroute\', array(
\'methods\'=>\'POST\',
\'callback\'=>\'process_my_request\'
));
}
add_action(\'rest_api_init\', \'register_my_route\');
完成后,现在可以将请求发布到以下路径
site_url(\'wp-json/myplugin/v1/myroute\');