BuddyDev

Search

[Resolved] Disable Specific Plugins and Load Specific css on Each Buddyboss Component

  • Participant
    Level: Initiated
    Posts: 10
    Emmanuel Johnson on #48146

    I want to disable specific plugins and also load specific css files on each buddyboss components.

    I am using this code to disable the specified plugins

    add_filter( 'activeplugins', function(){
    	
    	$active_plugins = get_option( 'active_plugins' );
    	$plugins = "";
    	if( count( $active_plugins ) > 0 ){
    		foreach ( $active_plugins as $plugin ) {
    			$plugins =  $plugin;
    		}
    	}
    	return $plugins;
    });
    
    if ( bp_is_user_profile() ) {
    	$allowed_plugins = array(
    		"buddyboss-platform-2.2.4/bp-loader.php"
    	);
    	$plugins = array_diff( $plugins, $allowed_plugins );
    	return $plugins;
    }

    I’m not sure if the code is correct, but the first error I’m getting is “Call to undefined function bp_is_user_profile()”.

    Somebody please help me with this.

  • Keymaster
    (BuddyDev Team)
    Posts: 24645
    Brajesh Singh on #48147

    Hi Emmanuel,
    Please contact BuddyBoss support for the same. we do not provide custom code or support for BuddyBoss.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    Emmanuel Johnson on #48152

    Hi Brajesh,
    What about the “Call to undefined function bp_is_user_profile()”, please just help me on how to resolve the Call to undefined function problem for the various components. Or how do I check whether the current page is the members directory, the view profile, edit profile, upload profile photo, friends, timeline, photos, videos, and so on…

    How do I check if it is any of these components without any error.

  • Keymaster
    (BuddyDev Team)
    Posts: 24645
    Brajesh Singh on #48168

    Hi Emmanuel,
    You are getting call to undefined as you are calling the function before it is loaded by BuddyBoss.

    You are probably calling it in bp-custom.php directly or in a plugin file.

    Try calling it after bp_include priority 10 or on any action after it.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    Emmanuel Johnson on #48198

    Hi Brajesh, I don’t understand how to do that.
    Can you please post an example here.

  • Keymaster
    (BuddyDev Team)
    Posts: 24645
    Brajesh Singh on #48207

    Hi Emmanuel,
    If your goal is to disable, it is a difficult one.

    You will need to learn about MU plugins/drop ins(as they are loaded before the actual plugins) and then filter on the active plugins.
    Still, you are trying to filter on plugins based on another plugin while none of the plugins are loaded.
    So, that’s not a simple thing to achieve and will not work as normal.

    I will suggest looking at plugin organizer or similar package that handles the complexity and makes it work.

    https://wordpress.org/plugins/plugin-organizer/

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    Emmanuel Johnson on #48245

    Hi Brajesh,
    I understand what you are saying and I have already achieved that by using the urls to determine whether the user is on a perticular buddypress component, and disabled the irrelevant plugins by modifying the code above.

    However, please just post some examples on how I can call the functions without getting a “Call to undefined function” error, since now I want to filter the unused css on these components, but I don’t want to use the urls to check with this one.

    Since this topic seems to be off the hook, good thing that I have already figured it out, let me atleast benefit by learning how to check if a user is on a particular buddypress component.

    Thank you for understanding.

  • Keymaster
    (BuddyDev Team)
    Posts: 24645
    Brajesh Singh on #48250

    Here is a smaple code.

    
    add_action( 'bp_template_redirect', function () {
    
    	if ( bp_is_user() ) {
    		// do somethign here.
    	}
    
    } );
    

    You need to call the functions after they have been loaded. Most of the plugins complete their loading by ‘plugins_loaded’ action(there are some exceptions) and you can use it after that. There is another aspect(if the state is ready) when you call, for example, if you call is_page() on plugins_loaded, It will false even one page as the main query is not set. so, you need to understand these 2 aspects.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    Emmanuel Johnson on #48326

    Hi Brajesh,
    Thanks a lot, I was able to figure it out.

  • Keymaster
    (BuddyDev Team)
    Posts: 24645
    Brajesh Singh on #48341

    You are welcome.
    I am glad you found it.

    Regards
    Brajesh

The topic ‘ [Resolved] Disable Specific Plugins and Load Specific css on Each Buddyboss Component’ is closed to new replies.

This topic is: resolved