[buddypress-trac] [BuddyPress Trac] #9019: `bp_is_group()` can return true on the group creation page

buddypress-trac noreply at wordpress.org
Tue Nov 7 02:44:13 UTC 2023


#9019: `bp_is_group()` can return true on the group creation page
--------------------------+------------------------------------
 Reporter:  r-a-y         |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Core          |    Version:
 Severity:  normal        |   Keywords:  dev-feedback has-patch
--------------------------+------------------------------------
 Ran into an issue where `bp_is_group()` is returning `true` on the group
 creation page.

 When a BuddyPress group is created, it sets the
 `buddypress()->groups->current_group` property to the new group's details:
 https://github.com/buddypress/buddypress/blob/7a2458117e98f4861f9a9b85806b712770fb5919/src
 /bp-groups/actions/create.php#L60-L62 . This code runs on 'bp_actions' at
 priority 10. So if you have any code running after 'bp_actions' at a
 priority on 10 or greater, then `bp_is_group()` will return `true`.

 Example code:

 {{{#!php
 <?php
 add_action( 'bp_actions', function() {
   if ( bp_is_group_create() ) {
     var_dump( bp_is_group() );
   }
 }, 11 );
 }}}


 Devs can workaround this by running their `bp_is_group()` checks before
 `'bp_actions'` at priority 9 or lower. Or by adding a
 `bp_is_group_create()` check next to the `bp_is_group()` conditional.

 I've attached a patch that does the latter.

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/9019>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list