Ticket #6482: 6482.03b.patch
File 6482.03b.patch, 17.9 KB (added by , 8 years ago) |
---|
-
src/bp-activity/bp-activity-actions.php
797 797 if ( $new_status === $old_status ) { 798 798 // An edit of an existing post should update the existing activity item. 799 799 if ( $new_status == 'publish' ) { 800 bp_activity_post_type_update( $post ); 800 $edit = bp_activity_post_type_update( $post ); 801 802 // Post was never recorded into activity stream, so record it now! 803 if ( null === $edit ) { 804 bp_activity_post_type_publish( $post->ID, $post ); 805 } 801 806 } 802 807 803 808 return; -
src/bp-activity/bp-activity-functions.php
606 606 } 607 607 608 608 /** 609 * Helper function to check if the activity action is about a "parent" post type activity 610 * supporting comments tracking 609 * Check if a certain activity type supports a specific feature. 611 610 * 612 611 * @since 2.5.0 613 612 * 614 * @param string $action_id the activity action to check 615 * @return bool true if it's a parent post type activity supporting comments 616 * false otherwise 613 * @param string $activity_type The activity type to check. 614 * @param string $supports The feature to check. Currently supports: 615 * 'comment-tracking', 'post-comments'. See inline doc for more info. 616 * @return bool 617 617 */ 618 function bp_activity_action_is_post_tracking_action( $action_id ) { 619 if ( empty( $action_id ) ) { 620 return false; 621 } 618 function bp_activity_type_supports( $activity_type = '', $supports = '' ) { 619 $retval = false; 622 620 623 621 $bp = buddypress(); 624 622 625 $retval = bp_activity_action_supports_comments_tracking( $action_id ); 626 627 if ( empty( $retval ) ) { 628 return $retval; 629 } 630 631 return ! empty( $bp->activity->track[ $action_id ]->comment_action_id ); 632 } 623 switch ( $supports ) { 624 /** 625 * Does this activity type support comment tracking? 626 * 627 * eg. 'new_blog_post' and 'new_blog_comment' will both return true. 628 */ 629 case 'comment-tracking' : 630 // Set the activity track global if not set yet 631 if ( empty( $bp->activity->track ) ) { 632 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 633 } 633 634 634 /** 635 * Helper function to check if the activity action is supporting comments tracking 636 * 637 * @since 2.5.0 638 * 639 * @param string $action_id the activity action to check 640 * @return bool true activity action supports comments tracking 641 * false otherwise 642 */ 643 function bp_activity_action_supports_comments_tracking( $action_id ) { 644 if ( empty( $action_id ) ) { 645 return false; 646 } 635 if ( ! empty( $bp->activity->track[ $activity_type ]->comments_tracking ) ) { 636 $retval = true; 637 } 638 break; 647 639 648 $bp = buddypress(); 640 /** 641 * Is this a parent activity type that support post comments? 642 * 643 * eg. 'new_blog_post' will return true; 'new_blog_comment' will return false. 644 * 645 * Might need to rename 'post-comments' to something else... 646 */ 647 case 'post-comments' : 648 // Set the activity track global if not set yet 649 if ( empty( $bp->activity->track ) ) { 650 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 651 } 649 652 650 // Set the activity track global if not set yet 651 if ( empty( $bp->activity->track ) ) { 652 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 653 if ( ! empty( $bp->activity->track[ $activity_type ]->comments_tracking ) && ! empty( $bp->activity->track[ $activity_type ]->comment_action_id ) ) { 654 $retval = true; 655 } 656 break; 653 657 } 654 658 655 return ! empty( $bp->activity->track[ $action_id ]->comments_tracking );659 return $retval; 656 660 } 657 661 658 662 /** -
src/bp-blogs/bp-blogs-activity.php
18 18 * @return bool|null Returns false if activity component is not active. 19 19 */ 20 20 function bp_blogs_register_activity_actions() { 21 $bp = buddypress();22 23 // Bail if activity is not active.24 if ( ! bp_is_active( 'activity' ) ) {25 return false;26 }27 28 21 if ( is_multisite() ) { 29 22 bp_activity_set_action( 30 $bp->blogs->id,23 buddypress()->blogs->id, 31 24 'new_blog', 32 25 __( 'New site created', 'buddypress' ), 33 26 'bp_blogs_format_activity_action_new_blog', … … 47 40 add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' ); 48 41 49 42 /** 43 * Set up the tracking arguments for the 'post' post type. 44 * 45 * @since 2.5.0 This was moved out of the BP_Blogs_Component class. 46 * 47 * @see bp_activity_get_post_type_tracking_args() for information on parameters. 48 * 49 * @param object|null $params Tracking arguments. 50 * @param string|int $post_type Post type to track. 51 * @return object 52 */ 53 function bp_blogs_register_post_tracking_args( $params = null, $post_type = 0 ) { 54 55 /** 56 * Filters the post types to track for the Blogs component. 57 * 58 * @since 1.5.0 59 * @deprecated 2.3.0 60 * 61 * Make sure plugins still using 'bp_blogs_record_post_post_types' 62 * to track their post types will generate new_blog_post activities 63 * See https://buddypress.trac.wordpress.org/ticket/6306 64 * 65 * @param array $value Array of post types to track. 66 */ 67 $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ); 68 $post_types_array = array_flip( $post_types ); 69 70 if ( ! isset( $post_types_array[ $post_type ] ) ) { 71 return $params; 72 } 73 74 // Set specific params for the 'post' post type. 75 $params->component_id = buddypress()->blogs->id; 76 $params->action_id = 'new_blog_post'; 77 $params->admin_filter = __( 'New post published', 'buddypress' ); 78 $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post'; 79 $params->front_filter = __( 'Posts', 'buddypress' ); 80 $params->contexts = array( 'activity', 'member' ); 81 $params->position = 5; 82 83 if ( post_type_supports( $post_type, 'comments' ) ) { 84 $params->comment_action_id = 'new_blog_comment'; 85 86 /** 87 * Filters the post types to track for the Blogs component. 88 * 89 * @since 1.5.0 90 * @deprecated 2.5.0 91 * 92 * Make sure plugins still using 'bp_blogs_record_comment_post_types' 93 * to track comment about their post types will generate new_blog_comment activities 94 * See https://buddypress.trac.wordpress.org/ticket/6306 95 * 96 * @param array $value Array of post types to track. 97 */ 98 $comment_post_types = apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) ); 99 $comment_post_types_array = array_flip( $comment_post_types ); 100 101 if ( isset( $comment_post_types_array[ $post_type ] ) ) { 102 $params->comments_tracking = new stdClass(); 103 $params->comments_tracking->component_id = buddypress()->blogs->id; 104 $params->comments_tracking->action_id = 'new_blog_comment'; 105 $params->comments_tracking->admin_filter = __( 'New post comment posted', 'buddypress' ); 106 $params->comments_tracking->format_callback = 'bp_blogs_format_activity_action_new_blog_comment'; 107 $params->comments_tracking->front_filter = __( 'Comments', 'buddypress' ); 108 $params->comments_tracking->contexts = array( 'activity', 'member' ); 109 $params->comments_tracking->position = 10; 110 } 111 } 112 113 return $params; 114 } 115 add_filter( 'bp_activity_get_post_type_tracking_args', 'bp_blogs_register_post_tracking_args', 10, 2 ); 116 117 /** 50 118 * Format 'new_blog' activity actions. 51 119 * 52 120 * @since 2.0.0 … … 370 438 * @return int|bool On success, returns the activity ID. False on failure. 371 439 */ 372 440 function bp_blogs_record_activity( $args = '' ) { 373 374 // Bail if activity is not active.375 if ( ! bp_is_active( 'activity' ) ) {376 return false;377 }378 379 $bp = buddypress();380 381 441 $defaults = array( 382 442 'user_id' => bp_loggedin_user_id(), 383 443 'action' => '', 384 444 'content' => '', 385 445 'primary_link' => '', 386 'component' => $bp->blogs->id,446 'component' => buddypress()->blogs->id, 387 447 'type' => false, 388 448 'item_id' => false, 389 449 'secondary_item_id' => false, … … 447 507 * @return bool True on success, false on failure. 448 508 */ 449 509 function bp_blogs_delete_activity( $args = '' ) { 450 451 // Bail if activity is not active.452 if ( ! bp_is_active( 'activity' ) ) {453 return false;454 }455 456 510 $r = bp_parse_args( $args, array( 457 511 'item_id' => false, 458 512 'component' => buddypress()->blogs->id, … … 570 624 */ 571 625 function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) { 572 626 // if parent activity isn't a post type having the buddypress-activity support, stop now! 573 if ( ! bp_activity_ action_supports_comments_tracking( $parent_activity->type) ) {627 if ( ! bp_activity_type_supports( $parent_activity->type, 'comment-tracking' ) ) { 574 628 return; 575 629 } 576 630 … … 688 742 $parent_activity = new BP_Activity_Activity( $parent_activity_id ); 689 743 690 744 // if parent activity isn't a post type having the buddypress-activity support, stop now! 691 if ( ! bp_activity_ action_supports_comments_tracking( $parent_activity->type) ) {745 if ( ! bp_activity_type_supports( $parent_activity->type, 'comment-tracking' ) ) { 692 746 return $retval; 693 747 } 694 748 … … 744 798 $parent_activity = new BP_Activity_Activity( $activity->item_id ); 745 799 746 800 // if parent activity isn't a post type having the buddypress-activity support for comments, stop now! 747 if ( ! bp_activity_ action_supports_comments_tracking( $parent_activity->type) ) {801 if ( ! bp_activity_type_supports( $parent_activity->type, 'comment-tracking' ) ) { 748 802 return; 749 803 } 750 804 … … 834 888 * powers the 'Comments' filter in the activity directory dropdown) includes 835 889 * both old-style and new-style activity comments. 836 890 * 837 * This implementation involves filtering the activity queries directly, and838 * should be considered a stopgap. The proper solution would involve enabling839 * multiple query condition clauses, connected by an OR, in the bp_has_activities()840 * API.841 *842 891 * @since 2.1.0 843 892 * @since 2.5.0 Used for any synced Post type comments, in wp-admin or front-end contexts. 844 893 * … … 849 898 global $wpdb; 850 899 $bp = buddypress(); 851 900 852 // if activity comments are disabled for blog posts, stop now!901 // If activity comments are disabled for blog posts, stop now! 853 902 if ( bp_disable_blogforum_comments() ) { 854 903 return $args; 855 904 } … … 934 983 } 935 984 936 985 // parent not a post post type action ? stop now! 937 if ( ! bp_activity_ action_is_post_tracking_action( $activity->type) ) {986 if ( ! bp_activity_type_supports( $activity->type, 'post-comments' ) ) { 938 987 return; 939 988 } 940 989 … … 1016 1065 return $retval; 1017 1066 } 1018 1067 1019 $ action = bp_get_activity_action_name();1068 $type = bp_get_activity_type(); 1020 1069 1021 // It's a post type action supporting comment tracking1022 if ( bp_activity_ action_supports_comments_tracking( $action) ) {1070 // It's a post type supporting comment tracking. 1071 if ( bp_activity_type_supports( $type, 'comment-tracking' ) ) { 1023 1072 // it's a "post" action 1024 if ( bp_activity_ action_is_post_tracking_action( $action) ) {1073 if ( bp_activity_type_supports( $type, 'post-comments' ) ) { 1025 1074 global $activities_template; 1026 1075 1027 1076 // Setup some globals we'll need to reference later. … … 1187 1236 return $retval; 1188 1237 } 1189 1238 1190 $bp = buddypress();1191 1239 $blog_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' ); 1192 1240 1193 1241 if ( ! empty( $blog_comment_id ) ) { 1242 $bp = buddypress(); 1243 1194 1244 // Fetch the parent blog post activity item. 1195 1245 $parent_blog_post_activity = new BP_Activity_Activity( $activity->item_id ); 1196 1246 -
src/bp-blogs/bp-blogs-loader.php
106 106 add_post_type_support( $post_type, 'buddypress-activity' ); 107 107 } 108 108 } 109 110 // Filter the generic track parameters for the 'post' post type.111 add_filter( 'bp_activity_get_post_type_tracking_args', array( $this, 'post_tracking_args' ), 10, 2 );112 109 } 113 110 114 111 /** … … 128 125 'classes', 129 126 'template', 130 127 'filters', 131 'activity',132 128 'functions', 133 129 ); 134 130 131 if ( bp_is_active( 'activity' ) ) { 132 $includes[] = 'activity'; 133 } 134 135 135 if ( is_multisite() ) { 136 136 $includes[] = 'widgets'; 137 137 } … … 300 300 301 301 parent::setup_cache_groups(); 302 302 } 303 304 /**305 * Set up the tracking arguments for the 'post' post type.306 *307 * @since 2.2.0308 *309 * @see bp_activity_get_post_type_tracking_args() for information on parameters.310 *311 * @param object|null $params Tracking arguments.312 * @param string|int $post_type Post type to track.313 * @return object314 */315 public function post_tracking_args( $params = null, $post_type = 0 ) {316 317 /**318 * Filters the post types to track for the Blogs component.319 *320 * @since 1.5.0321 * @deprecated 2.3.0322 *323 * Make sure plugins still using 'bp_blogs_record_post_post_types'324 * to track their post types will generate new_blog_post activities325 * See https://buddypress.trac.wordpress.org/ticket/6306326 *327 * @param array $value Array of post types to track.328 */329 $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) );330 $post_types_array = array_flip( $post_types );331 332 if ( ! isset( $post_types_array[ $post_type ] ) ) {333 return $params;334 }335 336 // Set specific params for the 'post' post type.337 $params->component_id = $this->id;338 $params->action_id = 'new_blog_post';339 $params->admin_filter = __( 'New post published', 'buddypress' );340 $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post';341 $params->front_filter = __( 'Posts', 'buddypress' );342 $params->contexts = array( 'activity', 'member' );343 $params->position = 5;344 345 if ( post_type_supports( $post_type, 'comments' ) ) {346 $params->comment_action_id = 'new_blog_comment';347 348 /**349 * Filters the post types to track for the Blogs component.350 *351 * @since 1.5.0352 * @deprecated 2.5.0353 *354 * Make sure plugins still using 'bp_blogs_record_comment_post_types'355 * to track comment about their post types will generate new_blog_comment activities356 * See https://buddypress.trac.wordpress.org/ticket/6306357 *358 * @param array $value Array of post types to track.359 */360 $comment_post_types = apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) );361 $comment_post_types_array = array_flip( $comment_post_types );362 363 if ( isset( $comment_post_types_array[ $post_type ] ) ) {364 $params->comments_tracking = new stdClass();365 $params->comments_tracking->component_id = $this->id;366 $params->comments_tracking->action_id = 'new_blog_comment';367 $params->comments_tracking->admin_filter = __( 'New post comment posted', 'buddypress' );368 $params->comments_tracking->format_callback = 'bp_blogs_format_activity_action_new_blog_comment';369 $params->comments_tracking->front_filter = __( 'Comments', 'buddypress' );370 $params->comments_tracking->contexts = array( 'activity', 'member' );371 $params->comments_tracking->position = 10;372 }373 }374 375 return $params;376 }377 303 } 378 304 379 305 /** -
tests/phpunit/testcases/activity/actions.php
49 49 // 'new' => 'publish' 50 50 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 51 51 52 // Delete the activity53 bp_activity_post_type_unpublish( $post_id, $post );54 55 $post->post_status = 'publish';56 $post->post_content .= ' foo';57 58 wp_update_post( $post );59 60 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Updating a post type should not create a new activity' );61 62 52 _unregister_post_type( 'foo' ); 63 53 } 64 54 … … 123 113 _unregister_post_type( 'foo' ); 124 114 } 125 115 116 /** 117 * @group bp_activity_catch_transition_post_type_status 118 * @group activity_tracking 119 */ 120 public function test_bp_activity_catch_transition_post_type_status_publish_existing_post() { 121 $u = $this->factory->user->create(); 122 123 $labels = array( 124 'bp_activity_admin_filter' => 'New Foo', 125 'bp_activity_front_filter' => 'Foos', 126 'bp_activity_new_post' => '%1$s posted a new <a href="%2$s">foo</a>', 127 'bp_activity_new_post_ms' => '%1$s posted a new <a href="%2$s">foo</a>, on the site %3$s', 128 ); 129 130 /** 131 * 'public' must be set to true, otherwise bp_activity_get_post_types_tracking_args() fails. 132 */ 133 register_post_type( 'foo', array( 134 'labels' => $labels, 135 'public' => true, 136 'supports' => array( 'buddypress-activity' ), 137 'bp_activity' => array( 138 'action_id' => 'new_foo', 139 'contexts' => array( 'activity' ), 140 'position' => 40, 141 ) 142 ) ); 143 144 // Temporarily remove post type activity hook so activity item isn't created. 145 remove_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 ); 146 147 // Create the initial post. 148 $p = $this->factory->post->create( array( 149 'post_author' => $u, 150 'post_type' => 'foo', 151 ) ); 152 153 $this->assertEmpty( bp_activity_get_activity_id( array( 'type' => 'new_foo' ) ) ); 154 155 // Add the post type activity hook back. 156 add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 ); 157 158 // Emulate updating a post; this should create an activity item. 159 wp_update_post( array( 160 'ID' => $p, 161 'post_title' => 'This is an edit', 162 ) ); 163 164 // Assert! 165 $this->assertNotEmpty( bp_activity_get_activity_id( array( 'type' => 'new_foo' ) ), 'Activity item was not created during an edit of an existing WordPress post.' ); 166 167 // Clean up. 168 _unregister_post_type( 'foo' ); 169 } 170 126 171 protected function activity_exists_for_post( $post_id, $action ) { 127 172 $a = bp_activity_get( array( 128 173 'action' => $action,