I want to get user by email address. Getting issue with custom api endpoint route.
function getUserByEmail( $data ) {
$user = get_user_by( 'email', $data['email'] );
if ( empty( $user ) ) {
return null;
}
return $user;
}
add_action( 'rest_api_init', function () {
register_rest_route( 'myplugin/v1', '/updateRole/(?P<email>\d+)', array(
'methods' => 'GET',
'callback' => 'getUserByEmail',
) );
} );
Error : {"code":"rest_no_route","message":"No route was found
matching the URL and request method","data":{"status":404}}