BuddyDev

Search

[Resolved] Please add filter to BP Default Group Tab plugin

  • Participant
    Level: Enlightened
    Posts: 68
    Nick on #43677

    Could please add a filter to the BP Default Group Tab plugin to be able to remove particular tabs from the available tabs dropdown?

    I have another plugin that relies upon its tab slug for some of its functionality, so if I give group admins the ability to select it as the default, the slug disappears and the functionality doesn’t work anymore. Surely it would be ideal to fix how that plugin works, but that is unlikely to happen whereas this should be quite easy (and perhaps even generally desirable)!

    My guess is the filter could be added to either the show_settings_box_content or get_group_tabs function.

    Thanks!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43678

    Hello Nick,

    Thank you for posting here. We will release the update in the future version. For the time being You can use the following code:

    
    
    /**
     * Check and redirect on the restricted tab
     *
     * @param int $group_id Group id.
     */
    function buddydev_check_redirect_restricted_tab( $group_id ) {
    
    	if ( ! groups_is_user_admin( get_current_user_id(), $group_id ) || ! bp_is_group_admin_screen( 'group-settings' ) ) {
    		return;
    	}
    
    	if ( ! empty( $_POST['group_default_tab'] ) && 'members' == $_POST['group_default_tab'] ) {
    		bp_core_add_message( sprintf( 'Members tab can not be use as default tab.' ), 'error' );
    		bp_core_redirect( bp_get_group_admin_permalink( $group_id ) . 'group-settings' );
    	}
    }
    
    add_action( 'groups_group_settings_edited', 'buddydev_check_redirect_restricted_tab', 9 );
    

    It will restrict group admin to save the ‘members’ tab as the default tab. You can replace this with your own tab slug. Please give it a try and let me know if it works or not.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 68
    Nick on #43692

    Thanks very much!

    However, I get some errors with this.

    Notice: Trying to get property ‘slug’ of non-object in /home/seeingtheforest.net/public_html/wp-content/plugins/buddyboss-platform/bp-groups/bp-groups-template.php on line 1315

    Warning: Cannot modify header information – headers already sent by (output started at /home/seeingtheforest.net/public_html/wp-content/plugins/buddyboss-platform/bp-groups/bp-groups-template.php:1315) in /home/seeingtheforest.net/public_html/wp-includes/pluggable.php on line 1355

    Warning: Cannot modify header information – headers already sent by (output started at /home/seeingtheforest.net/public_html/wp-content/plugins/buddyboss-platform/bp-groups/bp-groups-template.php:1315) in /home/seeingtheforest.net/public_html/wp-includes/pluggable.php on line 1358

    But I think it would be better to just add a filter to remove it from the dropdown altogether. This seems to work


    public function get_group_tabs() {

    // Find current group
    // $current_group = new BP_Groups_Group( $current_group_id );

    // We need slug to access the nav items
    // $current_group_slug = $current_group->slug;
    // Get all nav items.

    $new_tabs = array();

    $tabs = buddypress()->groups->nav->get_secondary( array( 'parent_slug' => bp_get_current_group_slug() ) );
    // bp_get_nav_menu_items('groups');

    foreach ( $tabs as $tab ) {
    $new_tabs[ $tab['slug'] ] = $tab['name'];
    }

    $new_tabs = apply_filters('bpdgt_remove_tabs', $new_tabs);

    // Let us reset the admin option from the tab.
    foreach ( $new_tabs as $key => $tab ) {
    if ( $key == 'admin' ) {
    unset( $tabs[ $key ] );
    break;
    }
    }

    // Reset the empty items.
    $new_tabs = array_filter( $new_tabs );

    return $new_tabs;
    }

  • Participant
    Level: Enlightened
    Posts: 68
    Nick on #43693
    
    public function get_group_tabs() {
    
    // Find current group
    // $current_group = new BP_Groups_Group( $current_group_id );
    
    // We need slug to access the nav items
    // $current_group_slug = $current_group->slug;
    // Get all nav items.
    
    $new_tabs = array();
    
    $tabs = buddypress()->groups->nav->get_secondary( array( 'parent_slug' => bp_get_current_group_slug() ) );
    // bp_get_nav_menu_items('groups');
    
    foreach ( $tabs as $tab ) {
    $new_tabs[ $tab['slug'] ] = $tab['name'];
    }
    
    $new_tabs = apply_filters('bpdgt_remove_tabs', $new_tabs);
    
    // Let us reset the admin option from the tab.
    foreach ( $new_tabs as $key => $tab ) {
    if ( $key == 'admin' ) {
    unset( $tabs[ $key ] );
    break;
    }
    }
    
    // Reset the empty items.
    $new_tabs = array_filter( $new_tabs );
    
    return $new_tabs;
    }
    
  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #43702

    Hi Nick,

    I am sorry for the issue. We will be testing and updating the plugin early next week.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 68
    Nick on #43703

    There’s nothing to apologize for! The filter I added works for my purposes, so it would be great if you can add it in your update.

    
    $new_tabs = apply_filters('bpdgt_remove_tabs', $new_tabs);
    
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43713

    Hello Nick,

    Thank you for your acknowledgement. ‘bpdgt_remove_tabs’ is not a good name for the filter as with this name filter’s sole purpose seems to be only removal. I would suggest use ‘bpdgt_modify_tabs’ instead. Also, the position should be on the return statement

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 68
    Nick on #43733

    Good points. It now looks like this for me.

    
    return apply_filters ('bpdgt_modify_tabs', $new_tabs);
    
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43736

    Thank you

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved