In looking in to this further, I’ve found that the plugin redirects just fine, as long as you’re not using custom permalinks or custom page templates. But what’s the fun in that?
The code pasted above changes the condition and hook that call the function but, as noted, breaks when custom templates are used. In looking in to the actual ‘redirect’ function that’s being called, I found that permalinks were causing the break. I’m not sure if the plugin developer built something in to deal with permalinks or just forgot but the function was looking for variables that just don’t exist under custom permalinks. Rather than try to totally re-engineer the code, I simply grabbed the variables that did exist (at least for my permalinks) and swapped them in.
So here’s my fix:
Do NOT swap in the code pasted above to user-access-manager.php; leave that file untouched.
Instead, go to UserAccessManager.class.php and find ‘public function redirect’. There you’ll find a multi-conditional statement that determines whether the user is attempting to access a post, a page or category archive. My code is pasted below, commenting out the original lines and inserting the lines needed. Again, these new lines worked for my permalink structure (postname/postid); not sure if they’ll work for others.
if (isset($pageParams->query_vars['p'])) {
$object = get_post($pageParams->query_vars['p']);
$objectType = $object->post_type;
$objectId = $object->ID;
//} elseif (isset($pageParams->query_vars['page_id'])) { // sfc: for use with no permalinks
} elseif (isset($pageParams->query_vars['pagename'])) {
//$object = get_post($pageParams->query_vars['page_id']); // sfc: for use with no permalinks
$object = get_page_by_path($pageParams->query_vars['pagename']);
$objectType = $object->post_type;
$objectId = $object->ID;
//} elseif (isset($pageParams->query_vars['cat_id'])) { // sfc: for use with no permalinks
} elseif (isset($pageParams->query_vars['category_name'])) {
//$object = get_category($pageParams->query_vars['cat_id']); // sfc: for use with no permalinks
$object = get_category_by_slug($pageParams->query_vars['category_name']);
$objectType = 'category';
$objectId = $object->term_id;
}
Hope this helps somebody. Better yet, I hope this helps the developer. I really like this plug in and hope to see it supported. I also use a similar plugin called Role Scoper but find that, while powerful, it’s also very complicated. I really like the straightforward nature of User Access Manager for those sites that just need some simple access management.