Restricting specific page templates within ProSites.

Can anyone give me the basic outline of a code I could use within a theme’s page template to restrict it from being useable depending on ProSite level? For instance, someone with page creation ability tries to switch the page template they are using to one that only works with PREMIUM, and so they get a message when viewing that page live that they need to upgrade their blog in order for people to see that page. I’m familiar with creating page templates within themes, just need the specific line of code to restrict a template’s use specific to a particular ProSite level. Thanks for any help you can provide.

  • Vaughan
    • Support/SLS MockingJay

    Hi @xbladerunner,

    You could probably use something like

    if(is_pro_site() && get_level() >= 2) {
    // your code here
    }

    Should return true if level is greater than or equal to 2.

    or maybe;

    if(is_pro_site($blog_id, 2)) {
    // your code here
    }

    Which will return true only if pro_site level is 2 or below.

    Hope this helps

  • xbladerunner
    • Syntax Hero

    Thanks Vaughan,

    I’ve tried this out but am experiencing a problem with it. The “else” code is working fine, by which I mean that non premium accounts successfully receive a message that they need to upgrade to see this content when they visit the page template. BUT when they upgrade and visit the page template, they get this message: Fatal error: Call to undefined function get_level() in [with the address to my template file] Any ideas of what I may be doing wrong?

    I would swear that it was working until an update of the plugin this past week, but I could be mistaken.

  • xbladerunner
    • Syntax Hero

    Thanks Vaughan,

    It seems to me that the second code example above can’t be used, as it would prevent level 3 sites from having what level 2 sites have, which is contrary to the way the plugin is designed, where higher levels get everything lower levels have.

    Is there a way to write the first code without using the get_level function, or a way to get my page template to recognize that function?

  • aristath
    • Recruit

    Hello again @xbladerunner,

    I am using this on one of my sites:

    <?php

    global $wpdb;
    $blog_id = $wpdb->blogid;
    $sql = "SELECT level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'";
    $level = $wpdb->get_var( $sql );

    if ( $level == 1 ) {
    // Do something if level 1
    } elseif ( $level == 2 ) {
    // Do something if level 2
    } elseif ( $level == 3 ) {
    // Do something if level 3
    } else {
    // Do something if none of the above
    }

    I hope that helps!

    Take care,

    Ari.

  • Tyler Postle
    • CGO

    Hey Mathias,

    Hope you’re doing well today! I just want to note that it is better to create a new thread and reference an older one like this instead of bringing it back from the dead – only because staff that were originally on it might not still be working for us. So you will get a faster reply creating a new one :slight_smile:

    With that said, I’m not positive what you are wanting to do here. You’re wanting to display how long ago a page from a certain template was posted? I feel like I’m misunderstanding. Any further information here would be helpful.

    Cheers,

    Tyler

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.