Support Forum
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...
Visit Cruise Talk Central and Mr Papa's World
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.
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...
Visit Cruise Talk Central and Mr Papa's World
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!
You are welcome.. Glad to help. Thanks for the update.
Visit Cruise Talk Central and Mr Papa's World
1 Guest(s)