Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Premium Content Plugin

I am looking at the PremHide plugin and am looking to make one modification to the plugin that I think would be useful for others as well. Currently the PremHide plugin makes content behind the 'prem' tags only visible to logged in members.

I want to extend that and make it visible to logged in members with premium roles. Here is the code for the PremHide plugin that checks if a user is logged on and grants viewership to contents behind 'prem' tags.

if (($Session->IsValid())) { $pattern = '#\[.?prem\]#si'; $context = preg_replace($pattern, "", $body);

I want to add an && statement that also checks if the current user session has premium roles.

Comments

  • R_JR_J Admin

    In vanilla you grant access based on permissions and you can assign permissions to roles.

    Creating a new permission is easy: simply add a 'RegisterPermissions' entry to your plugin info and you can use that with Gdn::session()->checkPermission to see if the current user has that permission.

    Do a full text search for finding examples.

  • edited May 2016

    @R_J Thanks! I got it to work as I wanted.

    For those reading and still lost, here is how it works:

    • You give your plugin a placeholder in the roles & permissions section of the dashboard by inserting the following code into your plugin php file: 'RegisterPermissions' => array('Plugins.Premium.View'),
      The options are View, Delete, Edit, Notify, etc. (you'll see them in the roles & permission page)

    • Then you check if the user has the permissions with this bit of code: (CheckPermission('Plugins.Premium.View')) which returns a true or false depending if the user has the permissions listed.

  • I have two things now that I want to add to this plugin:

    • The ability to user either forward or backward slash to close out the private tags. Currently only "/" works.
    • An option in the paragraph drop-down menu to allow user to just click the "premium" button from the list which outputs the pair of tags.

    I'll try to figure it out. Once I do, is there a way I can contribute to this plugin?

  • BleistivtBleistivt Moderator
    • The ability to user either forward or backward slash to close out the private tags. Currently only "/" works.

    Modify the regex like this: '#\[prem\](.*?)\[[\/\\]prem\]#si'

    • An option in the paragraph drop-down menu to allow user to just click the "premium" button from the list which outputs the pair of tags.

    This is how you add a button to the advanced editor:

    public function editorPlugin_initEditorToolbar_handler($Sender) {
        echo '<span class="editor-action icon editor-action-premhide premhide-icon"></span>';
    }
    

    You will also need to write some javascript to execute the insertion when the button is clicked.

    I'll try to figure it out. Once I do, is there a way I can contribute to this plugin?

    https://github.com/adrianspeyer/VanExtend/tree/master/Plugins/PremHide

  • @Bleistivt Thanks. I'll look into the last bit on execution of the button insertion.

    I've just now created a Github. I don't know how to contribute.

  • R_JR_J Admin

    @Rangerine said:
    I've just now created a Github. I don't know how to contribute.

    https://vanillaforums.org/discussion/26822/a-git-github-primer

Sign In or Register to comment.