I'm using WP to build a help/training portal for a commercial software product (Product X). We'd like to restrict access to this new WP site to only authenticated users of Product X as it contains sensitive information. Integrating with Product X's auth API is not a problem (I've done this before). However, all the docs/examples related to customizing WP auth seem focused on the WP admin portal, not the actual WP site. Is such a thing supported? If so, links to examples/docs would be appreciated.
-
3It's possible to redirect all non-logged in users to the login page. Then you restrict who can/can not register for the site, so I assume you'd use Product X's API to authenticate/create accounts. I guess you'd have to build some sort of single sign-on utility, so they'd sign in to Product X's site and then be auto-logged in via WordPress?– Tony DjukicApr 30, 2020 at 16:11
-
This is a basic method: peterstavrou.com/blog/website/… Also take a look at: codex.wordpress.org/Function_Reference/auth_redirect See Yahya's answer to this question: wordpress.stackexchange.com/questions/131879/…– Tony DjukicApr 30, 2020 at 16:16
-
Does this answer your question? How to redirect non-logged in users to a specific page?– cjbjApr 30, 2020 at 16:43
1 Answer
Add this to the top of your header.php file, or a file that will be loaded at the top of every page.
<?php
if(!is_user_logged_in()) {
wp_redirect('/wp-login.php');
exit;
}
?>
Someone will probably point out a reason why not to do this, but it's the first thing that came to mind.