Ticket #8089: 8089.patch
File 8089.patch, 15.5 KB (added by , 6 years ago) |
---|
-
src/bp-activity/bp-activity-admin.php
diff --git src/bp-activity/bp-activity-admin.php src/bp-activity/bp-activity-admin.php index ab68de61b..0eb1e610a 100644
function bp_activity_admin_get_activity_actions() { 840 840 $action = array_values( (array) $action ); 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 ); 852 858 … … function bp_activity_admin_edit_metabox_type( $item ) { 870 876 foreach ( bp_activity_get_actions() as $action ) { 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 892 877 // This was a mis-named activity type from before BP 1.6.878 unset( $actions['friends_register_activity_action'] );879 880 893 // Sort array by the human-readable value. 881 894 natsort( $actions ); 882 895 -
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index be1e48b40..fc0e82a76 100644
function bp_activity_show_filters( $context = '' ) { 3848 3848 $action['key'] = 'friendship_accepted,friendship_created'; 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 } 3853 3858 -
src/bp-activity/classes/class-bp-activity-list-table.php
diff --git src/bp-activity/classes/class-bp-activity-list-table.php src/bp-activity/classes/class-bp-activity-list-table.php index e7d023969..1538d2140 100644
class BP_Activity_List_Table extends WP_List_Table { 435 435 $component = 'xprofile'; 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' ) { 440 445 $component_name = buddypress()->profile->name; … … class BP_Activity_List_Table extends WP_List_Table { 455 460 <?php 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> 461 466 -
src/bp-groups/bp-groups-activity.php
diff --git src/bp-groups/bp-groups-activity.php src/bp-groups/bp-groups-activity.php index 85d2a8fc8..a2403257d 100644
function groups_register_activity_actions() { 54 54 array( 'activity', 'group', 'member', 'member_groups' ) 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. 59 68 * … … function groups_register_activity_actions() { 63 72 } 64 73 add_action( 'bp_register_activity_actions', 'groups_register_activity_actions' ); 65 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 } 95 66 96 /** 67 97 * Format 'created_group' activity actions. 68 98 * … … add_action( 'bp_register_activity_actions', 'groups_register_activity_actions' ) 75 105 function bp_groups_format_activity_action_created_group( $action, $activity ) { 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 81 111 $action = sprintf( __( '%1$s created the group %2$s', 'buddypress'), $user_link, $group_link ); … … function bp_groups_format_activity_action_created_group( $action, $activity ) { 103 133 function bp_groups_format_activity_action_joined_group( $action, $activity ) { 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 109 139 $action = sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), $user_link, $group_link ); … … function bp_groups_format_activity_action_joined_group( $action, $activity ) { 142 172 function bp_groups_format_activity_action_group_details_updated( $action, $activity ) { 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 148 178 /* … … function bp_groups_format_activity_action_group_details_updated( $action, $activ 183 213 return apply_filters( 'bp_groups_format_activity_action_joined_group', $action, $activity ); 184 214 } 185 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 ); 246 } 247 186 248 /** 187 249 * Fetch data related to groups at the beginning of an activity loop. 188 250 * … … function groups_record_activity( $args = '' ) { 440 502 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 ) { 451 509 $hide_sitewide = true; … … function groups_record_activity( $args = '' ) { 470 528 return bp_activity_add( $r ); 471 529 } 472 530 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 extract( $r, EXTR_SKIP ); 557 558 if ( empty( $group_id ) && !empty( $bp->groups->current_group->id ) ) 559 $group_id = $bp->groups->current_group->id; 560 561 if ( empty( $content ) || !strlen( trim( $content ) ) || empty( $user_id ) || empty( $group_id ) ) 562 return false; 563 564 $bp->groups->current_group = groups_get_group( $group_id ); 565 566 // Be sure the user is a member of the group before posting. 567 if ( !bp_current_user_can( 'bp_moderate' ) && !groups_is_user_member( $user_id, $group_id ) ) 568 return false; 569 570 // Record this in activity streams. 571 $activity_content = $content; 572 573 /** 574 * Filters the content for the new group activity update. 575 * 576 * @since 1.2.0 577 * 578 * @param string $activity_content The content of the update. 579 */ 580 $content_filtered = apply_filters( 'groups_activity_new_update_content', $activity_content ); 581 582 $activity_id = groups_record_activity( array( 583 'user_id' => $user_id, 584 'content' => $content_filtered, 585 'type' => 'activity_update', 586 'item_id' => $group_id, 587 'error_type' => $error_type 588 ) ); 589 590 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); 591 592 /** 593 * Fires after posting of an Activity status update affiliated with a group. 594 * 595 * @since 1.2.0 596 * 597 * @param string $content The content of the update. 598 * @param int $user_id ID of the user posting the update. 599 * @param int $group_id ID of the group being posted to. 600 * @param bool $activity_id Whether or not the activity recording succeeded. 601 */ 602 do_action( 'bp_groups_posted_update', $content, $user_id, $group_id, $activity_id ); 603 604 return $activity_id; 605 } 606 473 607 /** 474 608 * Function used to determine if a user can comment on a group activity item. 475 609 * -
src/bp-groups/bp-groups-functions.php
diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php index 43240122a..b391afd76 100644
function groups_is_user_creator( $user_id, $group_id ) { 1266 1266 return BP_Groups_Member::check_is_creator( $user_id, $group_id ); 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( __( '%1$s posted an update in the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $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 1364 1271 /**