how to show wp admin bar on frontend of only free accounts?

Hello this might be a simple request for you guys.

Basically i am looking in showing the wp admin bar on the frontend of sites that have the free plan. This way we could create a little more awareness to our network.

Thanks in avance.

  • Tyler Postle

    Hey rcbiili,

    I created a little mu-plugin that do what you're wanting here :slight_smile:

    Just unzip the attached folder and upload the remove-admin-bar-free.php file to your /wp-content/mu-plugins folder.

    The inside is this:

    <?php
    
    add_action( 'init', 'remove_admin_bar' );
    
    function remove_admin_bar() {
    if (is_pro_site()) {
      show_admin_bar(false);
    }
    }

    Essentially, it checks is the site is a pro site and if it is, then it hides the admin.

    Hope that helps! If you have any further questions just let us know.

    All the best,
    Tyler

  • Anang

    Hi @rcbiili

    The plugin is ok but what i want is to show the admin bar only for the free pro site users. Upgraded users should not see it at all when they are not logged in

    I'm a little confused here, how we determined if the user is a Upgraded users if they're not logged in yet ? How we can get the username and check if they're upgraded user if they're not enter any information yet in your website ?

    Please advise :slight_smile:

    Best Regards

  • rcbiili

    @Anang Thanks for answering. I'll explain this for each.

    Site A is not a pro user and uses the free plan. On this site the wp toolbar will be visible on the front end for non logged in visitors. The system already knows if that site is pro or not. This will be another reason why they have to upgrade to a pro plan so that the wp-toolbar will be no longer showing on the front end. When i say front end i mean for non logged in users. So visitors will come to this see the site and bar at the top where we will try to add our logo on the left, and Create a free website on the right.

    Site B is a pro user so the wp-toolbar will not be visible on the front end for non logged in visitors. It will work as usual they will see it when they log in.

    I hope this explanation is better and that you understood what i am trying to achieve.

    This is so we "mark" free sites with a sort of our branding. This is an awesome idea to bring more registrations on the network. Think at this scenario.

    User (visitor) goes to site (free site made on our network) and the first thing they note is the bar at top that shows the logo of our network on left and Create website on right. They than think, oh cool this is a free website, and i could build one like this too.

  • Anang

    Hi @rcbiili

    Thanks for detailing your requests :slight_smile: Now I'm understand what are you trying to achieve :slight_smile: And it's a brilliant idea to acquire new users :slight_smile:

    We can disable admin bar plugin on certain blogs (pro user) and let it enabled in free blog. Here's steps to achieve that :
    1. Create a new file called enable-free-bar.php inside wp-content/mu-plugins , create mu-plugins if you don't have one.
    2. Put this code inside enable-free-bar.php file

    <?php
    add_filter('site_option_active_sitewide_plugins', 'modify_sitewide_plugins');
    function modify_sitewide_plugins($value) {
        global $current_blog;
        $user_id = get_user_id_from_string( get_blog_option($current_blog->blog_id, 'admin_email'));
        if($current_blog->blog_id!=1 && is_pro_user($user_id)) {
            unset($value['admin-bar-login/admin-bar-login.php']);
        }
        return $value;
    }

    4. Save the file

    Let me know the result :slight_smile:

    Best Regards

  • rcbiili

    Hello Anang.

    I have network activated the admin bar login plugin and made a mu-plugin called enable-free-bar.php( i attached it to this post maybe i did something wrong).

    After doing this is making my whole network give white screen.

    I tried purging nginx cache and cloudflare cache. I have also put cloudflare in development mode.

    P.s: After publishing the post it told be that .php is not an allowed extension so i just copy and pasted the code on pastebin.

    This is the link: http://pastebin.com/KKz8xgQj

  • Anang

    Hi @rcbiili

    Could you change the code to this one ?

    <?php
    if(!function_exists('get_user_by')) {
        include(ABSPATH . "wp-includes/pluggable.php");
    }
    add_filter('site_option_active_sitewide_plugins', 'modify_sitewide_plugins');
    function modify_sitewide_plugins($value) {
        global $current_blog;
        $user_id = get_user_by('email',get_blog_option($current_blog->blog_id, 'admin_email'));
        if($current_blog->blog_id!=1 && is_pro_user($user_id)) {
            unset($value['admin-bar-login/admin-bar-login.php']);
        }
        return $value;
    }

    Some functions is not loaded before in multisite activation (under mu-plugins), so I include file and change a function there.

    Let me know the result :slight_smile:

    Best Regards

  • Anang

    Hi @rcbiili

    Would you mind send me your FTP account info , so I can test on your installation ? Please send me your FTP information here :
    https://premium.wpmudev.org/contact/
    Select "I have a different question" for your topic - this and the subject line ensure that it gets assigned to me :simple_smile:
    Subject: "Attn: Anang"
    -WordPress admin username
    -WordPress admin password
    -login url
    -FTP credentials (host/username/password)
    -link back to this thread for reference
    -any other relevant urls

    Looking forward for the acccess :slight_smile:

    Best Regards

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.