[buddypress-trac] [BuddyPress Trac] #7218: Only load component action and screen code when we're on the component's page

buddypress-trac noreply at wordpress.org
Tue Dec 12 13:09:07 UTC 2017


#7218: Only load component action and screen code when we're on the component's
page
-----------------------------+-----------------------
 Reporter:  r-a-y            |       Owner:
     Type:  enhancement      |      Status:  reopened
 Priority:  normal           |   Milestone:  3.0
Component:  Core             |     Version:
 Severity:  normal           |  Resolution:
 Keywords:  has-patch early  |
-----------------------------+-----------------------

Comment (by DJPaul):

 Let's check my understanding first:

 My understanding the intent of this ticket is to avoid loading components'
 action and screen code (files) when we're not on a page route that
 requires it. Because of how the codebase uses the `bp_actions` hooks etc
 to check if it needs to handle the current request, those callbacks always
 need to be loaded, but the implementation handlers could be moved
 elsewhere.

 And that you've decided that moving the implementation into classes, and
 relying on a class autoloader, is the best approach.

 Broadly, I agree with you, but the devil's in the details. This is what
 @boonebgorges commented previously:

 > I'd imagined maybe a single BP_Activity_Actions class, with (static?)
 methods for each router. This would keep our number of files lower. It
 would also prevent us from doing lots of logic inside of a construct()
 method, which makes it easier to imagine writing tests for these at some
 point in the future.

 As I mentioned previously, I think using static methods for this is bad,
 but I do agree with Boone's suggestion we have a single class, rather than
 one class per function, which is what your patches currently do (and
 surely must be some sort of class loader anti-pattern).

 Here's my take on your code sample:
 {{{
 <?php
 class BP_Activity_Action {
   public function action_delete( $activity_id ) {
     return $whatever;
   }

   public function action_foobar( $activity_id ) {
     return $whatever;
   }
 }

 function bp_activity_action_delete_activity( $activity_id = 0 ) {
   // ...
   $thing = new BP_Activity_Action();
   return $thing->action_delete( $activity_id );
 }
 add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
 }}

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7218#comment:38>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list