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-activity/bp-activity-actions.php

    r9190 r9194  
    767767}
    768768add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' );
     769
     770/**
     771 * Detect a change in post type status, and initiate an activity update if necessary.
     772 *
     773 * @since BuddyPress (2.2.0)
     774 *
     775 * @todo Support untrashing better.
     776 *
     777 * @param string $new_status New status for the post.
     778 * @param string $old_status Old status for the post.
     779 * @param object $post       Post data.
     780 */
     781function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) {
     782    if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) {
     783        return;
     784    }
     785
     786    // This is an edit.
     787    if ( $new_status === $old_status ) {
     788        // An edit of an existing post should update the existing activity item.
     789        if ( $new_status == 'publish' ) {
     790            bp_activity_post_type_update( $post );
     791        }
     792
     793        return;
     794    }
     795
     796    // Publishing a previously unpublished post.
     797    if ( 'publish' === $new_status ) {
     798        // Untrashing the post type - nothing here yet.
     799        if ( 'trash' == $old_status ) {
     800            do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post );
     801        } else {
     802            // Record the post.
     803            bp_activity_post_type_publish( $post->ID, $post );
     804        }
     805
     806    // Unpublishing a previously published post.
     807    } else if ( 'publish' === $old_status ) {
     808        // Some form of pending status - only remove the activity entry
     809        bp_activity_post_type_unpublish( $post->ID, $post );
     810    }
     811}
     812add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 );
Note: See TracChangeset for help on using the changeset viewer.