GB Gated Content

Running a subscription website? Or simply want to reserve some content for certain groups of users with particular roles assigned? GB Gated Content lets you control who gets to view the entries with a custom entries loop and/or a flexible field type for you to specify the access condition and/or passcode to unlock the content.

GB Gated Content Example

GB Gated Content List of Keys

Installation

Upload the folders to the respective system/user/addons/ and themes/user/ directories and click install on the Add-Ons page.

Usage

Custom Entries Loop

Does everything {exp:channel:entries} loop does, but with 3 additional parameters for access control.

check

If the check value matches the match value, the user will be granted access to the entry. Usually you’d want to check the Single Global Variables - Member Variables. Typing check="logged_in_primary_role_id" is the same as check="{logged_in_primary_role_id}".

match

This is the value that you are matching to verify access. You can start with condition like match="!= 3|4|5". = is the default, you can also use !=, <, <=, >, >=. If you use greater or less than conditions, you can’t have pipe | to specify multiple values because only the first one will be used.

passcode

The passcode to unlock the entry.

Preview in template

If the user doesn’t have access to the entry yet, only the content in the {gb_gated_content_preview} tag pairs will be parsed. You can create a form to unlock the entry using {gb_gated_content_preview:form} which will take the Passcode (if defined) and build a form. Some allowed parameters to help you style the form:

  • form:attrs
  • passcode:attrs
  • submit:attrs
  • submit:text (what the submit button should say)
  • success_url
  • fail_url

Template code not allowed in the parameters.

Once the form is submitted with the correct passcode, the add-on will insert the unlocked content to the cookie. If the user has cookie turned off, their access to the entry will be saved in the EE Cache for 1 day labelled with their IP address.

{exp:gb_gated_content:entries channel="blog" check="{logged_in_primary_role_id}" match="5|6" passcode="n0tAs@f3Pa$SvvOrD" limit="5"}
    <h2>{title}</h2>
    <p>{body}</p>
    {gb_gated_content_preview}
        <p>This content is for subscribers only. Please <a href="/signup">sign up here</a> and start learning how to code like a pro!</p>
        <p>If you have the access key, enter below to start reading.</p>
        {gb_gated_content_preview:form form:id="unlockForm" passcode:class="form-control" submit:class="btn btn-submit" submit:text="Unlock Content" fail_url="/test/gated_content_entries?unlock=failed"}
    {/gb_gated_content_preview}
{/exp:gb_gated_content:entries}

Field Type

With this field type, you can define specific access rules for each entry. Simply create the field type GB Gated Content and add it to the channel. IMPORTANT one GB Gated Content field per channel for now. I’m working on allowing multiple keys to be generated per entry but it’s not fully supported yet. Also, the short name gb_gated_content_preview is reserved for the custom entries loop.

Fields

Check

In the field type, you can choose the following Single Global Variables:

  • Email logged_in_email
  • Primary Role ID logged_in_primary_role_id
  • Primary Role Name logged_in_primary_role_name
  • All Role IDs logged_in_role_ids (custom built, spit out all the roles the logged in user is assigned to)
  • IP Address logged_in_ip_address
  • Member ID logged_in_member_id
  • Screen Name logged_in_screen_name
  • Total Comments logged_in_total_comments
  • Total Entries logged_in_total_entries
  • Total Forum Posts logged_in_total_forum_posts
  • Total Forum Replies logged_in_total_forum_replies
  • Total Forum Topics logged_in_total_forum_topics
  • Username logged_in_username

If you have any custom member fields, they will appear like this:

  • Member Field: custom_member_field

If you have GB IP to Nation installed, you’ll unlock the following tags:

  • IP: Country
  • IP: Country Code
  • IP: Phone Code
  • IP: Currency
  • IP: Currency Code
  • IP: Timezone
  • IP: Timezone Code
  • IP: Is Daylight Saving (bool)
Match

The value/condition is checked against Check to allow access. For example, if you only want people with Role ID 5 and 6 to read this entry, you will select All Role IDs {logged_in_role_ids} in Check and 5|6 in Match.

Passcode

If the Check/Match fails, and you still want to allow access to some folks, you can set up a passcode to unlock the content.

Preview

This is where you can write a “please subscribe to read this material” message. Of course, you can always have a generic message in the template but this is for entry specific preview text.

Enabled

Template usage

You can use the following tags to create the logic for how you want to allow access.

my_gb_gated_content_field:unlocked

Returns true/false if the user should have access to this entry. It depends on the Check/Match test, or if the user had previously unlocked the content.

my_gb_gated_content_field:check

Returns the check value

my_gb_gated_content_field:match

Returns the match value

my_gb_gated_content_field:passcode

Returns the passcode value… you probably don’t want to do this unless in if conditions

my_gb_gated_content_field:preview

Returns the preview content

my_gb_gated_content_field:form

Returns a form that has a password field to unlock the content. You can pass in some parameters to help style the form like {my_gb_gated_content_field:form form:id="myForm" passcode:class="form-control" submit:class="btn btn-submit" submit:text="Unlock Content"}.

Example
{exp:channel:entries channel="blog" limit="1"}
    {if my_gb_gated_content_field:unlocked}
        <h2>{title}</h2>
        <p>{body}</p>
        <hr>
    {if:else}
        <div class="preview">
            {my_gb_gated_content_field:preview}
        </div>
        {my_gb_gated_content_field:form form:id="myForm" passcode:class="form-control" submit:class="btn btn-submit" submit:text="Unlock Content"}
    {/if}
{/exp:channel:entries}

Notes

  • Super Admin can see everything
  • One GB Gated Content field per channel
  • Cookie information: we use a cookie exp_gb_gated_content_unlocked to keep track of all the entries unlocked

Changelog

1.0.2

Fixed

  • New entry bug

1.0.1

Fixed

  • Add-on service bug

1.0.0

  • Hello World!

Support

Email Gilbert at gilbert.lin.web@gmail.com

Support continuous development for this add-on

There will be a 30% fee of the original price per year to continue getting the most up to date version of this add-on.

License

Updated: February 6th, 2021

PERMITTED USE

ONE LICENSE GRANTS THE RIGHT TO PERFORM ONE INSTALLATION OF THE SOFTWARE. EACH ADDITIONAL INSTALLATION OF THE SOFTWARE REQUIRES AN ADDITIONAL PURCHASED LICENSE. FOR FREE SOFTWARE, NO PURCHASE IS NECESSARY, BUT THIS LICENSE STILL APPLIES.

RESTRICTIONS

UNLESS YOU HAVE BEEN GRANTED PRIOR, WRITTEN CONSENT FROM GILBERT LIN, YOU MAY NOT:

  • REPRODUCE, DISTRIBUTE, OR TRANSFER THE SOFTWARE, OR PORTIONS THEREOF, TO ANY THIRD PARTY.
  • SELL, RENT, LEASE, ASSIGN, OR SUBLET THE SOFTWARE OR PORTIONS THEREOF.
  • GRANT RIGHTS TO ANY OTHER PERSON.
  • USE THE SOFTWARE IN VIOLATION OF ANY CANADA OR INTERNATIONAL LAW OR REGULATION.

DISPLAY OF COPYRIGHT NOTICES

ALL COPYRIGHT AND PROPRIETARY NOTICES AND LOGOS IN THE CONTROL PANEL AND WITHIN THE SOFTWARE FILES MUST REMAIN INTACT.

SOFTWARE MODIFICATION

YOU MAY ALTER, MODIFY, OR EXTEND THE SOFTWARE FOR YOUR OWN USE, OR COMMISSION A THIRD-PARTY TO PERFORM MODIFICATIONS FOR YOU, BUT YOU MAY NOT RESELL, REDISTRIBUTE OR TRANSFER THE MODIFIED OR DERIVATIVE VERSION WITHOUT PRIOR WRITTEN CONSENT FROM GILBERT LIN. THE MODIFICATIONS BY YOU OR THE COMMISSIONED THIRD-PARTY MAY NOT INFRINGE AND/OR VIOLATE GILBERT LIN’S LICENSE RIGHTS. COMPONENTS FROM THE SOFTWARE MAY NOT BE EXTRACTED AND USED IN OTHER PROGRAMS WITHOUT PRIOR WRITTEN CONSENT FROM GILBERT LIN.

DISCLAIMER OF WARRANTY

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF QUALITY, PERFORMANCE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. FURTHER, GILBERT LIN DOES NOT WARRANT THAT THE SOFTWARE OR ANY RELATED SERVICE WILL ALWAYS BE AVAILABLE.

LIMITATIONS OF LIABILITY

YOU ASSUME ALL RISK ASSOCIATED WITH THE INSTALLATION AND USE OF THE SOFTWARE. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS OF THE SOFTWARE BE LIABLE FOR CLAIMS, DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE. LICENSE HOLDERS ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USE AND ASSUME ALL RISKS ASSOCIATED WITH ITS USE, INCLUDING BUT NOT LIMITED TO THE RISKS OF PROGRAM ERRORS, DAMAGE TO EQUIPMENT, LOSS OF DATA OR SOFTWARE PROGRAMS, OR UNAVAILABILITY OR INTERRUPTION OF OPERATIONS.

LinkedIn pictogram Instagram pictogram