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/tests/phpunit/testcases/blogs/functions.php

    r9139 r9194  
    299299
    300300        $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity (no change)' );
     301    }
     302
     303    /**
     304     * @group bp_blogs_catch_transition_post_status
     305     */
     306    public function test_transition_post_status_password_publish() {
     307        $post_id = $this->factory->post->create( array(
     308            'post_status'   => 'publish',
     309            'post_type'     => 'post',
     310            'post_password' => 'pass',
     311        ) );
     312        $post = get_post( $post_id );
     313
     314        // 'new' => 'publish with password'
     315        $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Published with password post should not have activity' );
     316    }
     317
     318    /**
     319     * @group bp_blogs_catch_transition_post_status
     320     */
     321    public function test_transition_post_status_publish_update_password() {
     322        $post_id = $this->factory->post->create( array(
     323            'post_status'   => 'publish',
     324            'post_type'     => 'post',
     325        ) );
     326        $post = get_post( $post_id );
     327
     328        // 'publish' => 'publish'
     329        $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' );
     330
     331        $post->post_content .= ' foo';
     332        $post->post_password = 'pass';
     333
     334        wp_update_post( $post );
     335
     336        $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Updated with password post should not have activity' );
     337    }
     338
     339    /**
     340     * @group bp_blogs_catch_transition_post_status
     341     */
     342    public function test_transition_post_status_private_publish() {
     343        $post_id = $this->factory->post->create( array(
     344            'post_status'   => 'private',
     345            'post_type'     => 'post',
     346        ) );
     347        $post = get_post( $post_id );
     348
     349        // 'new' => 'private'
     350        $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Private post should not have activity' );
     351
     352        $post->post_status = 'publish';
     353
     354        wp_update_post( $post );
     355
     356        // 'private' => 'publish'
     357        $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' );
     358    }
     359
     360    /**
     361     * @group bp_blogs_catch_transition_post_status
     362     */
     363    public function test_transition_post_status_publish_private() {
     364        $post_id = $this->factory->post->create( array(
     365            'post_status'   => 'publish',
     366            'post_type'     => 'post',
     367        ) );
     368        $post = get_post( $post_id );
     369
     370        // 'new' => 'publish'
     371        $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' );
     372
     373        $post->post_status = 'private';
     374
     375        wp_update_post( $post );
     376
     377        // 'publish' => 'private'
     378        $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Private post should not have activity' );
    301379    }
    302380
     
    478556    }
    479557
     558    /**
     559     * @group bp_blogs_catch_transition_post_status
     560     */
     561    public function test_bp_blogs_is_blog_trackable_false_publish_post() {
     562        add_filter( 'bp_blogs_is_blog_trackable', '__return_false' );
     563
     564        $post_id = $this->factory->post->create( array(
     565            'post_status'   => 'publish',
     566            'post_type'     => 'post',
     567        ) );
     568        $post = get_post( $post_id );
     569
     570        // 'new' => 'publish'
     571        $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Not trackable blog post should not have activity' );
     572
     573        $post->post_content .= ' foo';
     574
     575        wp_update_post( $post );
     576
     577        // 'publish' => 'publish'
     578        $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Not trackable blog post should not have activity' );
     579
     580        remove_filter( 'bp_blogs_is_blog_trackable', '__return_false' );
     581    }
     582
     583    /**
     584     * @group bp_blogs_catch_transition_post_status
     585     */
     586    public function test_bp_is_blog_public_zero_publish_post() {
     587        if ( ! is_multisite() ) {
     588            return;
     589        }
     590
     591        add_filter( 'bp_is_blog_public', '__return_zero' );
     592
     593        $post_id = $this->factory->post->create( array(
     594            'post_status'   => 'publish',
     595            'post_type'     => 'post',
     596        ) );
     597        $post = get_post( $post_id );
     598
     599        // 'new' => 'publish'
     600        $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Not public blog post should not have activity' );
     601
     602        $post->post_content .= ' foo';
     603
     604        wp_update_post( $post );
     605
     606        // 'publish' => 'publish'
     607        $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Not public blog post should not have activity' );
     608
     609        remove_filter( 'bp_is_blog_public', '__return_zero' );
     610    }
     611
    480612    protected function activity_exists_for_post( $post_id ) {
    481613        $a = bp_activity_get( array(
Note: See TracChangeset for help on using the changeset viewer.