Changeset 12395
- Timestamp:
- 05/11/2019 01:33:14 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-admin.php
r11907 r12395 841 841 842 842 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) { 843 /** 844 * Don't take in account: 845 * - a mis-named Friends activity type from before BP 1.6, 846 * - The Group's component 'activity_update' one as the Activity component is using it. 847 */ 848 if ( 'friends_register_activity_action' === $action[$i]['key'] || 'bp_groups_format_activity_action_group_activity_update' === $action[$i]['format_callback'] ) { 849 continue; 850 } 851 843 852 $actions[ $action[$i]['key'] ] = $action[$i]['value']; 844 853 } 845 854 } 846 855 847 // This was a mis-named activity type from before BP 1.6.848 unset( $actions['friends_register_activity_action'] );849 850 856 // Sort array by the human-readable value. 851 857 natsort( $actions ); … … 871 877 $action = array_values( (array) $action ); 872 878 873 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) 879 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) { 880 /** 881 * Don't take in account: 882 * - a mis-named Friends activity type from before BP 1.6, 883 * - The Group's component 'activity_update' one as the Activity component is using it. 884 */ 885 if ( 'friends_register_activity_action' === $action[$i]['key'] || 'bp_groups_format_activity_action_group_activity_update' === $action[$i]['format_callback'] ) { 886 continue; 887 } 888 874 889 $actions[ $action[$i]['key'] ] = $action[$i]['value']; 890 } 875 891 } 876 877 // This was a mis-named activity type from before BP 1.6.878 unset( $actions['friends_register_activity_action'] );879 892 880 893 // Sort array by the human-readable value. -
trunk/src/bp-activity/bp-activity-template.php
r11959 r12395 3849 3849 } 3850 3850 3851 // The 'activity_update' filter is already used by the Activity component. 3852 if ( 'bp_groups_format_activity_action_group_activity_update' === $action['format_callback'] ) { 3853 continue; 3854 } 3855 3851 3856 $filters[ $action['key'] ] = $action['label']; 3852 3857 } -
trunk/src/bp-activity/classes/class-bp-activity-list-table.php
r12331 r12395 436 436 } 437 437 438 // The 'activity_update' filter is already used by the Activity component. 439 if ( isset( $actions->activity_update ) && 'bp_groups_format_activity_action_group_activity_update' === $actions->activity_update['format_callback'] ) { 440 unset( $actions->activity_update ); 441 } 442 438 443 if ( bp_is_active( $component ) ) { 439 444 if ( $component === 'xprofile' ) { … … 456 461 457 462 // Skip the incorrectly named pre-1.6 action. 458 if ( 'friends_register_activity_action' !== $action_key ) : ?>463 if ( 'friends_register_activity_action' !== $action_key ) : ?> 459 464 460 465 <option value="<?php echo esc_attr( $action_key ); ?>" <?php selected( $action_key, $selected ); ?>><?php echo esc_html( $action_values[ 'value' ] ); ?></option> -
trunk/src/bp-groups/bp-groups-activity.php
r12393 r12395 55 55 ); 56 56 57 bp_activity_set_action( 58 $bp->groups->id, 59 'activity_update', 60 __( 'Posted a status update in a Group', 'buddypress' ), 61 'bp_groups_format_activity_action_group_activity_update', 62 __( 'Group Activity Updates', 'buddypress' ), 63 array( 'activity', 'group', 'member', 'member_groups' ) 64 ); 65 57 66 /** 58 67 * Fires at end of registration of the default activity actions for the Groups component. … … 63 72 } 64 73 add_action( 'bp_register_activity_actions', 'groups_register_activity_actions' ); 74 75 /** 76 * Get the group object the activity belongs to. 77 * 78 * @since 5.0.0 79 * 80 * @param integer $group_id The group ID the activity is linked to. 81 * @return BP_Groups_Group The group object the activity belongs to. 82 */ 83 function bp_groups_get_activity_group( $group_id = 0 ) { 84 // If displaying a specific group, check the activity belongs to it. 85 if ( bp_is_group() && bp_get_current_group_id() === (int) $group_id ) { 86 $group = groups_get_current_group(); 87 88 // Otherwise get the group the activity belongs to. 89 } else { 90 $group = groups_get_group( $group_id ); 91 } 92 93 return $group; 94 } 65 95 66 96 /** … … 76 106 $user_link = bp_core_get_userlink( $activity->user_id ); 77 107 78 $group = groups_get_group( $activity->item_id );108 $group = bp_groups_get_activity_group( $activity->item_id ); 79 109 $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>'; 80 110 … … 104 134 $user_link = bp_core_get_userlink( $activity->user_id ); 105 135 106 $group = groups_get_group( $activity->item_id );136 $group = bp_groups_get_activity_group( $activity->item_id ); 107 137 $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>'; 108 138 … … 143 173 $user_link = bp_core_get_userlink( $activity->user_id ); 144 174 145 $group = groups_get_group( $activity->item_id );175 $group = bp_groups_get_activity_group( $activity->item_id ); 146 176 $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>'; 147 177 … … 182 212 */ 183 213 return apply_filters( 'bp_groups_format_activity_action_joined_group', $action, $activity ); 214 } 215 216 /** 217 * Format the action for activity updates posted in a Group. 218 * 219 * @since 5.0.0 220 * 221 * @param string $action Static activity action. 222 * @param object $activity Activity data object. 223 * @return string The formatted action for activity updates posted in a Group. 224 */ 225 function bp_groups_format_activity_action_group_activity_update( $action, $activity ) { 226 $user_link = bp_core_get_userlink( $activity->user_id ); 227 $group = bp_groups_get_activity_group( $activity->item_id ); 228 229 $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>'; 230 231 // Set the Activity update posted in a Group action. 232 $action = sprintf( esc_html__( '%1$s posted an update in the group %2$s', 'buddypress' ), $user_link, $group_link ); 233 234 /** This filter is documented in wp-includes/deprecated.php */ 235 $action = apply_filters_deprecated( 'groups_activity_new_update_action', array( $action ), '5.0.0', 'bp_groups_format_activity_action_group_activity_update' ); 236 237 /** 238 * Filters the Group's activity update action. 239 * 240 * @since 5.0.0 241 * 242 * @param string $action The Group's activity update action. 243 * @param object $activity Activity data object. 244 */ 245 return apply_filters( 'bp_groups_format_activity_action_group_activity_update', $action, $activity ); 184 246 } 185 247 … … 441 503 // Set the default for hide_sitewide by checking the status of the group. 442 504 $hide_sitewide = false; 443 if ( !empty( $args['item_id'] ) ) { 444 if ( bp_get_current_group_id() == $args['item_id'] ) { 445 $group = groups_get_current_group(); 446 } else { 447 $group = groups_get_group( $args['item_id'] ); 448 } 505 if ( ! empty( $args['item_id'] ) ) { 506 $group = bp_groups_get_activity_group( $args['item_id'] ); 449 507 450 508 if ( isset( $group->status ) && 'public' != $group->status ) { … … 472 530 473 531 /** 532 * Post an Activity status update affiliated with a group. 533 * 534 * @since 1.2.0 535 * @since 2.6.0 Added 'error_type' parameter to $args. 536 * 537 * @param array|string $args { 538 * Array of arguments. 539 * @type string $content The content of the update. 540 * @type int $user_id Optional. ID of the user posting the update. Default: 541 * ID of the logged-in user. 542 * @type int $group_id Optional. ID of the group to be affiliated with the 543 * update. Default: ID of the current group. 544 * } 545 * @return WP_Error|bool|int Returns the ID of the new activity item on success, or false on failure. 546 */ 547 function groups_post_update( $args = '' ) { 548 $bp = buddypress(); 549 550 $r = bp_parse_args( $args, array( 551 'content' => false, 552 'user_id' => bp_loggedin_user_id(), 553 'group_id' => 0, 554 'error_type' => 'bool' 555 ), 'groups_post_update' ); 556 557 $group_id = (int) $r['group_id']; 558 if ( ! $group_id && ! empty( $bp->groups->current_group->id ) ) { 559 $group_id = (int) $bp->groups->current_group->id; 560 } 561 562 $content = $r['content']; 563 $user_id = (int) $r['user_id']; 564 if ( ! $content || ! strlen( trim( $content ) ) || ! $user_id || ! $group_id ) { 565 return false; 566 } 567 568 $bp->groups->current_group = groups_get_group( $group_id ); 569 570 // Be sure the user is a member of the group before posting. 571 if ( ! bp_current_user_can( 'bp_moderate' ) && ! groups_is_user_member( $user_id, $group_id ) ) { 572 return false; 573 } 574 575 /** 576 * Filters the content for the new group activity update. 577 * 578 * @since 1.2.0 579 * 580 * @param string $content The content of the update. 581 */ 582 $content_filtered = apply_filters( 'groups_activity_new_update_content', $content ); 583 584 $activity_id = groups_record_activity( array( 585 'user_id' => $user_id, 586 'content' => $content_filtered, 587 'type' => 'activity_update', 588 'item_id' => $group_id, 589 'error_type' => $r['error_type'], 590 ) ); 591 592 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); 593 594 /** 595 * Fires after posting of an Activity status update affiliated with a group. 596 * 597 * @since 1.2.0 598 * 599 * @param string $content The content of the update. 600 * @param int $user_id ID of the user posting the update. 601 * @param int $group_id ID of the group being posted to. 602 * @param bool $activity_id Whether or not the activity recording succeeded. 603 */ 604 do_action( 'bp_groups_posted_update', $content, $user_id, $group_id, $activity_id ); 605 606 return $activity_id; 607 } 608 609 /** 474 610 * Function used to determine if a user can comment on a group activity item. 475 611 * -
trunk/src/bp-groups/bp-groups-functions.php
r12393 r12395 1267 1267 } 1268 1268 1269 /** Group Activity Posting ****************************************************/1270 1271 /**1272 * Post an Activity status update affiliated with a group.1273 *1274 * @since 1.2.01275 * @since 2.6.0 Added 'error_type' parameter to $args.1276 *1277 * @param array|string $args {1278 * Array of arguments.1279 * @type string $content The content of the update.1280 * @type int $user_id Optional. ID of the user posting the update. Default:1281 * ID of the logged-in user.1282 * @type int $group_id Optional. ID of the group to be affiliated with the1283 * update. Default: ID of the current group.1284 * }1285 * @return WP_Error|bool|int Returns the ID of the new activity item on success, or false on failure.1286 */1287 function groups_post_update( $args = '' ) {1288 if ( ! bp_is_active( 'activity' ) ) {1289 return false;1290 }1291 1292 $bp = buddypress();1293 1294 $r = bp_parse_args( $args, array(1295 'content' => false,1296 'user_id' => bp_loggedin_user_id(),1297 'group_id' => 0,1298 'error_type' => 'bool'1299 ), 'groups_post_update' );1300 extract( $r, EXTR_SKIP );1301 1302 if ( empty( $group_id ) && !empty( $bp->groups->current_group->id ) )1303 $group_id = $bp->groups->current_group->id;1304 1305 if ( empty( $content ) || !strlen( trim( $content ) ) || empty( $user_id ) || empty( $group_id ) )1306 return false;1307 1308 $bp->groups->current_group = groups_get_group( $group_id );1309 1310 // Be sure the user is a member of the group before posting.1311 if ( !bp_current_user_can( 'bp_moderate' ) && !groups_is_user_member( $user_id, $group_id ) )1312 return false;1313 1314 // Record this in activity streams.1315 $activity_action = sprintf( esc_html__( '%1$s posted an update in the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . esc_url( bp_get_group_permalink( $bp->groups->current_group ) ) . '">' . esc_html( $bp->groups->current_group->name ) . '</a>' );1316 $activity_content = $content;1317 1318 /**1319 * Filters the action for the new group activity update.1320 *1321 * @since 1.2.01322 *1323 * @param string $activity_action The new group activity update.1324 */1325 $action = apply_filters( 'groups_activity_new_update_action', $activity_action );1326 1327 /**1328 * Filters the content for the new group activity update.1329 *1330 * @since 1.2.01331 *1332 * @param string $activity_content The content of the update.1333 */1334 $content_filtered = apply_filters( 'groups_activity_new_update_content', $activity_content );1335 1336 $activity_id = groups_record_activity( array(1337 'user_id' => $user_id,1338 'action' => $action,1339 'content' => $content_filtered,1340 'type' => 'activity_update',1341 'item_id' => $group_id,1342 'error_type' => $error_type1343 ) );1344 1345 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );1346 1347 /**1348 * Fires after posting of an Activity status update affiliated with a group.1349 *1350 * @since 1.2.01351 *1352 * @param string $content The content of the update.1353 * @param int $user_id ID of the user posting the update.1354 * @param int $group_id ID of the group being posted to.1355 * @param bool $activity_id Whether or not the activity recording succeeded.1356 */1357 do_action( 'bp_groups_posted_update', $content, $user_id, $group_id, $activity_id );1358 1359 return $activity_id;1360 }1361 1362 1269 /** Group Invitations *********************************************************/ 1363 1270 -
trunk/tests/phpunit/testcases/blogs/activity.php
r12311 r12395 728 728 * @group bp_blogs_sync_activity_edit_to_post_comment 729 729 * @group post_type_comment_activities 730 * @group imath731 730 */ 732 731 public function test_bp_blogs_sync_activity_edit_to_post_comment_trash_comment_ham_activity() { -
trunk/tests/phpunit/testcases/groups/activity.php
r12393 r12395 6 6 */ 7 7 class BP_Tests_Groups_Activity extends BP_UnitTestCase { 8 protected $groups_post_update_args; 9 8 10 /** 9 11 * @group activity_action … … 223 225 224 226 $this->set_current_user( $old_user ); 227 } 228 229 /** 230 * @group activity_action 231 * @group bp_groups_format_activity_action_group_activity_update 232 */ 233 public function test_bp_groups_format_activity_action_group_activity_update() { 234 $u = self::factory()->user->create(); 235 $g = self::factory()->group->create(); 236 $a = self::factory()->activity->create( array( 237 'component' => buddypress()->groups->id, 238 'type' => 'activity_update', 239 'user_id' => $u, 240 'item_id' => $g, 241 ) ); 242 243 $a_obj = new BP_Activity_Activity( $a ); 244 $g_obj = groups_get_group( $g ); 245 246 $expected = sprintf( esc_html__( '%1$s posted an update in the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_permalink( $g_obj ) ) . '">' . esc_html( $g_obj->name ) . '</a>' ); 247 248 $this->assertSame( $expected, $a_obj->action ); 249 } 250 251 /** 252 * @group groups_post_update 253 */ 254 public function test_groups_post_update() { 255 $u = self::factory()->user->create(); 256 $g = self::factory()->group->create(); 257 258 // The user is a group member. 259 groups_join_group( $g, $u ); 260 261 $activity_args = array( 262 'content' => 'Test group_post_update', 263 'user_id' => $u, 264 'group_id' => $g, 265 'error_type' => 'wp_error', 266 ); 267 268 add_filter( 'bp_before_groups_record_activity_parse_args', array( $this, 'groups_post_update_args' ), 10, 1 ); 269 270 groups_post_update( $activity_args ); 271 272 remove_filter( 'bp_before_groups_record_activity_parse_args', array( $this, 'groups_post_update_args' ), 10, 1 ); 273 274 $expected = array_merge( $activity_args, array( 'item_id' => $g ) ); 275 unset( $expected['group_id'] ); 276 277 $this->assertEquals( $expected, $this->groups_post_update_args ); 278 } 279 280 /** 281 * @group groups_post_update 282 */ 283 public function test_groups_post_update_in_group() { 284 $bp = buddypress(); 285 $u = self::factory()->user->create(); 286 $g = self::factory()->group->create(); 287 288 // The user is a group member. 289 groups_join_group( $g, $u ); 290 291 $bp->groups->current_group = groups_get_group( $g ); 292 293 $activity_args = array( 294 'content' => 'Test group_post_update in a group', 295 'user_id' => $u, 296 ); 297 298 $a = groups_post_update( $activity_args ); 299 $a_obj = new BP_Activity_Activity( $a ); 300 301 $this->assertSame( $a_obj->item_id, $g ); 302 $this->assertSame( $a_obj->component, 'groups' ); 303 304 unset( $bp->groups->current_group ); 225 305 } 226 306 … … 263 343 $this->set_current_user( $old_user ); 264 344 } 345 346 public function groups_post_update_args( $args = array() ) { 347 $this->groups_post_update_args = array_intersect_key( $args, array( 348 'content' => true, 349 'user_id' => true, 350 'item_id' => true, 351 'error_type' => true, 352 ) ); 353 354 return $args; 355 } 265 356 }
Note: See TracChangeset
for help on using the changeset viewer.