Customising Sub Menu in App

Following is an example of how you can customise sub-menu in the vibbep social app.

 

Here we read the capabilities of a user and add / remove sub-menu items from the app.

class MY_API_Custom{

    private $user;
    public static $instance;
    public static function init(){

        if ( is_null( self::$instance ) )
            self::$instance = new MY_API_Custom();
        return self::$instance;
    }

    private function __construct(){
        
        add_filter('vibebp_profile_menu',array($this,'cache_user'),10,2);
        add_filter('vibebp_setup_nav',array($this,'nav'),10,1);
        //add_filter('bp_rest_activity_get_item_permissions_check',array($this,'auth'),99,2);
        
    }

    function cache_user($menu,$user){
        $this->user = $user;
        return $menu;
    }
	
    function nav($nav){
        
        if($this->user && is_Object($this->user->caps) && !in_array('manage_options',array_keys((Array)$this->user->caps))){
            foreach($nav as $i=>$n){
                if($n['css_id'] == 'projects' && !empty($n['parent']) && $n['parent'] == 'projects'){
                    unset($nav[$i]);        
                }
            }
            
        }
        return array_values($nav);
    }
}

MY_API_Custom::init();