I have a custom endpoint which looks like this:
add_action( 'rest_api_init', function () {
register_rest_route( 't2mchat/v2', '/get_curr_user_lang', array(
'methods' => 'GET',
'callback' => 'get_user_lang'
));
});
I was able to call the callback function "get_user_lang" when it wasn't a class based method. But once I converted it to a class based method, I wasn't able to call it.
My class looks like this:
<?php
namespace T2mchat\TokenHandler;
class TokenHandler {
function get_user_lang() {
return "client_langs";
}
}
?>
and my new endpoint looks like this:
$t2m = new T2mchat\TokenHandler\TokenHandler();
add_action( 'rest_api_init', function () {
register_rest_route( 't2mchat/v2', '/get_curr_user_lang', array(
'methods' => 'GET',
'callback' => array($t2m, 'get_user_lang')
));
});
Anyone have any idea on how to call a class based method in WordPress Rest API custom endpoints?