Hi benjudy,
Thank you for great question. Yes there is much easier, undocumented way however you would have to create a small callback function and you should have AAM Plus Package.
Step 1.
Create two page categories (e.g. Unregistered, Registered) and group your pages accordingly.
Step 2.
Switch to the Manage Default Settings (fourth tab on the User/Role panel) and go to Posts & Pages. Click Manage Access for Pages and for the Frontend REDIRECT instead of valid URL or page ID, enter valid PHP callback function. This will define redirect rule for all pages to all users and visitors on your website. All pages will inherit this rule unless overwritten for any user, role or visitor. For more info about AAM access settings inheritance check this article.
Step 3.
Create your callback function that checks if user is logged in and currently is trying to browse page in Unregistered category. If so, then redirect to the page in Registered category with the same name. Do vise versa for unregistered user.
Hopefully this is helpful.
Regards,
Vasyl
Hi Vasyl,
Thanks so much for your reply! I think it makes sense.
However, I am having trouble in step 2, when entering my PHP function in the REDIRECT to Valid URL or Page ID field. After applying this, I get an error message when I try to view a page.
It seems that whatever I add is not being interpreted as PHP code. The function I added is visible in the ‘view source’ HTML of the page.
Is there some other setting I must enable, so AAM will allow entering PHP in the REDIRECT field? Thanks!
benjudy,
It has to be a valid PHP callback function like MyClassName::myRedirectFunc or myCustomRedirect func. Do not insert any PHP code as AAM does not evaluate any PHP code.
Also note, that whatever callback function you’ve defined, it has to be loaded before WordPress call ‘init’ hook.
Regards,
Vasyl
Got it! It is working now. I was trying to make it too complicated. And as you can tell, I’m not much of a programmer. But your help was excellent, thanks so much for taking time to reply. Cheers!