Disable Ultimate Branding on the main site when network activated

I want to use Ultimate Branding to add some custom styles and stuff my multisite admin bar. However, I'm using the Boss theme from BuddyBoss on the main site and it doesn't play well when UB is activated and modifiying the admin bar (Boss does major modifications to the admin bar).

Can you help me put together a snippet that will let me keep it network activated so that I can brand the subsites with my brand, but disable (or not load it) on the main site so that it doesn't conflict with my theme?

  • Anang

    Hi Saunt

    Hope you have a great day :slight_smile: To disable a plugin on certain site, you need to know what blog id is your main site (usually 2). And then you can try put this script on your functions.php on your active theme folder (main site theme).

    add_filter('site_option_active_sitewide_plugins', 'modify_sitewide_plugins');
    
    function modify_sitewide_plugins($value) {
        global $current_blog;
    
        if( $current_blog->blog_id == 2 ) {
            unset($value['ultimate-branding/ultimate-branding.php']);
        }
    
        return $value;
    }

    Don't forget to change $current_blog->blog_id == 2 to your blog id
    Let me know if that script working or not :slight_smile:

    Best Regards

  • Jude

    Hi there @Saunt Valerian

    Hope you're doing great !!

    Here is some code I cobbled together for you.

    remove_all_actions( 'admin_bar_menu ' ) ;
    remove_all_actions( 'wp_before_admin_bar_render ' ) ;
    remove_all_actions( 'wp_after_admin_bar_render ' ) ;
    remove_all_actions( 'wp_ajax_ub_save_menu_ordering ' ) ;
    remove_all_filters( 'ultimatebranding_settings_menu_adminbar_process ') ;

    Just copy/paste the code into the functions.php file of your child theme or a site specific plugin if you use one.

    It may however remove any modifications your theme makes as well.

    Let me know how it goes

    Cheers
    Jude

  • Saunt Valerian

    Hey guys, sorry for the really late reply on this. I just tested both of these methods and neither one worked.

    @Anang This method was overkill in that it stopped ultimate branding from working everywhere. This is probably because the main site ID in my install is 1, so ends up disabling ultimate branding across the network. With this snippet, the plugin settings are no longer available in the network admin.

    @Jude The method you provided didn't seem to have any effect at all and when I re-enabled the admin bar module in the plugin, it still conflicted with theme.

    I suppose, essentially what I really need here, is to ensure the custom admin bar module doesn't load on the main site of the network because it conflicts with my theme

  • Saunt Valerian

    @Anang Doing a site-by-site activation is not practical. The whole point of the network activation is to control the user experience across the subsites and manipulate as I see fit. Network activation is the right method.

    It looks like the conflict is only js and css. The Boss theme integrates the features of the admin bar into the theme by repurposing how the admin bar works. So when then admin bar module of the ultimate branding is activated, it does exactly what it is supposed to do on the subsites, but on the main site (where Boss is deployed), it conflicts with the theme's modifications - all of those modifications appear to be js and css.

    The site is http://teatra.de
    Here is the subsite directory so you can browse to the subsites: http://teatra.de/directory/

    I've enabled support access for you to go in and have a look around. Please play with it a little to get an idea the impact the admin bar module is having.

  • Anang

    Hi @Saunt Valerian

    Sorry for late response :slight_frown:

    Could you try put this code in you themes functions.php that used on your main site :

    add_action( 'admin_enqueue_scripts', 'my_deregister_adminbar_styles', 200 );
    function my_deregister_adminbar_styles() {
    	if (get_current_blog_id()==1)
    		wp_deregister_style( 'ub_adminbar_general_styles' );
    }

    Basically it remove admin bar css on main site. If it's not worked could you grant me access again to your site ? The access has been expired :slight_smile:

    Let me know the result :slight_smile:

    Best Regards

  • Anang

    HI @Saunt Valerian

    I have check your theme settings and found out you're not setup the logo yet, maybe that's why it's not displayed ?

    And also could you tell me where's the messed up menu ? On backend or frontend ? Because I'm checking all is fine with your themes right now. If you can attach screenshot that would be great :slight_smile:

    Looking forward for your answer :slight_smile:

    Best Regards

  • Saunt Valerian

    @Anang yeah, sorry, I should have explained. To see the issue, you'll need to go into the network admin Branding settings and re-enable the Admin Bar module. I have it turned off during regular use until I can get it working right.

    What you will see is that the user menu in the top right of the screen gets messed up. Take a moment to compare how it works with the Admin bar enabled and disabled. That user menu is the WordPress/BuddyPress admin bar as controlled by the theme. I'm not using a logo, just allowing the theme to display the site name in text. This disappears when the Admin Bar module is turned on.

  • Anang

    Hi @Saunt Valerian

    After trying on my installation , it seems our old code is worked. But need to put in mu-plugins folder. So you need to create file disable-ultimate.php under /wp-content/mu-plugins create folder mu-plugins if it doesn't exist. Then put this code in the file :

    add_filter('site_option_active_sitewide_plugins', 'modify_sitewide_plugins');
    function modify_sitewide_plugins($value) {
        global $current_blog;
    
        if( $current_blog->blog_id == 1 ) {
            unset($value['ultimate-branding/ultimate-branding.php']);
        }
    
        return $value;
    }

    It will disable ultimate branding only in main site, I have tested it, and hope it worked on you too :slight_smile:

    Let me know the result :slight_smile:

    Best Regards

  • Dutchman

    @Anang thanks for your reply.
    I have exactly the same issue here, using the exact same theme and plugin (branding).
    I tried your code described as above this reply, but it gives me this error:

    add_filter('site_option_active_sitewide_plugins', 'modify_sitewide_plugins'); function modify_sitewide_plugins($value) { global $current_blog; if( $current_blog->blog_id == 1 ) { unset($value['ultimate-branding/ultimate-branding.php']); } return $value; }
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/.../public_html/wp-content/mu-plugins/disable-ultimate.php:10) in /home/.../public_html/wp-content/plugins/pro-sites/pro-sites-files/lib/ProSites/Helper/Session.php on line 29

    Warning: Cannot modify header information - headers already sent by (output started at /home/.../public_html/wp-content/mu-plugins/disable-ultimate.php:10) in /home/.../public_html/wp-content/plugins/sitewide-privacy-options/sitewide-privacy-options.php on line 591

  • Anang

    Hi @dutchmen

    Sorry for the confusion.. It's need php open tag <?php so it's become :

    <?php
    add_filter('site_option_active_sitewide_plugins', 'modify_sitewide_plugins');
    function modify_sitewide_plugins($value) {
        global $current_blog;
    
        if( $current_blog->blog_id == 1 ) {
            unset($value['ultimate-branding/ultimate-branding.php']);
        }
    
        return $value;
    }

    Let me know the result :slight_smile:

    Best Regards

  • Anang

    Hi @dutchmen

    Please note that this plugins is gonna disable Ultimate Branding plugin not the "custom admin bar" addon only. And you must have network activated Ultimate Branding before you put that code. You can comment that code first, and then try activate Ultimate Branding then uncomment that code again.

    The Ultimate Branding won't load on your main site, but it's loaded to all your subsite :slight_smile:

    Let me know the result :slight_smile:

    Best Regards

  • Anang

    Hi @dutchmen

    Please note that this plugins is gonna disable Ultimate Branding plugin not the "custom admin bar" addon only. And you must have network activated Ultimate Branding before you put that code. You can comment that code first, and then try activate Ultimate Branding then uncomment that code again.

    The Ultimate Branding won't load on your main site, but it's loaded to all your subsite :slight_smile:

    Let me know the result :slight_smile:

    Best Regards

  • Dutchman

    HI @Anang

    Thank you for your explanation. But unfortunately that doesn't help. I have a multisite running and I did what you have explained. I have network activated it (creating a settings menu at the network dashboard, not the main site) but when I have the code snippet saved under mu-plugins, no matter what sequence I activate/deactivate or ad the snippet. The results are the same, it disables the plugin completely. The settings menu is gone and it's says deactivated on the network plugins page. Also I have no place to edit the settings anymore, plus the custom admin is not workiing on any sub sites.

    Am I missing something?

  • Tyler Postle

    Hey Dutchmen,

    Sorry for the delay on this, Anang is away for a few days. I've tested the code out as well and I'm finding a similar behaviour. While it does remain active for me on subsites, it's removed from the network admin so you can't change any settings. I've left a message for anang about this and he'll check it when he is back.

    Any further questions in the meantime just let us know.

    Cheers,
    Tyler

  • Anang

    Hi All

    Finally I got the solutions, but unfortunately it need changes on plugins core files. That's mean when you update the plugins, you need to do this changes again :slight_smile:

    You need to find load_modules() function on this files :
    wp-content\plugins\ultimate-branding\ultimate-branding-files\classes\ubadmin.php line 212 , and
    wp-content\plugins\ultimate-branding\ultimate-branding-files\classes\ubpublic.php line 36

    and replace it with :

    function load_modules() {
                // Load our remaining modules here
                foreach ($this->modules as $module => $plugin) {
                    if (ub_is_active_module($module)) {
                        if (get_current_blog_id()==1&&$module=="custom-admin-bar.php")
                            continue;
                        ub_load_single_module($module);
                    }
                }
            }

    Hope that's worked :slight_smile:

    Best Regards

  • Anang

    Hi @dutchmen

    Custom Admin Bar addons not only adding a style on your admin bar. But if you want to try remove the Custom Admin Bar css only, you can add this script in your custom file under mu-plugins folder :

    add_action( 'admin_enqueue_scripts', 'my_deregister_adminbar_styles', 200 );
    function my_deregister_adminbar_styles() {
    	if (get_current_blog_id()==1)
    		wp_deregister_style( 'ub_adminbar_general_styles' );
    }

    Let me know if that's worked for you :slight_smile:

    Best Regards

  • Michael Bissett

    Hey @dutchmen,

    I'd say that we'll want to have a deeper look at your site here, could you please send in the following via our secure contact form:

    - Mark to my attention, the subject line should contain only: ATTN: Michael Bissett
    - Do not include anything else in the subject line, doing so may delay our response due to how email filtering works.
    - Link back to this thread
    - Include WordPress network admin access details (login address, username & password)
    - Include FTP log-in details (hostname, username & password)
    - Include any relevant URLs for your site

    On the contact form (linked to below), please select "I have a different question", this ensures it comes through and gets assigned to me.

    https://premium.wpmudev.org/contact/

    Thanks! :slight_smile:

    Kind Regards,
    Michael

  • Michael Bissett

    Hey @Saunt Valerian,

    Gah, sorry for missing that!

    In that case, could you please send in the following for your site, so that I can have a deeper look at things?

    - Mark to my attention, the subject line should contain only: ATTN: Michael Bissett
    - Do not include anything else in the subject line, doing so may delay our response due to how email filtering works.
    - Link back to this thread
    - Include WordPress network admin access details (login address, username & password)
    - Include FTP log-in details (hostname, username & password)
    - Include any relevant URLs for your site

    On the contact form, select "I have a different question", this ensures it comes through and gets assigned to me.

    https://premium.wpmudev.org/contact/

    Thanks a bunch! :slight_smile:

    Kind Regards,
    Michael

  • Michael Bissett

    Hey @Saunt Valerian,

    Okay, after a lot of digging into this, I've found this to do the trick, both on my own site, as well as yours:

    <?php
    
    add_filter('plugins_loaded', 'modify_sitewide_plugins');
    function modify_sitewide_plugins() {
    	global $current_blog, $uba;
    
                $modules = get_ub_activated_modules();
    
        if( $current_blog->blog_id == 1 && !is_admin() ) {
                    unset($modules['custom-admin-bar.php']);
                    update_ub_activated_modules($modules);
        } else {
                    $modules['custom-admin-bar.php'] = 'yes';
                    update_ub_activated_modules($modules);
                }
    }

    Can you confirm the same on your end please? This'll disable the module on the front end of your main site only, otherwise, it'll be enabled.

    Kind Regards,
    Michael

  • Saunt Valerian

    @Michael Bissett Wow, thank you for taking the time to look into this and sort it out.

    This looks like a very solid solution and I can confirm that it is working.

    I did experience a fatal error shortly after you set it up, and attempts to navigate the network showed this fatal error noting back to your code:

    Fatal error: Call to undefined function get_ub_activated_modules() in /home/teatrade/public_html/wp-content/mu-plugins/ub-fix.php on line 7

    Shortly after that, I experienced a whole bunch of corrupted database tables and had to run through the repair and optimize process to get everything working again....

    Nevertheless, you have provided a solution, but I don't know if the solution has created a full weakness yet. I've repaired and reset everything and put your code back into place in the mu-plugin. I'm going to let it run again now and see what happens with it.

    Interestingly, line 7 is this part:
    $modules = get_ub_activated_modules();

    Once I got everything repaired and running again, I discovered that the Admin Bar Module had been deactivated, I don't know when that deactivation occurred, but the fatal error was probably related to that line combined with the deactivation of the module.

    Thank you for this, despite the snafu, I'm happy that you've made such headway with this. I'll report back again in the next day or so about the stability issues after I've had some time to let it run.