Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/27/2014 05:13:29 PM (7 years ago)
Author:
imath
Message:

Post Type Activity Tracking feature

So far the tracking feature was requiring the Blogs component to be active. In 2.2 we are centralizing the majority of the tracking code into the Activity component. A new set of functions and hooks has been created to catch public post types supporting the feature 'buddypress-activity' and to automatically generate an activity when a new item is publicly published.

It's now possible to add this support to any public post type using one unique line of code, eg: add_post_type_support( 'page', 'buddypress-activity' ). In this case BuddyPress will use generic activity attributes.
Each activity attribute of the supported post type can be customized using a specific function (eg: set custom strings to describe the post type activity action).

When registering a post type in WordPress it's also possible to set the 'buddypress-activity' feature using the support parameter of the second argument of the register_post_type() function. Custom activity action strings can be defined within the labels parameter and activity attributes can be set using the new parameter 'bp_activity'.

When the Blogs component is active, the 'post' post type is automatically supporting the 'buddypress-activity' feature. The conditional logic (eg: blog_public option set to 1 ...) that occurs before a new activity is posted and the comments tracking remain unchanged.

props boonebgorges, DJPaul

Fixes #5669

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-template.php

    r9169 r9194  
    33163316function bp_activity_can_comment() {
    33173317    global $activities_template;
     3318    $bp = buddypress();
    33183319
    33193320    // Assume activity can be commented on
     
    33223323    // Determine ability to comment based on activity action name
    33233324    $activity_action = bp_get_activity_action_name();
    3324     switch ( $activity_action ) {
    3325 
    3326         // Maybe turn off for blog and forum updates
    3327         case 'new_blog_post'    :
    3328         case 'new_blog_comment' :
    3329         case 'new_forum_topic'  :
    3330         case 'new_forum_post'   :
    3331             if ( ! empty( $activities_template->disable_blogforum_replies ) ) {
    3332                 $can_comment = false;
    3333             }
    3334             break;
    3335 
    3336         // Turn off for activity comments
    3337         case 'activity_comment' :
    3338             $can_comment = false;
    3339             break;
    3340     }
     3325
     3326    $turn_off = 0;
     3327    if ( ! empty( $activities_template->disable_blogforum_replies ) ) {
     3328        $turn_off = 1;
     3329    }
     3330
     3331    $maybe_turn_off = array_fill_keys( array(
     3332        'new_blog_post',
     3333        'new_blog_comment',
     3334        'new_forum_topic',
     3335        'new_forum_post',
     3336    ), $turn_off );
     3337
     3338    $maybe_turn_off['activity_comment'] = 1;
     3339
     3340    // Fetch all the tracked post types once.
     3341    if ( empty( $bp->activity->track ) ) {
     3342        $bp->activity->track = bp_activity_get_post_types_tracking_args();
     3343    }
     3344
     3345    foreach ( $bp->activity->track as $action => $tracking_args ) {
     3346        if ( empty( $tracking_args->activity_comment ) ) {
     3347            $maybe_turn_off[ $action ] = $turn_off;
     3348        }
     3349    }
     3350
     3351    $can_comment = empty( $maybe_turn_off[ $activity_action ] );
    33413352
    33423353    /**
     
    43684379        // Walk through the registered actions, and prepare an the
    43694380        // select box options.
    4370         foreach ( buddypress()->activity->actions as $actions ) {
     4381        foreach ( bp_activity_get_actions() as $actions ) {
    43714382            foreach ( $actions as $action ) {
    43724383                if ( ! in_array( $context, (array) $action['context'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.