Logout redirect doesn't work when header 'logout' button is used

Hi There,
Problem I have with Logout redirect is that working only when user logout form the top bar. I use WPMUDev Social theme https://premium.wpmudev.org/project/buddypress-social-theme/
which have user name and logout button at the header. When I click this button, logout just return me to homepage. But if I click logout button at the WP black bar logout redirect will work. Now I intend to hide bar and keep only logout button at the top of header.
- If there a difference in logout code here?
- Shouldn't both work the same?
- Can you please advise if I need to change logout code on this button?
Maybe if developer (is it Vladislav? :grinning: give me code that I can place on this logout button and it will work. I guess it should not be too hard, as function is very simple, right - just log out :slight_smile:
Cheers,
Dean

  • Vladislav
    • Dead Eye Dev

    Hello,

    Here's the nature of the issue - the redirection in the theme comes with a "redirect_to" parameter, which is respected by the plugin. However, the latest plugin release (v1.1, just released) allows forced redirection mode, that will disregard this parameter. In this light, there are two possible solutions:

    a) Upgrade to latest plugin release and add "LOGOUT_REDIRECT_FORCED" define to your wp-config.php like so:

    define('LOGOUT_REDIRECT_FORCED', true, true);

    ... or:

    b) edit the bp-social/lib/templates/wp-template/top-bar.php and change this line:

    <li id="li-user"><?php _e('Welcome back', TEMPLATE_DOMAIN); ?>, <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><strong><?php echo $user_identity; ?></strong></a> / <?php $mywp_version = get_bloginfo('version'); if ($mywp_version >= '2.7') { ?> <a href="<?php echo wp_logout_url(get_bloginfo('url')); ?>"><?php _e('Log out', TEMPLATE_DOMAIN); ?></a> <?php } else { ?> <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="<?php _e('Log out of this account', TEMPLATE_DOMAIN); ?>"><?php _e('Log out', TEMPLATE_DOMAIN); ?></a> <?php } ?></li>

    to this:

    <li id="li-user"><?php _e('Welcome back', TEMPLATE_DOMAIN); ?>, <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><strong><?php echo $user_identity; ?></strong></a> / <?php $mywp_version = get_bloginfo('version'); if ($mywp_version >= '2.7') { ?> <a href="<?php echo wp_logout_url(); ?>"><?php _e('Log out', TEMPLATE_DOMAIN); ?></a> <?php } else { ?> <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="<?php _e('Log out of this account', TEMPLATE_DOMAIN); ?>"><?php _e('Log out', TEMPLATE_DOMAIN); ?></a> <?php } ?></li>

    The approach marked b) is plugin version agnostic - the logout URL in the theme will no longer have the "redirect_to" parameter, so the plugin will be able to do its thing.

  • deanl
    • Design Lord, Child of Thor

    Hi Vladislav,
    Thanks for update.
    I tried "a", just sound easier for noob :slight_smile: But after upgrade and config change, redirect worked, but to wrong page :disappointed:mysite.com/goodbuy/" target="_blank">http://mysite.com/http:disappointed:mysite.com/goodbuy/ - instead of http:disappointed:mysite.com/goodbuy/
    Obviously quick fix was that I edited my redirect url to in settings to only "goodbuy/" and it worked. But I am not sure if this was intended by plugin author, not to include the full URL. In login redirect, full URL works fine.
    Cheers, Dean

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.