Replies: 0
Hi,
I have set up a rest endpoint using the following code in a custom plugin however when I try to access the parameters the process is somehow terminated and the email is never sent. I cant find anything in the error logs to indicate what is happening.
add_action( 'rest_api_init', function () {
register_rest_route( 'pp-subscribe', '/subscribe', array(
'methods' => 'POST',
'callback' => 'pp_subscribe'
));
});
function pp_subscribe( WP_REST_Request $request ){
$email = $request->get_param('email');
wp_mail( 'email@address.com', 'Subscribe Test', $email );
}
If I do the following:
add_action( 'rest_api_init', function () {
register_rest_route( 'pp-subscribe', '/subscribe', array(
'methods' => 'POST',
'callback' => 'pp_subscribe'
));
});
function pp_subscribe( WP_REST_Request $request ){
$email = print_r( $request , true );
wp_mail( 'email@address.com', 'Subscribe Test', $email );
}
I can see the parameters in the request object so they are being posted correctly.
Does anyone know why this is occurring?
Thanks.