How to Detect Site Level in PHP?

We need to detect whether a new custom post type is being created from a blog that is free, or from one that is at level N upgrade on Pro Sites, and fire respective events in any of those cases.

How can this be done?


  • Tyler Postle

    Hey Blake,

    Hope you're doing well today and thanks to your question!

    You can place something like this inside the custom post type single post template:

    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 elseif ( $level == 2 ) : ?>
        Level 2 content here
    <?php elseif ( $level == 3 ) : ?>
        Level 3 content here
    <?php else : ?>
        Free level content here
    <?php endif; ?>

    Then it will output whatever content you like depending on that level.

    How does that sound? Let us know if you need any further assistance here :slight_smile:

    All the best,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.