Before today, I had the SP Global Settings set to redirect users below a certain level to the front page of our forum (“/community”) and it worked great. It only allow back-end admin access to Admins, anyone else logging in or out went to the forum.
Today we have opened up the back-end access to Editors, Authors and Contributors as well so that we can start adding more content from non-staff writers, and I have things working well EXCEPT that when users now logout, they STILL get redirected to the forum page instead of staying on the page they were on, which is what we want (I created a logout link instead of using wp_loginout() because we needed to add extra links if they were logged in or if they were logged out).
I’ve double-checked that I don’t have any URL set in the Global Settings for Simple:Press where it says “URL to redirect to if blocking admin access:” – that box is blank.
I regenerated the SP permalinks and the WP permalinks but it still redirects anyone on logout to the forum.
Here’s what I added in my functions to show the logout link if they are logged in:
`if ( is_user_logged_in() ) {
$userprofilelink = get_edit_user_link();
$pageURL = ‘http://’;
$pageURL .= $_SERVER[‘HTTP_HOST’];
$pageURL .= $_SERVER[‘REQUEST_URI’];
echo ‘<li><a href=”‘;
echo wp_logout_url($pageURL);
echo ‘”>Logout</a>’;
echo ‘<li><a href=”‘;
echo $userprofilelink;
echo ‘”>Edit Profile</a></li>’;
} `
So when you hover over the logout link it looks correct – it calls the current page – but when you click on it, it changes the url from the current page to the community.
Also, I don’t know if this is relevant, but when we first started using SP I didn’t know it would redirect certain users so I had a function in my functions.php to do the same thing, once I learned that SP would do this, I removed that function entirely…..is it possible that my WP installation is somehow storing an old wp_redirect command?
This is what I had, and my understanding is that the default type of redirect is 302, not 301 so it should have only been a temporary change anyway…..
`function restrict_admin()
{
if ( ! current_user_can( ‘manage_users’ ) && ‘/wp-admin/admin-ajax.php’ != $_SERVER[‘PHP_SELF’] ) {
wp_redirect( site_url() . ‘/community’ );
exit;
}
}
add_action( ‘admin_init’, ‘restrict_admin’, 1 );`
Any suggestions would be greatly appreciated – I feel like I must be overlooking something simple.