[buddypress-trac] [BuddyPress Trac] #5669: Help plugins to generate activities for their post type(s)

buddypress-trac noreply at wordpress.org
Wed Nov 26 16:43:05 UTC 2014

#5669: Help plugins to generate activities for their post type(s)
 Reporter:  imath                  |       Owner:
     Type:  enhancement            |      Status:  new
 Priority:  normal                 |   Milestone:  2.2
Component:  Activity               |     Version:  2.0
 Severity:  normal                 |  Resolution:
 Keywords:  2nd-opinion has-patch  |

Comment (by imath):

 Replying to [comment:20 boonebgorges]:
 > I still think my lazoloading idea is more elegant.

 Since the beginning of our discussions on this ticket, you've convinced
 me. The {{{buddypress()->activity->actions}}} thing was bothering me. So
 after a short night thinking about it, i thought let's try to do it to
 have an alternative to the way the patch was built so far.

 So i've changed some functions and tried to build the tracking feature the
 lazyloading way. So in 5669.05.patch, i'm not using hook(s) to register a
 {{{buddypress()->activity->track}}} global anymore.

 I now have a function i'm using just before publishing, updating or
 removing the activity : {{{bp_activity_get_post_type_tracking_args(
 $post_type = '' )}}}

 There's also {{{bp_activity_get_post_types_tracking_args()}}} which loop
 through the registered post types and uses the function i've mentioned
 above to build all "post types tracking argument".

 This function is used at 2 places :
 - to populate the dropdown lists
 - inside the format_callback function

 About the dropdowns in front and admin they are now using a wrapper
 function to {{{buddypress()->activity->actions}}} :
 {{{bp_activity_get_actions()}}} first fetches all post types to eventually
 add the actions about the post types and sort each component actions by
 their "position" order.

 About the format callback, as this function is used for each activity of
 the type listed in the stream, i thought maybe it could be interesting to
 use  {{{bp_activity_get_post_types_tracking_args()}}} only once, so that's
 the only place where i've kept {{{buddypress()->activity->track}}}.

 About the 7 points of your "nitpicky feedback", i've included them all and
 your point about the 'admin_filter' made me thought maybe we could leave
 all tracking args being customizable from the post types register

 So it's now possible to define all the tracking arguments using for
 instance :
 $labels = array(
         'name'                    => 'bars',
         'singular_name'           => 'bar',
         'bp_activity_new_post'    => __( '%1$s shared a new <a
 href="%2$s">bar</a>', 'bar-domain' ),
         'bp_activity_new_post_ms' => __( '%1$s shared a new <a
 href="%2$s">bar</a>, on the site %3$s', 'bar_domain' ),

 register_post_type( 'bars', array(
         'labels'   => $labels,
         'public'   => true,
         'supports' => array( 'buddypress-activity' ),
         'bp_activity => array( 'component_id' => 'my_custom_component',
 'action_id' => 'my_custom_action' .....),
 ) );

 we still can do a simple :
 add_post_type_support( 'page', 'buddypress-activity' );

 In this case BuddyPress will use generic strings, format callback etc...

 Finally, we can also set one or all arguments using

         add_post_type_support( 'page', 'buddypress-activity' );

         bp_activity_set_post_type_tracking_args( 'page', array(
                 'component_id'             => buddypress()->blogs->id,
                 'action_id'                => 'mabelle_page',
                 'bp_activity_admin_filter' => 'Nouvelle page publiée',
                 'bp_activity_front_filter' => 'Nouvelle page',
                 'contexts'                 => array( 'member', 'activity'
                 'activity_commment'        => false,
                 'bp_activity_new_post'     => '%1$s shared a new <a
 href="%2$s">test page</a>',
                 'bp_activity_new_post_ms'  => '%1$s shared a new <a
 href="%2$s">test page</a>, on the site %3$s',
                 'position'                 => 100,
         ) );

 I've edited the unit tests, ran it and checked on a multisite config,
 everything seems to work fine.

 I need extra eyes :) Thanks again for your help.

Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5669#comment:21>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac

More information about the buddypress-trac mailing list