Determining site Pro-Sites level using PHP

I’m building a theme for my project and I need to show/hide some parts of the template depending on whether the site is free or paying, and if paying different content depending on the level.

For example, I have found this

<?php if (psts_show_ads()) { ?>
Content here
<?php } ?>

which works perfectly fine and allows me to have some control, but I need a bit more flexibility than that.

Is there anything else besides the “show ads” that I could use? Something like

<?php global $pro_site_level;
if ($pro_site_level = 1) { ?> Content here <?php } ?>
if ($pro_site_level = 2) { ?> Content here <?php } ?>
if ($pro_site_level = 3) { ?> Content here
<?php } else { ?>
Content here
<?php } ?>

The pro_site_level here is hypothetical of course but that’s the sort of thing I’m trying to accomplish

  • Kimberly
    • Champion of Loops

    Hmm, I’ve got no specific coding solution, however you can try something like:

    <?php
    $user_id = get_current_user_id();
    if ( is_user_logged_in() ) {
    if ( $user_id == 2 ) {
    // display user_id = 2 content
    } elseif ( $user_id == 3 ) {
    // display user_id = 3 content
    } else {
    // display other user_id content
    }
    } else {
    // display content for guests
    }
    ?>

    Only substituting the ID for the Prosites ID?

    Best,

    Kimberly

  • aristath
    • Recruit

    This is my scenario:

    Suppose we have 3 levels: starter, pro, platinum and of course free.

    On FREE sites, display ads on posts. A button exists on the footer advertising the main site and another smaller button on the header.

    On “STARTER” sites, remove in-post ads. That’s doable using this code in the template:

    <?php if (psts_show_ads()) { ?>
    Ad code
    <?php } ?>

    On “PRO” sites, hide the links from the header and footer.

    On “PLATINUM” sites, provide a totally different header.

    I don’t see how the $user_id will be of any use here…

    Perhaps I didn’t understand what you wrote?

  • Kimberly
    • Champion of Loops

    My apologies, I was under the impression you were just needing to check for the site ID.

    Have you looked at the Ad Module in ProSites? It sounds like what you are looking to do is extend this capability, by creating custom ads for user levels.

    That might be the best place to look to see what you can apply code wise.

    Have you given it a look?

  • aristath
    • Recruit

    well not just ads…

    I want to be able to change dynamic content. Not HTML but PHP. So the ads feature of ProSites won’t do.

    What about something like this? Would this work?

    I have taken lines 102-118 of the pro-sites ads.php file and edited them to the below.

    I haven’t tested it yet ’cause I ‘m still dealing with my theme’s css but it should work…

    <?php
    global $wpdb, $psts;
    if ( empty( $blog_id ) ){$blog_id = $wpdb->blogid;}

    if ( is_pro_site($blog_id, $psts->1) || $this->check($blog_id) ) { ?>
    CONTENT HERE
    <?php }
    else if ( is_pro_site($blog_id, $psts->2) || $this->check($blog_id) ) { ?>
    CONTENT HERE
    <?php }
    else if ( is_pro_site($blog_id, $psts->3) || $this->check($blog_id) ) { ?>
    CONTENT HERE
    <?php } ?>

  • Kimberly
    • Champion of Loops

    Unfortunately I’m not much for coding php, I’m still very green when it comes to that :slight_frown:

    That being said, our lead developer for this plugin is out for a few weeks, so if nothing blows up and you need some additional input I can pull out my google skills, learn a bit more, and add this code into my own sandbox site to see if we can figure it out

    Looking forward to your results :slight_smile:

  • aristath
    • Recruit

    Nailed it… :slight_smile:

    The solution is this:

    <?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);
    ?>
    <?php if ($level == 1){ ?>
    Level 1 content here
    <?php } ?>
    <?php if ($level == 2) { ?>
    Level 2 content here
    <?php } ?>
    <?php if ($level == 3) { ?>
    Level 3 content here
    <?php } ?>

    You can put that in your template files and display different content depending on the pro-sites level (You can even show/hide entire sections such as a sidebar depending on the site’s level).

    This is going to be really fun…

  • Kirk Ward
    • Syntax Hero

    Sorry to be late to the party, but I had a bit of the same problem and had not seen this code here, so I spent a bit of time figuring it out. Wish I had seen it.

    Anyhoo, that is not the point of this post to the thread.

    I found it helpful to put the solution (using almost the exact same code) in a plugin and then allow Pro Sites to control the release of the content. Provides a way of releasing the content, which Pro Sites is otherwise unable to handle.

    Might be a model for an add on plugin, where content is added through Custom Post Types.and released as set in the add on admin page.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.