[buddypress-trac] [BuddyPress] #3476: Change priority of bp_screens (and maybe bp_actions) hooks

buddypress-trac at lists.automattic.com buddypress-trac at lists.automattic.com
Fri Aug 12 20:49:09 UTC 2011


#3476: Change priority of bp_screens (and maybe bp_actions) hooks
--------------------------+-----------------------
 Reporter:  boonebgorges  |      Owner:
     Type:  defect        |     Status:  new
 Priority:  major         |  Milestone:  1.5
Component:  Core          |    Version:  1.5
 Severity:  major         |   Keywords:  has-patch
--------------------------+-----------------------
 When the bp_screens and bp_actions action hooks were introduced, they
 introduced some much needed sanity and regularity to the way that events
 were hooked to pageloads. In what I assume was an attempt to mirror the
 old, haphazard hooking of items directly to {{{wp}}}, both bp_actions and
 bp_screens were hooked to {{{wp}}} with priority 2.

 However, this causes problems with plugins that are written in a certain
 way. In particular, it used to be recommended (in the Skeleton Component,
 among other places) that your plugin set up its globals and nav like this:
 {{{ function bbg_setup_stuff() {
    global $bp;
    $bp->boone->is = 'cool';
 }
 add_action( 'wp', 'bbg_setup_stuff', 2 );}}}

 With the introduction of bp_screens and bp_actions, this method now works
 only sometimes: it will work if you put it in bp-custom.php or in
 functions.php of your theme (so that you are hooked to wp's 2 priority
 slot *before* the screen functions), and it will also work if it's in a
 plugin that *happens* to be loaded before BuddyPress (I think it's done
 alphabetically by plugin directory name), but in other cases it does not
 work. That's because bp_screens is the action to which screen functions
 are hooked, and screen functions generally call bp_core_load_template(),
 which dies after output.

 We can, and I think should, avoid this. By changing the priority of
 bp_screens to 3 or 4, we make sure that plugins loaded in this outmoded
 (but still widely used) fashion will continue to work.

 bp_actions is a slightly different story. Functions hooked to bp_actions
 generally do not render templates, and so the same problems don't
 necessarily arise. However, it's still probably best to make sure that
 plugins have a chance to load themselves before running bp_actions type
 functions. Moreover, it makes sense to load bp_actions *before*
 bp_screens, because bp_actions functions generally redirect to a different
 page without rendering anything. Right now, bp_actions does indeed fire
 before bp_screens, but I think it's only accidentally, because it's called
 first.

 My recommended approach (move bp_screens to 4, bp_actions to 3) is in the
 attached patch. At the very minimum, we should strongly consider moving
 bp_screens.

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


More information about the buddypress-trac mailing list