Individual Post and Term content restriction settings

Overview

Ultimate Member allows administrators to control post and term access. You can easily customize restrictions for individual posts and terms, specifying access permissions, verification options, and actions for restricted content. Enhance security with 404 error displays and choose actions for users without access. The Individual Post and Term content restriction settings provide the ability to customize access for posts (including pages and other post types) and terms (categories, tags, and other term types).

Enable Individual Content Restriction Settings for Post and Term Types

  • For Post Type:

  1. Navigate to wp-admin > Ultimate Member > Settings > Access > Content Restriction>Enable the "Content Restriction" settings for post types.
  2. Activate this feature for a specific post type by checking the 'Content Restriction' checkbox for post types. See the image below:
  3. After enabling, Ultimate Member: Content Restriction will be added under the content in the page or post settings. Refer to the image below for an example, found at wp-admin > Post > add/edit a post.

  • For Term Type:

  1. Navigate to wp-admin > Ultimate Member > Settings > Access > Content Restriction>Enable the "Content Restriction" settings for taxonomies.
  2. Activate this feature for a specific term type by checking the 'Content Restriction' checkbox for term types. See the image below:

  3. After enabling,  Ultimate Member: Content Restriction will be added under the category or term content settings. Refer to the image below for an example, found at wp-admin > Post > Categories>add/edit a category.


Individual content restriction settings for posts and terms

  1. Restrict access to this post? / Restrict access to this term and its posts?

    This enables the admin to set restriction settings for the individual post or term.

    Note: Please note that individual post settings have the highest priority. This means when you've checked the "Restrict access to this post?" checkbox, the settings of the terms of this post are ignored. 

  2. Who can access this post? / Who can access this term and its posts?

    • Everyone – Everyone is the default state for post/term which means that everyone who visits your site will see this post. It's data, comments, etc.
    • Logged out users – If you select this option, it means that this post/term will only be visible to visitors (e.g logged out users). When someone logs into your site they will no longer see this post/term.
    • Logged in users – If you select this option, it means that this post/term will only be visible to logged-in users. Visitors and non-members will not see this block content. 
      • Select which roles can access this post/Select which roles can access this term and its posts -If you choose the 'Logged in users' option, you'll find the 'Select which roles can access this post/Select which roles can access this term and its posts' setting, displaying all roles on your site. To specify which role(s) can view the post or term, simply select the desired roles.
  3. Would you like to display a 404 page for users who do not have access to this page? / Would you like to display a 404 page for users who do not have access to this term on the term's archive page and terms' posts single pages?

    • Enabling this option is recommended. It hides the archive pages of restricted posts and terms, as well as all posts related to those terms, by excluding them from the WP Query. This is the safest and most effective method to conceal or hide posts and their comments from all requests, RSS feeds, and other site elements. Notably, this setting does not impact the restricted term archive page, as it remains hidden by default when the term is restricted (refer to the 'Restrict access to this term and its posts?' option)

    • If checked or enabled: When a post or term is restricted, it will not appear in the adjacent post links. If a user attempts to access the restricted post or term via a link it will lead to a 404 error, indicating that the page is not found. See the example below: Another example below illustrates that the blog post titled 'Discovering Hidden Gems in Nature' becomes hidden when added in a page:

    • If unchecked or disabledThe 'What happens when users without access try to view the post?' or 'What happens when users without access try to view the term's post?' settings become active, allowing you to configure the desired behavior. You can choose to either redirect the user to a specific or custom page or display the Restricted Access Message based on your configuration.

  4. What happens when users without access try to view the post? / What happens when users without access try to view the term's post?

    • There is the ability to select actions if the post/term isn't removed from the query. Make this action if the post/terms is restricted according to the conditions:
      • Show access restricted message – This option allows visitors to see a restricted message instead of the post content. When you select 'Show access restricted message,' you will encounter the 'Restricted access message type' setting. This setting enables you to choose the type of restricted message, either Global or Custom. If you choose 'Custom message,' you will then see the 'Custom restricted access message' setting, allowing you to type a custom message.

        The example below is configured to display the access restricted message with the global default message:
      • Redirect user – This means visitors will be redirected from the single post page instead of viewing it. When a user attempts to access a restricted post, they will be automatically redirected. After selecting the 'Redirect user' option, you'll encounter the 'Where should users be redirected to?' setting. Here, you can choose either the 'Login page' or opt for a 'Custom URL' redirect. If 'Custom URL' is selected, the 'Redirect URL' setting will appear, allowing you to specify the URL where the visitor will be redirected.

        The example below is configured to redirect user to a login page:

Additional Settings if verified extension or plugin is activated:

  1. Lock content to verified accounts only?#

  2. It is possible to show the content only for verified users if the Verified Users extension is installed.

Workarounds

By default, the restricted post if isn't hidden in the query has a pre-defined restricted data array.

  • $post->post_title - replace by the "Restricted Access Post Title" setting value.
  • $post->post_content - replace by the "Restricted Access Message" setting value. (Custom individual for post or term. Or a global restricted message from Ultimate Member > Settings > Access tab)
  • $post->post_excerpt - replace by empty string to avoid displaying restricted content in the archive.

If you need to customize the WP_Post object of the restricted post. Please use the sample from this Gist.