// Redirects all pages except login, register, and profile url to the login page. // (note: the profile url is needed for password reset which is why it is excluded). /** * Use 'template_redirect' if you might need to use additional functions for * logical tests that need $post data, like is_page() * @see: https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect */ add_action( 'template_redirect', 'my_redirect_to_login' ); function my_redirect_to_login() { // Get an array of user pages with wpmem_user_pages() // @see: https://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_user_pages/ $pages = wpmem_user_pages(); // If the user is not logged in, and the current page is not in the user pages array. // @see: https://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_current_url/ if ( ! is_user_logged_in() && ! in_array( wpmem_current_url( true, false ), $pages ) ) { // Redirect the user to the login page. wpmem_redirect_to_login(); } return; }
Not sure what to do with this code?
You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.
Here are some free articles to get you started:
- Using Code Snippets from the Site
- Using a code snippets plugin
- The functions.php File
- Create a plugin file for custom functions
- Create a child theme
- Do not modify plugin files!
For "hands on" help, consider a plugin support subscription or the Pro Bundle.