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-filters.php

    r8945 r9194  
    4343 * @since BuddyPress (2.1.0)
    4444 *
    45  * @see bp_blogs_update_post()
     45 * @see bp_blogs_update_post_activity_meta()
    4646 *
    4747 * @param array Current SQL clauses in array format
     
    5050function bp_blogs_comments_clauses_select_by_id( $retval ) {
    5151    $retval['fields'] = 'comment_ID';
    52    
     52
    5353    return $retval;
    5454}
     55
     56/**
     57 * Check whether the current post can be published.
     58 *
     59 * Abstracted from the deprecated `bp_blogs_record_post()`.
     60 *
     61 * @since BuddyPress (2.2.0)
     62 *
     63 * @param  bool $return  Whether the post should be published.
     64 * @param  int  $blog_id ID of the blog.
     65 * @param  int  $post_id ID of the post.
     66 * @param  int  $user_id ID of the post author.
     67 * @return bool True to authorize the post to be published, otherwise false.
     68 */
     69function bp_blogs_post_pre_publish( $return = true, $blog_id = 0, $post_id = 0, $user_id = 0 ) {
     70    $bp = buddypress();
     71
     72    // If blog is not trackable, do not record the activity.
     73    if ( ! bp_blogs_is_blog_trackable( $blog_id, $user_id ) ) {
     74        return false;
     75    }
     76
     77    /*
     78     * Stop infinite loops with WordPress MU Sitewide Tags.
     79     * That plugin changed the way its settings were stored at some point. Thus the dual check.
     80     */
     81    if ( ! empty( $bp->site_options['sitewide_tags_blog'] ) ) {
     82        $st_options = maybe_unserialize( $bp->site_options['sitewide_tags_blog'] );
     83        $tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0;
     84    } else {
     85        $tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0;
     86    }
     87
     88    if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) ) {
     89        return false;
     90    }
     91
     92    $is_blog_public = apply_filters( 'bp_is_blog_public', (int) get_blog_option( $blog_id, 'blog_public' ) );
     93
     94    if ( 0 === $is_blog_public && is_multisite() ) {
     95        return false;
     96    }
     97
     98    return $return;
     99}
     100add_filter( 'bp_activity_post_pre_publish', 'bp_blogs_post_pre_publish', 10, 4 );
Note: See TracChangeset for help on using the changeset viewer.