Prosite disable/redirect backend on expiration

I am trying to disable the backend in addition to the frontend for all users , not just admins, on in a single multisite subsite for this condition:
- When they have a paid account and stop paying

Effectively, I want to disable the front and backend of a subsite for all users if the admin hasn't paid for the subsite. I have a plugin in the backend that seems to be able to be used freely even after account paid expiration (based on testing with a trial account).

I notice that there is the option to force the admin to redirect to the checkout page for what I would assume is when they login to the backend. This does not apply to all users if I understand correctly, and therefore does not disable the backend for users other then admins.

Any ways to do this?

  • Adam Czajczyk

    Hello Carmelo,

    I hope you're well today and thank you for your question!

    You can currently force redirect to checkout for admins of the page by turning on "Force redirect on Expiration" option on "Pro Sites -> Settings -> General" page. Let me however ask plugin developer whether we could easily lock entire site (front- and back-end) to become inaccessible for all its users and visitors.

    Please keep an eye on this thread and I'll let you know once I get a replay.

    Best regards,
    Adam

  • Carmelo

    Ok, I think I got it working. Took a few hours to come up with this and it works for myself. I placed it in the functions.php of my (child) theme since I'll never change the theme. (change any URLs in the script code below to match your site's appropriate urls')

    function account_not_paid() {
    	require_once(WP_PLUGIN_DIR . '/pro-sites/pro-sites.php');
    	if ( ! is_super_admin() && ( get_option( 'psts_signed_up' )  || apply_filters( 'psts_force_redirect', false ) ) ) {
    	     if (is_admin()) {
    			          $blogg_id = get_current_blog_id();
    			          wp_redirect( 'http://www.yoursite.com/yoursignuppage/?bid='.$blogg_id );
    	          unset ($blogg_id);
    			          exit;
    		     } else {
    	          wp_redirect( site_url() );
    			          exit;
    		     }
    	}
    }
    add_action('admin_init', 'account_not_paid');

    This code seems to work per subsite just fine. I've only tested it on trail accounts that were days past the trail. It will redirect the subsite admin to the purchase plan page. It will redirect all other subsite accounts that aren't admins to the homepage of the subsite, which displays the message that the 'pay to blog' module sets, which defaulty says the account is suspended until paid (I also put a logout link on this disable message). On accounts that don't need to pay anything (fully paid or permanently paid), nothing shows up, which is what we want.

    If there are any improvements or issues, let me know.

  • Carmelo

    Oops, I forgot: some people may want to add && current_user_can( 'edit_pages' ) in the above if statement if (is_admin()) { to make the if statement line look like:

    if ( is_admin() && current_user_can( 'edit_pages' )) {

    I needed it so that all non admin users didn't automatically get routed to the purchase page. You can change that 'edit_pages' capability to whatever capability you need it to be.

  • Carmelo

    Made a few changes that make sense for my purposes (I don't have a frontend of my subsites). Perhaps someone else may find this useful. Modified from edit_pages to create_sites, and a few other things.

    function account_not_paid() {
    	require_once(WP_PLUGIN_DIR . '/pro-sites/pro-sites.php');
    	if ( ! is_super_admin() && ( get_option( 'psts_signed_up' ) ) || apply_filters( 'psts_force_redirect', false ) ) {
    	     if ( current_user_can( 'create_sites' ) ) {
    			          $blogg_id = get_current_blog_id();
    			          wp_redirect( 'http://www.yoursite.com/yoursignuppage/?bid='.$blogg_id );
    			          unset ($blogg_id);
                       exit;
    		     } else {
    			          wp_redirect( site_url() );
    			          exit;
    		     }
    	}
    }
    add_action('admin_init', 'account_not_paid');

    I am open to any simpler ways to do this!

  • Milan

    Hello @hyperknightx,

    I hope you have been well today.

    I can see that you've done a good amount of work in finding solution for you. We really praise your efforts. By the way, I am wondering is this question for fun or you really mean it "I am open to any simpler ways to do this!" ? I am asking this because solution your derived is seems much granular and simplified one. I can't think much more simpler than this. So my suggestion is to you that you stick with this one for your issue.

    Please feel free to ask us further if you have something else in mind.

    Cheers,
    Milan Savaliya

  • Carmelo

    Thanks for replying. I was asking because I'm a pretty novice PHP developer, more-so I'm like a PHP tinker. So I'm really unsure if this can be done much easier.

    For example, I am not 100% sure of what is going on here in this line:
    if ( ! is_super_admin() && ( get_option( 'psts_signed_up' ) ) || apply_filters( 'psts_force_redirect', false ) ) {
    It was a guess and it just happened to work when I plugged it into the code (it was from the prosites.php file)!

    So what exactly is going on with that line?

  • Predrag Dubajic

    Hey Carmelo,

    That line is a condition that determines what needs to happen for the code wrapped below to work.

    So you have and three conditions above:
    ! is_super_admin() - Means if not super admin
    get_option( 'psts_signed_up' ) - checks for the value from psts_signed_up, so it's something like if is signed up for pro sites
    apply_filters( 'psts_force_redirect', false ) - checks psts_force_redirect value, if psts_force_redirect is false

    And then you have && which is AND in php and || which is OR.

    So to translate entire line it would be something like this:
    If (user is not super admin AND signed up for pro sites) OR (force redirect is false) THEN do below code

    Hope this makes sense and clears things up a bit

    Best regards,
    Predrag

  • Carmelo

    I see. Thanks for the explanation! So.. If I am checking to see if they are signed up or not past their account expiration, really, all I really need is to check if 'psts_force_redirect' is true.. right? (instead of if ( ! is_super_admin() && ( get_option( 'psts_signed_up' ) and psts_force_redirect false)

    I guess, even with that explaination, I'm not fully getting why it works so far.

  • Adam Czajczyk

    Hello Carmelo!

    So.. If I am checking to see if they are signed up or not past their account expiration, really, all I really need is to check if 'psts_force_redirect' is true..

    That's basically right. However, those additional checks are there to make sure that currently logged in admin is NOT a super-admin and is indeed and admin of Pro Sites site. Let me just shed some light on this

    1. "if is not super-admin"

    We need to exclude super-admin from that redirect because super-admin is automatically "admin for all". We don't want super admin to be redirected anywhere as it would lead to some unexpected issues.

    2. "that is indeed Pro Sites site"

    We can assume that the site has been expired but then has been for example turned to a "non Pro Sites site" by a super admin. I think an information that it's been expired would then stick in a database so we need to make sure that we avoid "false redirect" here.

    I hope I didn't confuse you further with this

    Best regards,
    Adam