Restricting Posts

Block Posts by Default

Under the Options tab in the plugin admin panel, the first option is Block Posts by Default.  Turning this on will do what it says, “block all posts by default.”  Likewise, if you leave it off, all posts will be left unrestricted by default.  Whatever you have here is what we will refer to as the “default setting for posts.”  We will discuss how to override this setting at the individual article level separately.

Something that is important to note about posts is that there are many places that a post can show up.  There are theme pages, such as the home page, archive, and search, that will show either full articles or excerpts, depending on whether you define an excerpt or not.  You can define an excerpt either using the excerpt field in the post editor, or you can use what is known as the ‘more’ tag.  (Read More about The Excerpt from the WordPress® Codex)  Either of these methods will cause WP to only display a “teaser” of your content on one of these summary pages rather than full content.  In order to protect posts, WP-Members™ requires that you use an excerpt, preferably by use of the ‘more’ tag.  In this way, your specified excerpt will display to anyone on the summary pages, but a registered user must be logged in to view the full content.

Write your content and put the ‘more’ tag at the point you want to restrict the post from non-registered users.  This will create your “teaser” content to be used on summary pages and will restrict the remainder of the content unless a user is logged in.

Override the Default Setting for Posts

What if you have set the default to block all posts by default but you have some content that you would like anyone to be able to view?  In the upper right hand corner of the Post and Page editor windows, there will be a WP-Members meta box.  This will contain a checkbox allowing you to override the default setting you have for Posts (or Pages, when in the Page Editor).

For example, if you have set the plugin to block posts by default, this checkbox will allow you to unblock this individual post.  Check the box and update the post.  That’s all you need to do.

Custom Post Meta

The checkbox takes the place of the plugin’s former method of setting a custom field (post meta).  However, the information on the post meta custom field is discussed here because (a) that is what the checkbox is setting, and (b) you may need this information if you are seeking to do some custom programming that might display all free posts, or putting an icon next to posts based on blocking status.  These are things you would need to know how the meta fields are set so that you could filter accordingly.

Custom fields are used in WordPress® to add some meta-data to a post that can be used for some action, typically by a plugin or a theme.  In this case, we are specifying a custom field to override the default setting for restricting posts.

The Custom Field entry is found in the post editor below the editor window.  They are not displayed by default, so if you have not used custom fields in the past, you may need to turn this setting on.  Look to the upper right corner of the admin panel when you are in the post editor window and find a tab called Screen Options.  Open this up and check the box next to Custom Fields.

To override a specific post when posts are:

  • restricted by default, specify a custom field of unblock with a value of true or 1.
  • unrestricted by default, specify a custom field of block with a value of true or 1.

IMPORTANT: As with many things in php (the web programming language WordPress® is written in), Custom Fields are CASE SENSITIVE!  This means that Block and block are NOT the same.  You must use all lowercase for the custom fields used by WP-Members™.

In choosing your default setting, consider whether more of your content will be restricted than unrestricted or vice versa.  Set the default setting accordingly.  Then use custom fields to override any posts that do not fit the default.