Skip to main content
fixed typo while copy pasting code
Source Link
realtebo
  • 267
  • 2
  • 15

Context: a custom plugin

My goal: i need to redirect user to another site after a logout

I wrote these

error_log("test of error logging");

add_action('wp_logout', function () {
  error_log("do_action wp_logout_called");
});

add_action('wp_logout', auto_redirect_user_after_logoutfunction()
  {
    wp_redirect('https://www.google.it');
    exit();
  };

In the error_log i can see test of error logging, so plugin is loaded and error logging works

But

  1. I never see do_action wp_logout_called, never logged at all
  2. The redirect is not working (the user returns to wordpress, no error, no redirect)

What am I doing wrong?

Edit 1 - More trial

I tried a manual logut using

http://www.domain.ext/wp-login.php?action=logout&redirect_to=https%3A%2F%2Fwww.google.it&_wpnonce=a7b9f2e2b0

Esit: logout works, but i'm redirected to home page.

Context: a custom plugin

My goal: i need to redirect user to another site after a logout

I wrote these

error_log("test of error logging");

add_action('wp_logout', function () {
  error_log("do_action wp_logout_called");
});

add_action('wp_logout', auto_redirect_user_after_logout()
  {
    wp_redirect('https://www.google.it');
    exit();
  };

In the error_log i can see test of error logging, so plugin is loaded and error logging works

But

  1. I never see do_action wp_logout_called, never logged at all
  2. The redirect is not working (the user returns to wordpress, no error, no redirect)

What am I doing wrong?

Context: a custom plugin

My goal: i need to redirect user to another site after a logout

I wrote these

error_log("test of error logging");

add_action('wp_logout', function () {
  error_log("do_action wp_logout_called");
});

add_action('wp_logout', function()
  {
    wp_redirect('https://www.google.it');
    exit();
  };

In the error_log i can see test of error logging, so plugin is loaded and error logging works

But

  1. I never see do_action wp_logout_called, never logged at all
  2. The redirect is not working (the user returns to wordpress, no error, no redirect)

What am I doing wrong?

Edit 1 - More trial

I tried a manual logut using

http://www.domain.ext/wp-login.php?action=logout&redirect_to=https%3A%2F%2Fwww.google.it&_wpnonce=a7b9f2e2b0

Esit: logout works, but i'm redirected to home page.

Source Link
realtebo
  • 267
  • 2
  • 15

wp_logout function not executed

Context: a custom plugin

My goal: i need to redirect user to another site after a logout

I wrote these

error_log("test of error logging");

add_action('wp_logout', function () {
  error_log("do_action wp_logout_called");
});

add_action('wp_logout', auto_redirect_user_after_logout()
  {
    wp_redirect('https://www.google.it');
    exit();
  };

In the error_log i can see test of error logging, so plugin is loaded and error logging works

But

  1. I never see do_action wp_logout_called, never logged at all
  2. The redirect is not working (the user returns to wordpress, no error, no redirect)

What am I doing wrong?