Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

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 Cheerleader & Troubleshooter Munich Moderator

    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.


    hgtonightK17Rangerine
  • 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.

    R_Jhgtonight
  • 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?

    • 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

    hgtonightRangerine
  • @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 Cheerleader & Troubleshooter Munich Moderator

    @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


    hgtonightRangerine
Sign In or Register to comment.