Password Protect Subscription Levels

Hi there,

Is it possible to force people to enter an admin-defined password before gaining access to certain subscription levels?

We are trying to make completing one "subscription" (which in our use case will be an online course) a pre-requisite for another subscription.

I thought a simple way to do this would be to lock down later subscriptions with a passcode and then only give out that passcode at the end of the previous subscription.

I can't see any built-in functionality to do this, but possibly (hopefully?) doable with some simple code?

I am PHP novice but I can paste it in if somebody tells me what to do :wink:

Thanks

Justin

  • Mason

    Hiya Justin,

    We don't have this built into membership currently. Using the method you describe you could use our password-protect plugin to do this though:
    https://premium.wpmudev.org/project/password-protect-selected-content

    It would allow you to let folks go through the content and give the next password at the end of each course exactly as you describe.

    The membership plugin would allow folks to go through various 'levels' in a drip-feed sort of way. After 1 week a new set of content becomes available. 3 weeks later - more new content, etc. The level progressions is all based on time though, and not on completion of any task (or course in your case) so it wouldn't be as effective as the plugin above.

    Let us know how it works for ya.

    Thanks!

  • Justin

    Hey masonjames,

    Thanks for the response. I gave this some thought, and I think the problem will be that this method of password protecting content won't be ideal in terms of how we need to administer the online courses.

    It sounds like we'd need to set up a single subscription with all course weeks as different levels, with certain levels being password protected.

    However, we really need people to opt into further course as a separate subscription rather than have them bundled in together.

    I wonder is there any way to password protect a specific line on the renewal form so that just the option to register for course #2 or course #3 is password protected?

    Thanks,

    Justin

  • Jonathan

    Hey Justin,

    Here is the latest scoop
    Source: https://premium.wpmudev.org/forums/topic/private-subscriptions
    And
    Source: https://premium.wpmudev.org/forums/topic/membership-version-21-beta-1

    We're moving that way in the new betas - I've added in a few new shortcodes to allow smarter or private/hidden signup pages to be built and single "purchases" to be made

    So you will be able to use shortcodes to create your own register/buynow buttons and you could wrap those in the password plugin perhaps. Or just use the inbuilt functionality of the membership plugin and use the private/hidden subscriptions :wink:

    You'll know as much as I do after reading those posts. But I think exciting times are ahead of us with regards to the membership plugin.

    Also on a sidenote: another nice plugin is the
    https://premium.wpmudev.org/project/scheduled-content
    It allows you to lock content until a specific time. Say week one equals week one of the month.
    You can schedule's monthly / weekly or one time.
    So if it takes 2 months to complete course 1, course 2 opens at month 3.
    I don't know if it will work as all users must be going through the course at the same time, but just trying to think outside the box :wink:

    Jonathan

  • Jonathan

    Okay Justin,

    Took a bit of time but here you go...

    Level Password Protection Plugin

    1) Copy code to file

    <?php
    /*
    Plugin Name: Level Password Protection
    Description: addon for membership plugin - password protects content based on user level
    Version: 0.0.1
    Author: Jonathan Du Toit
    */
    /*Usage: [level-password levelid="2" password="secretpassword"] hidden text goes here[/level-password]  */
    
    add_shortcode('level-password', 'level_password');
    function level_password( $atts, $content = null ) {
    
    	$defaults = array(		"levelid"				=>	'',
    							"password"				=>	''
    						);
    
    		extract(shortcode_atts($defaults, $atts));
    
    	if(!empty($levelid)) {
    		//also available: current_user_on_subscription()
    		if ( current_user_on_level($levelid) ) {
    
    		//if no pass set don't protect
    		if ( !$password )
        	return $content;
    
    		//check cookie for password
    				if($_POST['password'] == $password){
       		return $content;
    		} else {
    			return '<form action="'.str_replace( '%7E', '~', $_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data"><input type="password" name="password" class="password" value="Password" onfocus="if(this.value==this.defaultValue)this.value=\'\';" onblur="if(this.value==\'\')this.value=this.defaultValue;" /><input type="submit" value="submit" name="submit" class="button" /></form>
    			';
    		}
      }
    
    }
    
    }
    
    ?>

    2) Save file as level_password_protection.php
    3) Install plugin and activate
    4) Use this shortcode example
    [level-password levelid="2" password="secretpassword"] hidden text goes here[/level-password]
    Only users who are on level 2 can see the password box. Once password is entered correctly - content is shown.

    Please note that all persons using this plugin do so at their own risk.
    In no event will I be liable for any loss or damage including without limitation, indirect or consequential loss or damage, or any loss or damage whatsoever arising from loss of data or profits arising out of, or in connection with, the use of this plugin.
    bla bla bla :wink:

    Cheers,
    Jonathan

  • Justin

    Jonathan -- many thanks for your generous help. Some points to you!

    I appreciate the tip on those two threads...it seems Barry is hard at work on some of this functionality as we speak. Very cool.

    And sincere thanks for the plugin!

    Just a few questions on how that would work....

    So basically if a user is level 2 they would see the password box, if they were level 1 (or a guest) they would just see nothing at all, is that right?

    Also just checking if this could be applied to an actual line on the subscription form (i.e., the register button for level 3, so only people on existing level 2 could see it) or just to html content on a page -- I guess there is no way to put a shortcode inside a shortcode that I can see though?

    Hope that makes sense :slight_smile:

    Many thanks again.

  • Jonathan

    @Justin,

    Yes, if you put level 2 as the levelid as in levilid=2... then only, and only level 2 users will be able to see the password box. All other levels, and guest user will see nothing, as if it never existed.

    As for the applying it to the actual subscription form. No, but when the new beta goes live, and if I understand it - you could wrap the shortcode around the purchase shortcode.

    To answer your question, can you put a shortcode inside a shortcode. YES!
    But you need to change two lines in the plugin.
    Each
    return $content;
    must be changed to
    return do_shortcode($content);

    That's it, now other shortcodes should work within this shortcode. Will post updated plugin in new thread below :slight_smile:

    Cheers,
    Jonathan

  • Jonathan

    Here is the final product :slight_smile:

    Level Password Protection Plugin

    <?php
    /*
    Plugin Name: Level Password Protection
    Description: addon for membership plugin - password protects content based on user level
    Version: 0.0.1
    Author: Jonathan Du Toit
    */
    /*Usage: [level-password levelid="2" password="secretpassword"] hidden text goes here[/level-password]  */
    
    add_shortcode('level-password', 'level_password');
    function level_password( $atts, $content = null ) {
    
    	$defaults = array(		"levelid"				=>	'',
    							"password"				=>	''
    						);
    
    		extract(shortcode_atts($defaults, $atts));
    
    	if(!empty($levelid)) {
    		//also available: current_user_on_subscription()
    		if ( current_user_on_level($levelid) ) {
    
    		//if no pass set don't protect
    		if ( !$password )
        	return do_shortcode($content); 
    
    		//check cookie for password
    				if($_POST['password'] == $password){
       		return do_shortcode($content) ;
    		} else {
    			return '<form action="'.str_replace( '%7E', '~', $_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data"><input type="password" name="password" class="password" value="Password" onfocus="if(this.value==this.defaultValue)this.value=\'\';" onblur="if(this.value==\'\')this.value=this.defaultValue;" /><input type="submit" value="submit" name="submit" class="button" /></form>
    			';
    		}
      }
    
    }
    
    }
    
    ?>

    Hope you find it useful, but please note that all persons using this plugin do so at their own risk.
    In no event will I be liable for any loss or damage including without limitation, indirect or consequential loss or damage, or any loss or damage whatsoever arising from loss of data or profits arising out of, or in connection with, the use of this plugin.
    bla bla bla :wink:

  • Jonathan

    @ masonjames, davidm,

    Really appreciate the rep points guys, thought it was time to become a community player and try for that lifetime membership :slight_smile:
    That way, we all grow together, aid each other, and code becomes something shared among a community, rather than buried on my hard drive or in my head.

    Hope to release a few add-on's that I've been working on for membership plugin down the line :wink:

    Jonathan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.