better_messages_api_request_config
REQUIREMENTS
To be able to implement this guide, you need to learn how to use JS snippets at your website.
One of guides: https://dev.to/david_woolf/how-to-get-started-with-wordpress-hooks-in-javascript-400o
Compatibility
This filter compatible with Better Messages 2.4.21 or higher
The better_messages_api_request_config hook is a JavaScript filter that allows you to modify the configuration of the API request made by the Better Messages plugin.
This hook is invoked with the current configuration object as an argument.
The configuration object contains axios request configuration options. You can modify the configuration object and return it to change the request configuration.
wp.hooks.addFilter('better_messages_api_request_config', 'hook_override', function( config ){
var urlParams = new URLSearchParams(window.location.search);
var token = urlParams.get('token');
if (token) {
if ( ! config.baseURL.includes('rest_route=') ) {
let url = config.url;
if( url.includes('?') ){
url += '&app_token=' + token
} else {
url += '?app_token=' + token
}
config.url = url;
} else {
let url = config.url.replace(/\?/g, '&');
url += '&app_token=' + token
config.url = url;
}
}
return config;
})