[buddypress-trac] [BuddyPress] #2262: Patch for bp_core_new_subnav_item and bp_core_remove_subnav_item

buddypress-trac at lists.automattic.com buddypress-trac at lists.automattic.com
Tue Mar 30 22:36:36 UTC 2010


#2262: Patch for bp_core_new_subnav_item and bp_core_remove_subnav_item
-----------------------+----------------------------------------------------
 Reporter:  calvin_42  |       Owner:                   
     Type:  defect     |      Status:  new              
 Priority:  normal     |   Milestone:  1.3              
Component:  Core       |    Keywords:  reporter-feedback
-----------------------+----------------------------------------------------

Comment(by calvin_42):

 In the following example, I want to create a hook to change the default
 redirection groups/group-slug/admin -> groups/group-slug/admin/edit-
 details into groups/group-slug/admin/membership-requests. I have to use

 {{{
 remove_action( 'wp', 'groups_screen_group_admin', 3 );
 }}}

 in order for it to work. bp_core_remove_subnav_item() should have done it
 but it's not the case.

 {{{
 /**
  * bp_group_groups_admin_new_screen_function()
  *
  * Reorder the 'Admin' tab
  * Define a new screen function to change the default redirection
  */
 function bp_group_groups_admin_new_screen_function() {
         global $bp, $wp_filter;

         /* Execute next line because of bp_core_remove_subnav_item bug */
         /* See http://trac.buddypress.org/ticket/2262 */
         /* TODO : Check if the bug is corrected in a future version of
 BuddyPress */
         remove_action( 'wp', 'groups_screen_group_admin', 3 );

         if ( !$bp->is_single_item )
                 return;

         if ( !$bp->is_item_mod && !$bp->is_item_admin )
                 return;

         /* If the user is a group mod or more, then show the group admin
 nav item */
         if ( $bp->is_item_mod || $bp->is_item_admin ) {
                 bp_core_remove_subnav_item( $bp->groups->slug, 'admin' );

                 $group_link = $bp->root_domain . '/' . $bp->groups->slug .
 '/' . $bp->groups->current_group->slug . '/';

                 bp_core_new_subnav_item( array( 'name' => __( 'Admin',
 'buddypress' ), 'slug' => 'admin', 'parent_url' => $group_link,
                 'parent_slug' => $bp->groups->slug, 'screen_function' =>
 'groups_screen_group_admin_new', 'position' => 70,
                 'user_has_access' => ( $bp->is_item_admin +
 (int)$bp->is_item_mod ), 'item_css_id' => 'admin' ) );
         }

 }
 add_action('groups_setup_nav','bp_group_groups_admin_new_screen_function',
 10);

 /**
  * groups_screen_group_admin_new()
  *
  * Screen function for Admin Tab
  */
 function groups_screen_group_admin_new() {
         global $bp;

         if ( $bp->current_component != BP_GROUPS_SLUG || 'admin' !=
 $bp->current_action )
                 return false;

         if ( !empty( $bp->action_variables[0] ) )
                 return false;

         $current_tab = $bp->is_item_admin ? 'membership-requests' : 'edit-
 details';

         bp_core_redirect( bp_get_group_permalink(
 $bp->groups->current_group ) . 'admin/' . $current_tab . '/' );
 }
 }}}

-- 
Ticket URL: <http://trac.buddypress.org/ticket/2262#comment:2>
BuddyPress <http://buddypress.org/>
BuddyPress


More information about the buddypress-trac mailing list