Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add to add a new item in buddypress profile page only for admins ?


  • Iuda
    Participant

    @iuda

    Hy
    it’s possible to add new tab ,like a link, in the buddypress profile page only for admin role ? i have a community site.

Viewing 8 replies - 1 through 8 (of 8 total)

  • shanebp
    Moderator

    @shanebp

    Yes, use is_super_admin()

    For example:

    function add_iuda_tab() {
    	global $bp;
    	
    	if ( is_super_admin() ) {
    	
    		bp_core_new_nav_item( array(
    			'name'                  => 'Iuda',
    			'slug'                  => 'iuda',
    			'parent_url'            => $bp->displayed_user->domain,
    			'parent_slug'           => $bp->profile->slug,
    			'screen_function'       => 'iuda_screen',			
    			'position'              => 200,
    			'default_subnav_slug'   => 'iuda'
    		) );
    
    	}
    }
    add_action( 'bp_setup_nav', 'add_iuda_tab', 100 );
    
    function iuda_screen() {
        add_action( 'bp_template_title', 'iuda_screen_title' );
        add_action( 'bp_template_content', 'iuda_screen_content' );
        bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    
    function iuda_screen_title() { 
    	echo 'iuda Title<br/>';
    }
    
    function iuda_screen_content() { 
    	echo 'iuda Content<br/>';
    }

    Iuda
    Participant

    @iuda

    thank you @shanebp for quick response

    this function can be extended for administrator and editor role ?


    shanebp
    Moderator

    @shanebp

    is_super_admin() checks to see if the current user is an administrator.
    To check if they are an editor, you need to check whether they have an editor permission.

    Try:

    if ( is_super_admin() || current_user_can('editor') ) {


    Iuda
    Participant

    @iuda

    thank you @shanebp, it work.

    One small request if it’s possible: i want, if i click to “Iuda” tab, to send me to wp-admin page.
    This is the link https://failtrafic.ro/wp-admin/

    sorry but my knowledge in the field of php are at a chicken level 😀


    shanebp
    Moderator

    @shanebp

    Try:

    function iuda_screen_content() { 
    	bp_core_redirect( 'https://failtrafic.ro/wp-admin/' );
    }

    Iuda
    Participant

    @iuda

    not working.


    shanebp
    Moderator

    @shanebp

    Try :

    wp_redirect( 'https://failtrafic.ro/wp-admin/' ); exit;


    Iuda
    Participant

    @iuda

    still don’t working 🙁

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar