Paid Memberships Pro allows you to mark certain pages, posts, and categories as members-only. However, what if you want to lock access down to your whole site? This code snippet shows you how to do that.

Table of contents
About the Code Recipe
The code hooks into “template_redirect” which is called just before any output is sent to the browser.
The code defines $okay_pages
and adds some of the appropriate PMPro pages to the array. You can add other post ids and slugs here, e.g. to allow people to access your contact page or about page when signed out.
The code then checks if the user is logged out and if so redirects to the login page. If the user is logged in and not a member, they are redirected to the homepage.
As usual, add this code to functions.php in your active theme.
The Code Recipe
Adding the Recipe to Your Website
You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.