Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
Odd problem with logout redirect
Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Jun 13, 2016 - 10:32 pm

not sure what you are trying to do on the admin side, but for front end users, you are using the hook wrong...  its a filter, not an action...

not sure about using those server globals - easily spoofed... but assuming you have what you want there, something like:

// Restrict access to back-end to Admins, Editors, & Authors only, redirects other users to whatever page they were on
function restrict_admin($redirect) { 
    if (!current_user_can('publish_posts') && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF']) {
        $pageURL = 'http://';
        $pageURL.= $_SERVER['HTTP_HOST'];
        $pageURL.= $_SERVER['REQUEST_URI'];

        $redirect = $pageURL;
    }
    return $redirect;
}
add_filter('sph_logout_redirect', 'restrict_admin');

not sure what you admin init hook was doing..not sure its needed on logout...  if you logout from wp admin, where would you want to go?  certainly not to page you were on - you wouldnt have access...  seems like the standard sp logout redirect would be fine...

but try that for users on front end...

Avatar
Patricia Miller
Member
sp_UserOfflineSmall Offline
Jun 14, 2016 - 7:03 pm

Well I tried the code above and wound up removing all the code because it just isn't working as I'd like, and now without any logout redirect code at all it still redirects logged out users to the community (forum home page).

I've checked all my SP settings (Global Settings in particular) and there is no directive to send logged out users to the forum home page - is it possible that WP is just holding onto a default redirect/logout redirect URL?

Here's what I'm trying to do:

1. For any site visitor on our Forum, logging in or out should keep them at the forum. So the current behavior is actually *correct* for forum users;

2. For WP users that are Contributors (and Authors although we have no Author level users and don't plan to), I'm trying to create a front-end system only - no back end access at all.  SO they have some custom pages that lets them pitch ideas, write posts, and update their profile - that's all they can do, and all from the front-end.  If they logout they get to stay on the page they were on, but they can't actually *do* anything (the forms that let them submit an idea or write a post or modify their profile do not show up if they aren't logged in).

3.  Only Editors and Admin users can access the back-end.

I'm not quite there with all of it yet, but the whole logout-redirect-to-forum has stumped me.....I don't want people sent there unless that's where they started.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Jun 14, 2016 - 8:58 pm

well, I took a more detailed look at what  you are doing (vice helping with hooks and php) and what you have wont work - as  you found out...  you wont be able to use the server global variables.... this is because its too late...  the logout has already taken effect and you were directed to wp-login.php...  and no you are just filtering the redirect of where you will be sent when done...

what you really want is the page that referred you there... so something like:

// Restrict access to back-end to Admins, Editors, & Authors only, redirects other users to whatever page they were on
function restrict_admin($redirect) {
    if (!current_user_can('publish_posts') && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF']) {
        $redirect = $_SERVER['HTTP_REFERER'];
    }
    return $redirect;
}
add_filter('sph_logout_redirect', 'restrict_admin');

please note, this would be to handle case #2...  case #1 should continue doing what you want.. but did not explicitly check your "IF" statement logic...

Avatar
Patricia Miller
Member
sp_UserOfflineSmall Offline
Jun 15, 2016 - 6:45 pm

Yaay!  That works perfectly.

My priorities #1 and #2 now work exactly as needed - if they are on the forum, logging in or out keeps them at the forum, and if they are on the website, logging in or out keeps them on the website.

Thank you Mr. Papa, I deeply appreciate your help!

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Jun 15, 2016 - 7:34 pm

You are welcome.. Glad to help.  Thanks for the update.

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626