[buddypress-trac] [BuddyPress] #2325: Changing hooked-to action functions to make new BP hooks work for 3rd-party components

buddypress-trac at lists.automattic.com buddypress-trac at lists.automattic.com
Mon Jun 28 02:58:52 UTC 2010


#2325: Changing hooked-to action functions to make new BP hooks work for 3rd-party
components
--------------------------------------+-------------------------------------
 Reporter:  jeffsayre                 |        Owner:  johnjamesjacoby
     Type:  defect                    |       Status:  closed         
 Priority:  major                     |    Milestone:  1.3            
Component:  Core                      |   Resolution:  fixed          
 Keywords:  has-patch, needs-testing  |  
--------------------------------------+-------------------------------------

Comment(by jeffsayre):

 Two issues encountered with this new patch.

 '''The first issue''', none of the core activity actions are loaded into
 the $bp->activity->actions array. This is because action hook
 bp_register_activity_actions is triggered by the bp_init action hook on
 line 1195 of bp-activity.php.

 The action hook bp_register_activity_actions is used by
 bp_blogs_register_activity_actions(), friends_register_activity_actions(),
 groups_register_activity_actions(), and
 xprofile_register_activity_actions. If you look at these functions, you
 will see that they each require that an id be set in $bp->xxx->id where
 the “xxx” is the component name. But, where is $bp->xxx->id set?

 It turns out that it is set via individual component action functions tied
 to the action event bp_setup_globals. See the function
 bp_blogs_setup_globals on line 65 of bp-blogs.php as an example.

 But, if you look at the firing sequence of the action hooks, you will see
 that the bp_init action hook fires before the bp_setup_globals hook (
 ''See Action_hook_firing_sequence_1.png'' ). This means that $bp->xxx->id
 does not get set so the function bp_activity_set_action returns false on
 line 976 of bp-activity.php. This results in the component’s activity
 actions not getting registered.

 The fix is to hook bp_register_activity_actions to the bp-loaded event,
 not bp-init. But, it must be hooked to bp-loaded after bp_setup_globals.
 By making the following change on line 1195 of bp-activity.php that can be
 accomplished:

 Instead of: add_action( 'bp_init', 'bp_register_activity_actions' );

 Change it to: add_action( 'bp_loaded', 'bp_register_activity_actions' );

 Look at the screenshot ''Action_hook_firing_sequence_2.png'' to see how
 the action hook firing sequence is changed with the above fix.

 NOTE: This action hook firing sequence issue was figured out by my
 WordPress Hook Sniffer Plugin referenced above.

 ________

 '''The second issue''' is that the bp_init event should be triggered after
 all the core events have been triggered. Why? Because we want to make sure
 that 3rd-party components hook into BP after all necessary code has been
 loaded. As it stands now, any component that hooks into BP using bp_init
 will do so before the bp_setup_globals event is triggered. This means that
 key globals will not yet be set.

 So, change line 2063 of bp-core.php simply by adding a custom priority:
 add_action( 'bp_loaded', 'bp_init', 9 );

 This will force bp_init to be triggered after bp_setup_globals event.

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


More information about the buddypress-trac mailing list