Limiting Access To Plugin Usage

In a pre-sales question, I asked if it was possible for Pro Sites to remove access to a plugin if a user upgraded to a higher level. The definitive answer I received was "Yes!"

As I look at the plugin dashboard, I can see where the plugin minimum level is specified, but I do not see anywhere that I can limit the maximum level, or remove access for specific levels.

Can someone please inform me where this setting can be made?

Thank you,
Kirk

  • Adam Czajczyk

    Hey Kirk!

    In a pre-sales question, I asked if it was possible for Pro Sites to remove access to a plugin if a user upgraded to a higher level. The definitive answer I received was "Yes!"

    It seems that one of my colleagues to whom you're speaking might have mistakenly not-notice the "higher level" part. There's no feature like this as Pro Sites allows you only to assign "minimum" level that's allowed to use the plugin. So, after upgrade the site admin is able to use all the plugins/themes for his current level + all assigned to the lower level.

    I sincerely apologize for this mistake and I'm calling a developer here for help so we could craft a solution/fix for you!

    Please keep an eye on this thread for further information and updates and I'm sure we can solve this asap.

    Kind regards,
    Adam

  • Kirk Ward

    LOL Mike,

    It were do be two of them that gave a wrong turn on that. One who answered, and one who emailed as "Working beside" the other.

    I do hope you can craft a solution. I think it will open up some interesting possibilities, such as a plugin upgrade without the distraction of the lower level plugin. I am first thinking of two 'webinar' plugins. One of higher quality than the second. My market is keen for pre-recorded webinars, and the higher quality plugin has features I want to charge for, whilst the lower quality is a starter platform.

    Kirk

    Kirk

  • Ash

    Hello @Kirk Ward

    I hope you are well today.

    I have written a script for you. Just for example, you don't want to give access of abc plugin in level 5 though it is accessible from below level 5. In the following code, in first two lines you need to define the level and plugin name.

    define( 'SPECIFIED_PLUGIN', 'events-and-bookings/events-and-bookings.php' );
    define( 'SPECIFIED_LEVEL', 4 );
    
    add_action( 'psts_upgrade', 'deactivate_on_level', 99, 3 );
    add_action( 'psts_downgrade', 'deactivate_on_level', 99, 3 );
    function deactivate_on_level( $blog_id, $new_level, $old_level ) {
        require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
        global $psts;
    
        if( $new_level == SPECIFIED_LEVEL ){
            switch_to_blog( $blog_id );
            deactivate_plugins( array( SPECIFIED_PLUGIN ), true );
            restore_current_blog();
        }
    }
    
    add_filter( 'plugin_action_links', 'action_links', 10, 4 );
    function action_links( $action_links, $plugin_file, $plugin_data, $context ) {
        global $psts, $blog_id;
    
        if ( is_super_admin() ) {
                return $action_links;
        }
    
        $level = $psts->get_level( $blog_id );
        if( $level == SPECIFIED_LEVEL && $plugin_file == SPECIFIED_PLUGIN ){
            unset( $action_links['activate'] );
        }
    
        return $action_links;
    }
    
    add_action( "admin_footer", 'remove_checks' );
    function remove_checks() {
        global $psts, $blog_id;
        $level = $psts->get_level( $blog_id );
        if( $level == SPECIFIED_LEVEL )
            echo "<script type='text/javascript'>jQuery(\"input:checkbox[value='" . esc_attr( SPECIFIED_PLUGIN ) . "']\").remove();</script>\n";
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • Kirk Ward

    As far as I am able to read PHP Ash, this looks great. I will test it on the morrow.

    As an additional note, would you please pass on to all the tech supporter guru's folkses, that the support I have received in the past couple of days is one helluva lot better than it was some few years ago when I became very frustrated with WPMU. I do hope they keep up the pattern or rapid response. I can live with accurate daily responses, but I never expected to get responses within a few hours. It is a nice feeling. I do hope they will keep that up.

    Cheers and cheerios Ash,
    Kirk

  • Adam Czajczyk

    Hey Kirk!

    As far as I am able to read PHP Ash, this looks great. I will test it on the morrow.

    I think you may want to test even better solution. @Ashok has expanded his code a bit since he posted it here and I had a chance to test it yesterday. If you'd like to try it, here's what to do:

    1. On your dashboard's

    "Pro Sites" -> "Modules" page

    disable the "Premium Plugins" module

    2. download the attached .zip archive and unpack it
    3. access your WP install via FTP
    4. upload files as follows:

    - "plugins-loader.php" to /wp-content/plugins/pro-sites/pro-sites-files/
    - "premium-plugins-manager.php" to /wp-content/plulgins/pro-sites/pro-sites-files/modules/

    5. Go to your dashboard's

    "Pro Sites" -> "Modules" page

    and enable the "Premium Pluigins Manager" module

    It's important to disable the original "Premium Plugins" first as both modules cannot work alongside.

    The new module allows you to select a Pro Sites level and explicitly assign selected plugins to it so there's no "inheritance" at all. Plugins assigned will be made available only to this selected level and no site of higher or lower lever will be able to access them.

    Please note though that I'm sharing this with you as a "beta"/"test" version. It worked great during our tests but in case you encounter any issues, please let us know.

    Have a nice day!
    Adam

  • Kirk Ward

    Hello Ash,

    Thank you for this manager. Looks like it does exactly what is wanted.

    One suggestion, as the Premium Plugins module and the Premium Plugins Manager module cannot work simultaneously, I would modify the Pro sites Manager (?) so that a "Radio Button" option allowed only one to be selected. Might prevent errors in future releases and allow users to select the scheme that fits their needs most appropriately.

    Will play with it more, but activation and setup went smoothly.

    Cheers,
    Kirk

  • Adam Czajczyk

    Hey Kirk!

    Thank you for this manager. Looks like it does exactly what is wanted.

    That's good to hear! I hope it will serve you well!

    One suggestion, as the Premium Plugins module and the Premium Plugins Manager module cannot work simultaneously, I would modify the Pro sites Manager (?) so that a "Radio Button" option allowed only one to be selected. Might prevent errors in future releases and allow users to select the scheme that fits their needs most appropriately.

    As far as I'm aware @Ashok has taken it into account. This is still "work in progress" so please treat it as a "beta" version rather than a final release of a new feature. That said, all the insights and feedback are of great value to ass, so thank you for this!

    Cheers,
    Adam

  • Kirk Ward

    Ash,

    Suggestion for this module.

    I'd like to see columns of checkboxes, with one column for each level, and one row for each plugin (as it is now) so I could visualize my plugin access at each level. I presume there is a chance of running out of screen space if many columns are required because some user (such as me) has created a multitude of levels. This could be ameliorated by having the text description of the plugin going multi-row in a table cell that keeps the description onscreen as much as possible.

    I think the ability to compare plugin availability would enhance the managers usage.

    P.S. - So far, I like the way it works, except I am having trouble making sure the access mixture stays consistent with my levels. Especially if I rename the levels using the drag and drop feature on the edit levels page, which appears to only drag the title, and not the levels access. Is that correct?

  • Kirk Ward

    Another bright idea for another day.

    It might be helpful for some folks (namely 73 y.o. geezers trying to compete in a young folks world) if there were a way to add a descriptor that showed up next to the name of the premium plugins so that when the user was looking at assigning the plugin to a particular level, they might have some help in remembering the purpose of making the plugin available.

    For example, if I were to make a membership plugin available, such as Paid Membership Pro or Membership 2, so that course material could be drip released to a particular sites subscribers or customers, I could label it as something like Student Enrollment System.

  • Ash

    Hello @Kirk Ward

    Do you want something like the screenshot?

    If yes, then you can try this attached one. If not, would you please explain again?

    Especially if I rename the levels using the drag and drop feature on the edit levels page, which appears to only drag the title, and not the levels access. Is that correct?

    Well, in pro sites plugin everything is mapped using the ID. So, if you rename it's okay but if you reorder by drag and drop, then the ID will be changed. This doesn't matter what the name is, but the ID is. Like in this module, you have set some plugins for level ID 2, if you reorder or rename, these plugins is still associated to the level ID 2.

    About your last post, well, it's kinda different than the premium plugin concept, but I will add this to feature list but I can't promise you about the implementation of the feature.

    Cheers
    Ash

  • Kirk Ward

    Take a look at this cut and paste composite. The number of columns would increase as the number of level increased. The example would be the look if there were four levels (okay, I just used a slice from the same level, hopefully, you get the idea.). With the multiple columns showing, one for each level, the drop down would be removed, as it would no longer be needed.

    About your last post, well, it's kinda different than the premium plugin concept, but I will add this to feature list but I can't promise you about the implementation of the feature.

    Understand. This is for the admin, to maintain clarity of purpose. Only other use I can think of is if the descriptions might filter over to the features page. Not a pressing need.

  • Kirk Ward

    I tried the first one (without the _2) and the errors appear to be gone.

    Dearly Beloved is forcing me to sit at her knee and spend time with her as if I were here naked slave. Only, it would scare both of us if I were naked, so I'm going back to the TV set with her.

    Anyhoo, error seems to be gone with the first one. I'll try _2 in a bit to see what changes transpire. If no errors on either, which do you want me to stick with?

  • Adam Czajczyk

    Hey Kirk,

    Thanks for this information!

    It seems like you're help here is truly priceless as we've me and Ash we have both tested this and were not able to rise that error :slight_smile: That said, let me include @Ashok here so he'll be notified of this. I've also messaged him via our internal chat so I'm sure he'll come up with a new solution once he get's back on line!

    Cheers,
    Adam

  • Kirk Ward

    Do not recognize any errors. Yet, LOL.

    Dearly Beloved has me into the Honey Do list again (building a bed, fixing the bathroom sink, patching the hole in the fiberglass tub, re-hanging the kids gate in the loft, scrubbing the front porch, etc.), then tomorrow? LOL Every weekend. I keep hoping she'll get tired of me piddling and hire someone.

    Anyhoo, bottom line, it may be Monday before I can get into real testing.

    Cheerios and serendipitous felicitations,
    Kirk

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.