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

    r8662 r9194  
    7676        // Setup the globals
    7777        parent::setup_globals( $args );
     78
     79        /*
     80         * Set up the post post type to track.
     81         *
     82         * In case the config is not multisite, the blog_public option is ignored.
     83         */
     84        if ( 0 !== (int) get_option( 'blog_public' ) || ! is_multisite() ) {
     85            // Get all posts to track.
     86            $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) );
     87
     88            foreach ( $post_types as $post_type ) {
     89                add_post_type_support( $post_type, 'buddypress-activity' );
     90            }
     91        }
     92
     93        // Filter the generic track parameters for the 'post' post type.
     94        add_filter( 'bp_activity_get_post_type_tracking_args', array( $this, 'post_tracking_args' ), 10, 2 );
    7895    }
    7996
     
    247264        parent::setup_title();
    248265    }
     266
     267    /**
     268     * Set up the tracking arguments for the 'post' post type.
     269     *
     270     * @since BuddyPress (2.2.0)
     271     *
     272     * @see bp_activity_get_post_type_tracking_args() for information on parameters.
     273     */
     274    public function post_tracking_args( $params = array(), $post_type = 0 ) {
     275        if ( 'post' != $post_type ) {
     276            return $params;
     277        }
     278
     279        // Set specific params for the 'post' post type.
     280        $params->component_id    = $this->id;
     281        $params->action_id       = 'new_blog_post';
     282        $params->admin_filter    = __( 'New post published', 'buddypress' );
     283        $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post';
     284        $params->front_filter    = __( 'Posts', 'buddypress' );
     285        $params->contexts        = array( 'activity', 'member' );
     286        $params->position        = 5;
     287
     288        return $params;
     289    }
    249290}
    250291
Note: See TracChangeset for help on using the changeset viewer.