Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/27/2014 05:13:29 PM (10 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-blogs/bp-blogs-activity.php

    r8747 r9194  
    3434            __( 'New site created', 'buddypress' ),
    3535            'bp_blogs_format_activity_action_new_blog',
    36             __( 'New Sites', 'buddypress' )
     36            __( 'New Sites', 'buddypress' ),
     37            0
    3738        );
    3839    }
    3940
    40     bp_activity_set_action(
    41         $bp->blogs->id,
    42         'new_blog_post',
    43         __( 'New post published', 'buddypress' ),
    44         'bp_blogs_format_activity_action_new_blog_post',
    45         __( 'Posts', 'buddypress' ),
    46         array( 'activity', 'member' )
    47     );
    48 
    49     bp_activity_set_action(
    50         $bp->blogs->id,
    51         'new_blog_comment',
    52         __( 'New post comment posted', 'buddypress' ),
    53         'bp_blogs_format_activity_action_new_blog_comment',
    54         __( 'Comments', 'buddypress' ),
    55         array( 'activity', 'member' )
    56     );
     41    // Only add the comment type if the 'post' post type is trackable
     42    if ( post_type_supports( 'post', 'buddypress-activity' ) ) {
     43        bp_activity_set_action(
     44            $bp->blogs->id,
     45            'new_blog_comment',
     46            __( 'New post comment posted', 'buddypress' ),
     47            'bp_blogs_format_activity_action_new_blog_comment',
     48            __( 'Comments', 'buddypress' ),
     49            array( 'activity', 'member' ),
     50            10
     51        );
     52    }
    5753
    5854    do_action( 'bp_blogs_register_activity_actions' );
     
    109105    }
    110106
    111     $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) );
    112 
    113     $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
     107    if ( empty( $activity->post_url ) ) {
     108        $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) );
     109    } else {
     110        $post_url = $activity->post_url;
     111    }
     112
     113    if ( empty( $activity->post_title ) ) {
     114        $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
     115    } else {
     116        $post_title = $activity->post_title;
     117    }
    114118
    115119    // Should only be empty at the time of post creation
Note: See TracChangeset for help on using the changeset viewer.