Reputation: 4539
I want to do a check with JavaScript then based on condition I want to log the user out. How do I call the PHP from JS? Doing research I find lots on info on how to create a logout link, but I am trying to execute it inside JS instead.
Something like:
if(variable == 1) {
EXECUTE LOGOUT WITH NO CONFIRMATION (in PHP the function to show the link is "<?php echo wp_logout_url('/redirect/url/goes/here') ?>")
} else {
DO SOMETHING ELSE HERE;
};
Upvotes: 0
Views: 972
Reputation: 14983
Wouldn't simply setting location.href
do the trick,
as the URL would be pre-rendered with PHP?
if( variable == 1 ) {
window.location.href = '<?php echo wp_logout_url('/redirect/url/') ?>';
} else {
//DO SOMETHING ELSE HERE;
};
Upvotes: 1