Ticket #5266: 5266.groups.patch
File 5266.groups.patch, 42.1 KB (added by , 12 years ago) |
---|
-
plugins/buddypress/bp-groups/bp-groups-activity.php
diff --git a/plugins/buddypress/bp-groups/bp-groups-activity.php b/plugins/buddypress/bp-groups/bp-groups-activity.php index 479790e..324064c 100644
a b 59 59 * @return bool See {@link bp_activity_add()}. 60 60 */ 61 61 function groups_record_activity( $args = '' ) { 62 global $bp;63 62 64 if ( ! bp_is_active( 'activity' ) )63 if ( ! bp_is_active( 'activity' ) ) { 65 64 return false; 65 } 66 66 67 67 // Set the default for hide_sitewide by checking the status of the group 68 68 $hide_sitewide = false; … … 78 78 } 79 79 } 80 80 81 $ defaults = array(81 $r = wp_parse_args( $args, array( 82 82 'id' => false, 83 83 'user_id' => bp_loggedin_user_id(), 84 84 'action' => '', 85 85 'content' => '', 86 86 'primary_link' => '', 87 'component' => $bp->groups->id,87 'component' => buddypress()->groups->id, 88 88 'type' => false, 89 89 'item_id' => false, 90 90 'secondary_item_id' => false, 91 91 'recorded_time' => bp_core_current_time(), 92 92 'hide_sitewide' => $hide_sitewide 93 ) ;93 ) ); 94 94 95 $r = wp_parse_args( $args, $defaults ); 96 extract( $r ); 97 98 return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) ); 95 return bp_activity_add( $r ); 99 96 } 100 97 101 98 /** … … 105 102 * being updated. Default: the current group's ID. 106 103 */ 107 104 function groups_update_last_activity( $group_id = 0 ) { 108 global $bp;109 105 110 if ( empty( $group_id ) ) 111 $group_id = $bp->groups->current_group->id; 106 if ( empty( $group_id ) ) { 107 $group_id = buddypress()->groups->current_group->id; 108 } 112 109 113 if ( empty( $group_id ) ) 110 if ( empty( $group_id ) ) { 114 111 return false; 112 } 115 113 116 114 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); 117 115 } … … 120 118 add_action( 'groups_new_forum_topic', 'groups_update_last_activity' ); 121 119 add_action( 'groups_new_forum_topic_post', 'groups_update_last_activity' ); 122 120 123 function groups_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { 121 /** 122 * Add an activity stream item when a member joins a group 123 * 124 * @since BuddyPress (1.9.0) 125 * @param int $user_id 126 * @param int $group_id 127 */ 128 function bp_groups_membership_accepted_add_activity( $user_id, $group_id ) { 124 129 125 switch ( $action ) { 126 case 'new_membership_request': 127 $group_id = $secondary_item_id; 128 $requesting_user_id = $item_id; 129 130 $group = groups_get_group( array( 'group_id' => $group_id ) ); 131 $group_link = bp_get_group_permalink( $group ); 132 133 // Set up the string and the filter 134 // Because different values are passed to the filters, we'll return the 135 // values inline 136 if ( (int) $total_items > 1 ) { 137 $text = sprintf( __( '%1$d new membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name ); 138 $filter = 'bp_groups_multiple_new_membership_requests_notification'; 139 $notification_link = $group_link . 'admin/membership-requests/?n=1'; 140 141 if ( 'string' == $format ) { 142 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Group Membership Requests', 'buddypress' ) . '">' . $text . '</a>', $group_link, $total_items, $group->name, $text, $notification_link ); 143 } else { 144 return apply_filters( $filter, array( 145 'link' => $notification_link, 146 'text' => $text 147 ), $group_link, $total_items, $group->name, $text, $notification_link ); 148 } 149 } else { 150 $user_fullname = bp_core_get_user_displayname( $requesting_user_id ); 151 $text = sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname ); 152 $filter = 'bp_groups_single_new_membership_request_notification'; 153 $notification_link = $group_link . 'admin/membership-requests/?n=1'; 154 155 if ( 'string' == $format ) { 156 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname ) . '">' . $text . '</a>', $group_link, $user_fullname, $group->name, $text, $notification_link ); 157 } else { 158 return apply_filters( $filter, array( 159 'link' => $notification_link, 160 'text' => $text 161 ), $group_link, $user_fullname, $group->name, $text, $notification_link ); 162 } 163 } 164 165 break; 166 167 case 'membership_request_accepted': 168 $group_id = $item_id; 169 170 $group = groups_get_group( array( 'group_id' => $group_id ) ); 171 $group_link = bp_get_group_permalink( $group ); 172 173 if ( (int) $total_items > 1 ) { 174 $text = sprintf( __( '%d accepted group membership requests', 'buddypress' ), (int) $total_items, $group->name ); 175 $filter = 'bp_groups_multiple_membership_request_accepted_notification'; 176 $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1'; 177 178 if ( 'string' == $format ) { 179 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $group->name, $text, $notification_link ); 180 } else { 181 return apply_filters( $filter, array( 182 'link' => $notification_link, 183 'text' => $text 184 ), $total_items, $group->name, $text, $notification_link ); 185 } 186 } else { 187 $text = sprintf( __( 'Membership for group "%s" accepted', 'buddypress' ), $group->name ); 188 $filter = 'bp_groups_single_membership_request_accepted_notification'; 189 $notification_link = $group_link . '?n=1'; 190 191 if ( 'string' == $format ) { 192 return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link ); 193 } else { 194 return apply_filters( $filter, array( 195 'link' => $notification_link, 196 'text' => $text 197 ), $group_link, $group->name, $text, $notification_link ); 198 } 199 } 200 201 break; 202 203 case 'membership_request_rejected': 204 $group_id = $item_id; 205 206 $group = groups_get_group( array( 'group_id' => $group_id ) ); 207 $group_link = bp_get_group_permalink( $group ); 208 209 if ( (int) $total_items > 1 ) { 210 $text = sprintf( __( '%d rejected group membership requests', 'buddypress' ), (int) $total_items, $group->name ); 211 $filter = 'bp_groups_multiple_membership_request_rejected_notification'; 212 $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1'; 213 214 if ( 'string' == $format ) { 215 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $group->name ); 216 } else { 217 return apply_filters( $filter, array( 218 'link' => $notification_link, 219 'text' => $text 220 ), $total_items, $group->name, $text, $notification_link ); 221 } 222 } else { 223 $text = sprintf( __( 'Membership for group "%s" rejected', 'buddypress' ), $group->name ); 224 $filter = 'bp_groups_single_membership_request_rejected_notification'; 225 $notification_link = $group_link . '?n=1'; 226 227 if ( 'string' == $format ) { 228 return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link ); 229 } else { 230 return apply_filters( $filter, array( 231 'link' => $notification_link, 232 'text' => $text 233 ), $group_link, $group->name, $text, $notification_link ); 234 } 235 } 236 237 break; 238 239 case 'member_promoted_to_admin': 240 $group_id = $item_id; 241 242 $group = groups_get_group( array( 'group_id' => $group_id ) ); 243 $group_link = bp_get_group_permalink( $group ); 244 245 if ( (int) $total_items > 1 ) { 246 $text = sprintf( __( 'You were promoted to an admin in %d groups', 'buddypress' ), (int) $total_items ); 247 $filter = 'bp_groups_multiple_member_promoted_to_admin_notification'; 248 $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1'; 249 250 if ( 'string' == $format ) { 251 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link ); 252 } else { 253 return apply_filters( $filter, array( 254 'link' => $notification_link, 255 'text' => $text 256 ), $total_items, $text, $notification_link ); 257 } 258 } else { 259 $text = sprintf( __( 'You were promoted to an admin in the group "%s"', 'buddypress' ), $group->name ); 260 $filter = 'bp_groups_single_member_promoted_to_admin_notification'; 261 $notification_link = $group_link . '?n=1'; 262 263 if ( 'string' == $format ) { 264 return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link ); 265 } else { 266 return apply_filters( $filter, array( 267 'link' => $notification_link, 268 'text' => $text 269 ), $group_link, $group->name, $text, $notification_link ); 270 } 271 } 272 273 break; 274 275 case 'member_promoted_to_mod': 276 $group_id = $item_id; 277 278 $group = groups_get_group( array( 'group_id' => $group_id ) ); 279 $group_link = bp_get_group_permalink( $group ); 280 281 if ( (int) $total_items > 1 ) { 282 $text = sprintf( __( 'You were promoted to a mod in %d groups', 'buddypress' ), (int) $total_items ); 283 $filter = 'bp_groups_multiple_member_promoted_to_mod_notification'; 284 $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1'; 285 286 if ( 'string' == $format ) { 287 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link ); 288 } else { 289 return apply_filters( $filter, array( 290 'link' => $notification_link, 291 'text' => $text 292 ), $total_items, $text, $notification_link ); 293 } 294 } else { 295 $text = sprintf( __( 'You were promoted to a mod in the group "%s"', 'buddypress' ), $group->name ); 296 $filter = 'bp_groups_single_member_promoted_to_mod_notification'; 297 $notification_link = $group_link . '?n=1'; 298 299 if ( 'string' == $format ) { 300 return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link ); 301 } else { 302 return apply_filters( $filter, array( 303 'link' => $notification_link, 304 'text' => $text 305 ), $group_link, $group->name, $text, $notification_link ); 306 } 307 } 308 309 break; 310 311 case 'group_invite': 312 $group_id = $item_id; 313 $group = groups_get_group( array( 'group_id' => $group_id ) ); 314 $group_link = bp_get_group_permalink( $group ); 315 316 $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/?n=1'; 317 318 if ( (int) $total_items > 1 ) { 319 $text = sprintf( __( 'You have %d new group invitations', 'buddypress' ), (int) $total_items ); 320 $filter = 'bp_groups_multiple_group_invite_notification'; 321 322 if ( 'string' == $format ) { 323 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Group Invites', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link ); 324 } else { 325 return apply_filters( $filter, array( 326 'link' => $notification_link, 327 'text' => $text 328 ), $total_items, $text, $notification_link ); 329 } 330 } else { 331 $text = sprintf( __( 'You have an invitation to the group: %s', 'buddypress' ), $group->name ); 332 $filter = 'bp_groups_single_group_invite_notification'; 333 334 if ( 'string' == $format ) { 335 return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link ); 336 } else { 337 return apply_filters( $filter, array( 338 'link' => $notification_link, 339 'text' => $text 340 ), $group_link, $group->name, $text, $notification_link ); 341 } 342 } 343 344 break; 130 // Bail if Activity is not active 131 if ( ! bp_is_active( 'activity' ) ) { 132 return false; 345 133 } 346 134 347 do_action( 'groups_format_notifications', $action, $item_id, $secondary_item_id, $total_items ); 135 // Get the group so we can get it's name 136 $group = groups_get_group( array( 'group_id' => $group_id ) ); 348 137 349 return false; 138 // Record in activity streams 139 groups_record_activity( array( 140 'action' => apply_filters_ref_array( 'groups_activity_membership_accepted_action', array( sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $user_id, &$group ) ), 141 'type' => 'joined_group', 142 'item_id' => $group_id, 143 'user_id' => $user_id 144 ) ); 350 145 } 146 add_action( 'groups_membership_accepted', 'bp_groups_membership_accepted_add_activity', 10, 2 ); 147 148 /** 149 * Delete all group activity from activity streams 150 * 151 * @since BuddyPress (1.9.0) 152 */ 153 function bp_groups_delete_group_delete_all_activity( $group_id ) { 154 if ( bp_is_active( 'activity' ) ) { 155 bp_activity_delete_by_item_id( array( 156 'item_id' => $group_id, 157 'component' => buddypress()->groups->id 158 ) ); 159 } 160 } 161 add_action( 'groups_delete_group', 'bp_groups_delete_group_delete_all_activity', 10 ); 162 163 /** 164 * Delete group member activity if they leave or are removed within 5 minutes of 165 * membership modification. 166 * 167 * If the user joined this group less than five minutes ago, remove the 168 * joined_group activity so users cannot flood the activity stream by 169 * joining/leaving the group in quick succession. 170 * 171 * @since BuddyPress (1.9.0) 172 */ 173 function bp_groups_leave_group_delete_recent_activity( $group_id, $user_id ) { 174 175 // Bail if Activity component is not active 176 if ( ! bp_is_active( 'activity' ) ) { 177 return; 178 } 179 180 // Get the member's group membership information 181 $membership = new BP_Groups_Member( $user_id, $group_id ); 182 183 // Check the time period, and maybe delete their recent group activity 184 if ( time() <= strtotime( '+5 minutes', (int) strtotime( $membership->date_modified ) ) ) { 185 bp_activity_delete( array( 186 'component' => buddypress()->groups->id, 187 'type' => 'joined_group', 188 'user_id' => $user_id, 189 'item_id' => $group_id 190 ) ); 191 } 192 } 193 add_action( 'groups_leave_group', 'bp_groups_leave_group_delete_recent_activity', 10, 2 ); 194 add_action( 'groups_remove_member', 'bp_groups_leave_group_delete_recent_activity', 10, 2 ); 195 add_action( 'groups_ban_member', 'bp_groups_leave_group_delete_recent_activity', 10, 2 ); 196 No newline at end of file -
plugins/buddypress/bp-groups/bp-groups-forums.php
diff --git a/plugins/buddypress/bp-groups/bp-groups-forums.php b/plugins/buddypress/bp-groups/bp-groups-forums.php index d870188..600fff3 100644
a b 7 7 * have a template screen associated with them. Usually they will send the user 8 8 * back to the default screen after execution. 9 9 * 10 * Note that this file is only used for the retired version of bbPress (1.x) and 11 * will see minimal updates as of BuddyPress 1.9.0. 12 * 10 13 * @package BuddyPress 11 14 * @subpackage GroupsForums 12 15 */ -
plugins/buddypress/bp-groups/bp-groups-functions.php
diff --git a/plugins/buddypress/bp-groups/bp-groups-functions.php b/plugins/buddypress/bp-groups/bp-groups-functions.php index 2d48391..072bdd8 100644
a b 200 200 * @since BuddyPress (1.0) 201 201 */ 202 202 function groups_delete_group( $group_id ) { 203 global $bp;204 203 205 204 do_action( 'groups_before_delete_group', $group_id ); 206 205 207 206 // Get the group object 208 207 $group = groups_get_group( array( 'group_id' => $group_id ) ); 209 if ( !$group->delete() )210 return false;211 208 212 // Delete all group activity from activity streams 213 if ( bp_is_active( 'activity' ) ) 214 bp_activity_delete_by_item_id( array( 'item_id' => $group_id, 'component' => $bp->groups->id ) ); 209 // Bail if group cannot be deleted 210 if ( ! $group->delete() ) { 211 return false; 212 } 215 213 216 214 // Remove all outstanding invites for this group 217 215 groups_delete_all_group_invites( $group_id ); 218 216 219 // Remove all notifications for any user belonging to this group 220 bp_core_delete_all_notifications_by_type( $group_id, $bp->groups->id ); 221 222 do_action( 'groups_delete_group', $group_id); 217 do_action( 'groups_delete_group', $group_id ); 223 218 224 219 return true; 225 220 } … … 288 283 } 289 284 } 290 285 291 $membership = new BP_Groups_Member( $user_id, $group_id );292 293 286 // This is exactly the same as deleting an invite, just is_confirmed = 1 NOT 0. 294 if ( !groups_uninvite_user( $user_id, $group_id ) ) 287 if ( !groups_uninvite_user( $user_id, $group_id ) ) { 295 288 return false; 296 297 /** 298 * If the user joined this group less than five minutes ago, remove the 299 * joined_group activity so users cannot flood the activity stream by 300 * joining/leaving the group in quick succession. 301 */ 302 if ( bp_is_active( 'activity' ) && time() <= strtotime( '+5 minutes', (int)strtotime( $membership->date_modified ) ) ) 303 bp_activity_delete( array( 'component' => $bp->groups->id, 'type' => 'joined_group', 'user_id' => $user_id, 'item_id' => $group_id ) ); 289 } 304 290 305 291 bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) ); 306 292 … … 696 682 // If the user is already a member (because BP at one point allowed two invitations to 697 683 // slip through), delete all existing invitations/requests and return true 698 684 if ( groups_is_user_member( $user_id, $group_id ) ) { 699 if ( groups_check_user_has_invite( $user_id, $group_id ) ) 685 if ( groups_check_user_has_invite( $user_id, $group_id ) ) { 700 686 groups_delete_invite( $user_id, $group_id ); 687 } 701 688 702 if ( groups_check_for_membership_request( $user_id, $group_id ) ) 689 if ( groups_check_for_membership_request( $user_id, $group_id ) ) { 703 690 groups_delete_membership_request( $user_id, $group_id ); 691 } 704 692 705 693 return true; 706 694 } … … 708 696 $member = new BP_Groups_Member( $user_id, $group_id ); 709 697 $member->accept_invite(); 710 698 711 if ( !$member->save() ) 699 if ( !$member->save() ) { 712 700 return false; 701 } 713 702 714 703 // Remove request to join 715 if ( $member->check_for_membership_request( $user_id, $group_id ) ) 704 if ( $member->check_for_membership_request( $user_id, $group_id ) ) { 716 705 $member->delete_request( $user_id, $group_id ); 706 } 717 707 718 708 // Modify group meta 719 709 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); 720 710 721 bp_core_mark_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'group_invite' );722 723 711 do_action( 'groups_accept_invite', $user_id, $group_id ); 712 724 713 return true; 725 714 } 726 715 727 716 function groups_reject_invite( $user_id, $group_id ) { 728 if ( ! BP_Groups_Member::delete( $user_id, $group_id ) )717 if ( ! BP_Groups_Member::delete( $user_id, $group_id ) ) 729 718 return false; 730 719 731 720 do_action( 'groups_reject_invite', $user_id, $group_id ); … … 734 723 } 735 724 736 725 function groups_delete_invite( $user_id, $group_id ) { 726 if ( ! BP_Groups_Member::delete_invite( $user_id, $group_id ) ) 727 return false; 737 728 738 $delete = BP_Groups_Member::delete_invite($user_id, $group_id );729 do_action( 'groups_delete_invite', $user_id, $group_id ); 739 730 740 if ( !empty( $delete ) ) { 741 bp_core_mark_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'group_invite' ); 742 } 743 744 return $delete; 731 return true; 745 732 } 746 733 747 734 function groups_send_invites( $user_id, $group_id ) { … … 905 892 906 893 function groups_accept_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) { 907 894 908 if ( !empty( $user_id ) && !empty( $group_id ) ) 895 if ( !empty( $user_id ) && !empty( $group_id ) ) { 909 896 $membership = new BP_Groups_Member( $user_id, $group_id ); 910 else897 } else { 911 898 $membership = new BP_Groups_Member( false, false, $membership_id ); 899 } 912 900 913 901 $membership->accept_request(); 914 902 915 if ( !$membership->save() ) 903 if ( !$membership->save() ) { 916 904 return false; 905 } 917 906 918 907 // Check if the user has an outstanding invite, if so delete it. 919 if ( groups_check_user_has_invite( $membership->user_id, $membership->group_id ) ) 908 if ( groups_check_user_has_invite( $membership->user_id, $membership->group_id ) ) { 920 909 groups_delete_invite( $membership->user_id, $membership->group_id ); 910 } 921 911 922 // Record this in activity streams 923 $group = groups_get_group( array( 'group_id' => $membership->group_id ) ); 924 925 groups_record_activity( array( 926 'action' => apply_filters_ref_array( 'groups_activity_membership_accepted_action', array( sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $membership->user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $membership->user_id, &$group ) ), 927 'type' => 'joined_group', 928 'item_id' => $membership->group_id, 929 'user_id' => $membership->user_id 930 ) ); 931 932 // Send a notification to the user. 933 groups_notification_membership_request_completed( $membership->user_id, $membership->group_id, true ); 934 935 do_action( 'groups_membership_accepted', $membership->user_id, $membership->group_id ); 912 do_action( 'groups_membership_accepted', $membership->user_id, $membership->group_id, true ); 936 913 937 914 return true; 938 915 } 939 916 940 917 function groups_reject_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) { 941 if ( !$membership = groups_delete_membership_request( $membership_id, $user_id, $group_id ) ) 918 if ( !$membership = groups_delete_membership_request( $membership_id, $user_id, $group_id ) ) { 942 919 return false; 920 } 943 921 944 // Send a notification to the user. 945 groups_notification_membership_request_completed( $membership->user_id, $membership->group_id, false ); 946 947 do_action( 'groups_membership_rejected', $membership->user_id, $membership->group_id ); 922 do_action( 'groups_membership_rejected', $membership->user_id, $membership->group_id, false ); 948 923 949 924 return true; 950 925 } … … 1074 1049 /*** Group Cleanup Functions ****************************************************/ 1075 1050 1076 1051 function groups_remove_data_for_user( $user_id ) { 1077 global $bp;1078 1079 1052 BP_Groups_Member::delete_all_for_user( $user_id ); 1080 1081 bp_core_delete_notifications_from_user( $user_id, $bp->groups->id, 'new_membership_request' );1082 1053 1083 1054 do_action( 'groups_remove_data_for_user', $user_id ); 1084 1055 } -
plugins/buddypress/bp-groups/bp-groups-notifications.php
diff --git a/plugins/buddypress/bp-groups/bp-groups-notifications.php b/plugins/buddypress/bp-groups/bp-groups-notifications.php index 37d2f56..55e32f9 100644
a b 13 13 // Exit if accessed directly 14 14 if ( !defined( 'ABSPATH' ) ) exit; 15 15 16 /** Emails ********************************************************************/ 17 16 18 function groups_notification_group_updated( $group_id ) { 17 19 18 20 $group = groups_get_group( array( 'group_id' => $group_id ) ); … … 56 58 57 59 function groups_notification_new_membership_request( $requesting_user_id, $admin_id, $group_id, $membership_id ) { 58 60 59 bp_core_add_notification( $requesting_user_id, $admin_id, 'groups', 'new_membership_request', $group_id ); 61 if ( bp_is_active( 'notifications' ) ) { 62 bp_notifications_add_notification( $requesting_user_id, $admin_id, 'groups', 'new_membership_request', $group_id ); 63 } 60 64 61 65 if ( 'no' == bp_get_user_meta( $admin_id, 'notification_groups_membership_request', true ) ) 62 66 return false; … … 105 109 function groups_notification_membership_request_completed( $requesting_user_id, $group_id, $accepted = true ) { 106 110 107 111 // Post a screen notification first. 108 if ( $accepted ) 109 bp_core_add_notification( $group_id, $requesting_user_id, 'groups', 'membership_request_accepted' ); 110 else 111 bp_core_add_notification( $group_id, $requesting_user_id, 'groups', 'membership_request_rejected' ); 112 if ( bp_is_active( 'notifications' ) ) { 113 if ( $accepted ) { 114 bp_notifications_add_notification( $group_id, $requesting_user_id, 'groups', 'membership_request_accepted' ); 115 } else { 116 bp_notifications_add_notification( $group_id, $requesting_user_id, 'groups', 'membership_request_rejected' ); 117 } 118 } 112 119 113 120 if ( 'no' == bp_get_user_meta( $requesting_user_id, 'notification_membership_request_completed', true ) ) 114 121 return false; … … 159 166 160 167 do_action( 'bp_groups_sent_membership_approved_email', $requesting_user_id, $subject, $message, $group_id ); 161 168 } 169 add_action( 'groups_membership_accepted', 'groups_notification_membership_request_completed', 10, 3 ); 170 add_action( 'groups_membership_rejected', 'groups_notification_membership_request_completed', 10, 3 ); 162 171 163 172 function groups_notification_promoted_member( $user_id, $group_id ) { 164 173 … … 171 180 } 172 181 173 182 // Post a screen notification first. 174 bp_core_add_notification( $group_id, $user_id, 'groups', $type ); 183 if ( bp_is_active( 'notifications' ) ) { 184 bp_notifications_add_notification( $group_id, $user_id, 'groups', $type ); 185 } 175 186 176 187 if ( 'no' == bp_get_user_meta( $user_id, 'notification_groups_admin_promotion', true ) ) 177 188 return false; … … 222 233 $invited_user_id = $member->user_id; 223 234 224 235 // Post a screen notification first. 225 bp_core_add_notification( $group->id, $invited_user_id, 'groups', 'group_invite' ); 236 if ( bp_is_active( 'notifications' ) ) { 237 bp_notifications_add_notification( $group->id, $invited_user_id, 'groups', 'group_invite' ); 238 } 226 239 227 240 if ( 'no' == bp_get_user_meta( $invited_user_id, 'notification_groups_invite', true ) ) 228 241 return false; … … 264 277 do_action( 'bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group ); 265 278 } 266 279 } 280 281 /** Notifications *************************************************************/ 282 283 /** 284 * Format the BuddyBar/Toolbar notifications for the Groups component 285 * 286 * @since BuddyPress (1.0) 287 * @param string $action The kind of notification being rendered 288 * @param int $item_id The primary item id 289 * @param int $secondary_item_id The secondary item id 290 * @param int $total_items The total number of messaging-related notifications waiting for the user 291 * @param string $format 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar 292 */ 293 function groups_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { 294 295 switch ( $action ) { 296 case 'new_membership_request': 297 $group_id = $secondary_item_id; 298 $requesting_user_id = $item_id; 299 300 $group = groups_get_group( array( 'group_id' => $group_id ) ); 301 $group_link = bp_get_group_permalink( $group ); 302 303 // Set up the string and the filter 304 // Because different values are passed to the filters, we'll return the 305 // values inline 306 if ( (int) $total_items > 1 ) { 307 $text = sprintf( __( '%1$d new membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name ); 308 $filter = 'bp_groups_multiple_new_membership_requests_notification'; 309 $notification_link = $group_link . 'admin/membership-requests/?n=1'; 310 311 if ( 'string' == $format ) { 312 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Group Membership Requests', 'buddypress' ) . '">' . $text . '</a>', $group_link, $total_items, $group->name, $text, $notification_link ); 313 } else { 314 return apply_filters( $filter, array( 315 'link' => $notification_link, 316 'text' => $text 317 ), $group_link, $total_items, $group->name, $text, $notification_link ); 318 } 319 } else { 320 $user_fullname = bp_core_get_user_displayname( $requesting_user_id ); 321 $text = sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname ); 322 $filter = 'bp_groups_single_new_membership_request_notification'; 323 $notification_link = $group_link . 'admin/membership-requests/?n=1'; 324 325 if ( 'string' == $format ) { 326 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname ) . '">' . $text . '</a>', $group_link, $user_fullname, $group->name, $text, $notification_link ); 327 } else { 328 return apply_filters( $filter, array( 329 'link' => $notification_link, 330 'text' => $text 331 ), $group_link, $user_fullname, $group->name, $text, $notification_link ); 332 } 333 } 334 335 break; 336 337 case 'membership_request_accepted': 338 $group_id = $item_id; 339 340 $group = groups_get_group( array( 'group_id' => $group_id ) ); 341 $group_link = bp_get_group_permalink( $group ); 342 343 if ( (int) $total_items > 1 ) { 344 $text = sprintf( __( '%d accepted group membership requests', 'buddypress' ), (int) $total_items, $group->name ); 345 $filter = 'bp_groups_multiple_membership_request_accepted_notification'; 346 $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1'; 347 348 if ( 'string' == $format ) { 349 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $group->name, $text, $notification_link ); 350 } else { 351 return apply_filters( $filter, array( 352 'link' => $notification_link, 353 'text' => $text 354 ), $total_items, $group->name, $text, $notification_link ); 355 } 356 } else { 357 $text = sprintf( __( 'Membership for group "%s" accepted', 'buddypress' ), $group->name ); 358 $filter = 'bp_groups_single_membership_request_accepted_notification'; 359 $notification_link = $group_link . '?n=1'; 360 361 if ( 'string' == $format ) { 362 return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link ); 363 } else { 364 return apply_filters( $filter, array( 365 'link' => $notification_link, 366 'text' => $text 367 ), $group_link, $group->name, $text, $notification_link ); 368 } 369 } 370 371 break; 372 373 case 'membership_request_rejected': 374 $group_id = $item_id; 375 376 $group = groups_get_group( array( 'group_id' => $group_id ) ); 377 $group_link = bp_get_group_permalink( $group ); 378 379 if ( (int) $total_items > 1 ) { 380 $text = sprintf( __( '%d rejected group membership requests', 'buddypress' ), (int) $total_items, $group->name ); 381 $filter = 'bp_groups_multiple_membership_request_rejected_notification'; 382 $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1'; 383 384 if ( 'string' == $format ) { 385 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $group->name ); 386 } else { 387 return apply_filters( $filter, array( 388 'link' => $notification_link, 389 'text' => $text 390 ), $total_items, $group->name, $text, $notification_link ); 391 } 392 } else { 393 $text = sprintf( __( 'Membership for group "%s" rejected', 'buddypress' ), $group->name ); 394 $filter = 'bp_groups_single_membership_request_rejected_notification'; 395 $notification_link = $group_link . '?n=1'; 396 397 if ( 'string' == $format ) { 398 return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link ); 399 } else { 400 return apply_filters( $filter, array( 401 'link' => $notification_link, 402 'text' => $text 403 ), $group_link, $group->name, $text, $notification_link ); 404 } 405 } 406 407 break; 408 409 case 'member_promoted_to_admin': 410 $group_id = $item_id; 411 412 $group = groups_get_group( array( 'group_id' => $group_id ) ); 413 $group_link = bp_get_group_permalink( $group ); 414 415 if ( (int) $total_items > 1 ) { 416 $text = sprintf( __( 'You were promoted to an admin in %d groups', 'buddypress' ), (int) $total_items ); 417 $filter = 'bp_groups_multiple_member_promoted_to_admin_notification'; 418 $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1'; 419 420 if ( 'string' == $format ) { 421 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link ); 422 } else { 423 return apply_filters( $filter, array( 424 'link' => $notification_link, 425 'text' => $text 426 ), $total_items, $text, $notification_link ); 427 } 428 } else { 429 $text = sprintf( __( 'You were promoted to an admin in the group "%s"', 'buddypress' ), $group->name ); 430 $filter = 'bp_groups_single_member_promoted_to_admin_notification'; 431 $notification_link = $group_link . '?n=1'; 432 433 if ( 'string' == $format ) { 434 return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link ); 435 } else { 436 return apply_filters( $filter, array( 437 'link' => $notification_link, 438 'text' => $text 439 ), $group_link, $group->name, $text, $notification_link ); 440 } 441 } 442 443 break; 444 445 case 'member_promoted_to_mod': 446 $group_id = $item_id; 447 448 $group = groups_get_group( array( 'group_id' => $group_id ) ); 449 $group_link = bp_get_group_permalink( $group ); 450 451 if ( (int) $total_items > 1 ) { 452 $text = sprintf( __( 'You were promoted to a mod in %d groups', 'buddypress' ), (int) $total_items ); 453 $filter = 'bp_groups_multiple_member_promoted_to_mod_notification'; 454 $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1'; 455 456 if ( 'string' == $format ) { 457 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link ); 458 } else { 459 return apply_filters( $filter, array( 460 'link' => $notification_link, 461 'text' => $text 462 ), $total_items, $text, $notification_link ); 463 } 464 } else { 465 $text = sprintf( __( 'You were promoted to a mod in the group "%s"', 'buddypress' ), $group->name ); 466 $filter = 'bp_groups_single_member_promoted_to_mod_notification'; 467 $notification_link = $group_link . '?n=1'; 468 469 if ( 'string' == $format ) { 470 return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link ); 471 } else { 472 return apply_filters( $filter, array( 473 'link' => $notification_link, 474 'text' => $text 475 ), $group_link, $group->name, $text, $notification_link ); 476 } 477 } 478 479 break; 480 481 case 'group_invite': 482 $group_id = $item_id; 483 $group = groups_get_group( array( 'group_id' => $group_id ) ); 484 $group_link = bp_get_group_permalink( $group ); 485 486 $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/?n=1'; 487 488 if ( (int) $total_items > 1 ) { 489 $text = sprintf( __( 'You have %d new group invitations', 'buddypress' ), (int) $total_items ); 490 $filter = 'bp_groups_multiple_group_invite_notification'; 491 492 if ( 'string' == $format ) { 493 return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Group Invites', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link ); 494 } else { 495 return apply_filters( $filter, array( 496 'link' => $notification_link, 497 'text' => $text 498 ), $total_items, $text, $notification_link ); 499 } 500 } else { 501 $text = sprintf( __( 'You have an invitation to the group: %s', 'buddypress' ), $group->name ); 502 $filter = 'bp_groups_single_group_invite_notification'; 503 504 if ( 'string' == $format ) { 505 return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link ); 506 } else { 507 return apply_filters( $filter, array( 508 'link' => $notification_link, 509 'text' => $text 510 ), $group_link, $group->name, $text, $notification_link ); 511 } 512 } 513 514 break; 515 } 516 517 do_action( 'groups_format_notifications', $action, $item_id, $secondary_item_id, $total_items ); 518 519 return false; 520 } 521 522 /** 523 * Remove all notifications for any member belonging to a specific group 524 * 525 * @since BuddyPress (1.9.0) 526 */ 527 function bp_groups_delete_group_delete_all_notifications( $group_id ) { 528 if ( bp_is_active( 'notifications' ) ) { 529 bp_notifications_delete_all_notifications_by_type( $group_id, buddypress()->groups->id ); 530 } 531 } 532 add_action( 'groups_delete_group', 'bp_groups_delete_group_delete_all_notifications', 10 ); 533 534 /** 535 * Mark notifications read when a member accepts a group invitation 536 * 537 * @since BuddyPress (1.9.0) 538 * @param int $user_id 539 * @param int $group_id 540 */ 541 function bp_groups_accept_invite_mark_notifications( $user_id, $group_id ) { 542 if ( bp_is_active( 'notifications' ) ) { 543 bp_notifications_mark_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'group_invite' ); 544 } 545 } 546 add_action( 'groups_accept_invite', 'bp_groups_accept_invite_mark_notifications', 10, 2 ); 547 add_action( 'groups_reject_invite', 'bp_groups_accept_invite_mark_notifications', 10, 2 ); 548 add_action( 'groups_delete_invite', 'bp_groups_accept_invite_mark_notifications', 10, 2 ); 549 550 /** 551 * Mark notifications read when a member views their group memberships 552 * 553 * @since BuddyPress (1.9.0) 554 */ 555 function bp_groups_screen_my_groups_mark_notifications() { 556 557 // Delete group request notifications for the user 558 if ( isset( $_GET['n'] ) && bp_is_active( 'notifications' ) ) { 559 560 // Get the necessary ID's 561 $group_id = buddypress()->groups->id; 562 $user_id = bp_loggedin_user_id(); 563 564 // Mark notifications read 565 bp_notifications_mark_notifications_by_type( $user_id, $group_id, 'membership_request_accepted' ); 566 bp_notifications_mark_notifications_by_type( $user_id, $group_id, 'membership_request_rejected' ); 567 bp_notifications_mark_notifications_by_type( $user_id, $group_id, 'member_promoted_to_mod' ); 568 bp_notifications_mark_notifications_by_type( $user_id, $group_id, 'member_promoted_to_admin' ); 569 } 570 } 571 add_action( 'groups_screen_my_groups', 'bp_groups_screen_my_groups_mark_notifications', 10 ); 572 add_action( 'groups_screen_home', 'bp_groups_screen_my_groups_mark_notifications', 10 ); 573 574 /** 575 * Mark group invitation notifications read when a member views their invitations 576 * 577 * @since BuddyPress (1.9.0) 578 */ 579 function bp_groups_screen_invites_mark_notifications() { 580 if ( bp_is_active( 'notifications' ) ) { 581 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->groups->id, 'group_invite' ); 582 } 583 } 584 add_action( 'groups_screen_invites', 'bp_groups_screen_invites_mark_notifications', 10 ); 585 586 /** 587 * Mark group join requests read when an admin or moderator visits the group 588 * administration area. 589 * 590 * @since BuddyPress (1.9.0) 591 * @param int $group_id 592 */ 593 function bp_groups_screen_group_admin_requests_mark_notifications( $group_id ) { 594 if ( bp_is_active( 'notifications' ) ) { 595 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), $group_id, 'new_membership_request' ); 596 } 597 } 598 add_action( 'groups_screen_group_admin_requests', 'bp_groups_screen_group_admin_requests_mark_notifications', 10 ); 599 600 /** 601 * Delete new group membership notifications when a user is being deleted. 602 * 603 * @since BuddyPress (1.9.0) 604 * @param int $user_id 605 */ 606 function bp_groups_remove_data_for_user_notifications( $user_id ) { 607 if ( bp_is_active( 'notifications' ) ) { 608 bp_notifications_delete_notifications_from_user( $user_id, buddypress()->groups->id, 'new_membership_request' ); 609 } 610 } 611 add_action( 'groups_remove_data_for_user', 'bp_groups_remove_data_for_user_notifications', 10 ); -
plugins/buddypress/bp-groups/bp-groups-screens.php
diff --git a/plugins/buddypress/bp-groups/bp-groups-screens.php b/plugins/buddypress/bp-groups/bp-groups-screens.php index d249a98..73d5d08 100644
a b 27 27 28 28 function groups_screen_my_groups() { 29 29 30 $bp = buddypress();31 32 // Delete group request notifications for the user33 if ( isset( $_GET['n'] ) ) {34 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_accepted' );35 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_rejected' );36 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_mod' );37 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_admin' );38 }39 40 30 do_action( 'groups_screen_my_groups' ); 41 31 42 32 bp_core_load_template( apply_filters( 'groups_template_my_groups', 'members/single/home' ) ); … … 93 83 bp_core_redirect( $redirect_to ); 94 84 } 95 85 96 // Remove notifications97 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->groups->id, 'group_invite' );98 99 86 do_action( 'groups_screen_group_invites', $group_id ); 100 87 101 88 bp_core_load_template( apply_filters( 'groups_template_group_invites', 'members/single/home' ) ); … … 103 90 104 91 function groups_screen_group_home() { 105 92 106 if ( ! bp_is_single_item() ) 93 if ( ! bp_is_single_item() ) { 107 94 return false; 108 109 $bp = buddypress();110 111 if ( isset( $_GET['n'] ) ) {112 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_accepted' );113 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_rejected' );114 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_mod' );115 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_admin' );116 95 } 117 96 118 97 do_action( 'groups_screen_group_home' ); … … 804 783 add_action( 'bp_screens', 'groups_screen_group_admin_manage_members' ); 805 784 806 785 function groups_screen_group_admin_requests() { 807 global $bp;786 $bp = buddypress(); 808 787 809 if ( 'membership-requests' != bp_get_group_current_admin_tab() ) 788 if ( 'membership-requests' != bp_get_group_current_admin_tab() ) { 810 789 return false; 790 } 811 791 812 if ( ! bp_is_item_admin() || ( 'public' == $bp->groups->current_group->status ) ) 792 if ( ! bp_is_item_admin() || ( 'public' == $bp->groups->current_group->status ) ) { 813 793 return false; 794 } 814 795 815 // Remove any screen notifications 816 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'new_membership_request' ); 817 818 $request_action = (string)bp_action_variable( 1 ); 819 $membership_id = (int)bp_action_variable( 2 ); 796 $request_action = (string) bp_action_variable( 1 ); 797 $membership_id = (int) bp_action_variable( 2 ); 820 798 821 799 if ( !empty( $request_action ) && !empty( $membership_id ) ) { 822 800 if ( 'accept' == $request_action && is_numeric( $membership_id ) ) {