BuddyPress - Version 1.9-beta2

Version Description

= 1.8.1 = See: http://codex.buddypress.org/releases/version-1-8-1/

= 1.8 = See: http://codex.buddypress.org/releases/version-1-8/

= 1.7.3 = See: http://codex.buddypress.org/releases/version-1-7-3/

= 1.7.2 = See: http://codex.buddypress.org/releases/version-1-7-2/

= 1.7.1 = See: http://codex.buddypress.org/releases/version-1-7-1/

= 1.7 = See: http://codex.buddypress.org/releases/version-1-7/

= 1.6.5 = See: http://codex.buddypress.org/releases/version-1-6-5/

= 1.6.4 = See: http://codex.buddypress.org/releases/version-1-6-4/

= 1.6.3 = See: http://codex.buddypress.org/releases/version-1-6-3/

= 1.6.2 = Compatibility with WordPress 3.5

= 1.6.1 = Fixes 4 bugs

= 1.6 = See: http://codex.buddypress.org/releases/version-1-6/

= 1.5 = See: http://codex.buddypress.org/releases/version-1-5/

= 1.2.9 = Compatibility with WordPress 3.2

= 1.2.8 = Compatibility with WordPress 3.1

= 1.2.7 = Fixes over 10 bugs.

Download this release

Release Info

Developer boonebgorges
Plugin Icon 128x128 BuddyPress
Version 1.9-beta2
Comparing to
See all releases

Code changes from version 1.9-beta1 to 1.9-beta2

Files changed (79) hide show
  1. .travis.yml +52 -0
  2. bp-activity/bp-activity-functions.php +10 -64
  3. bp-activity/bp-activity-notifications.php +123 -8
  4. bp-activity/bp-activity-screens.php +0 -14
  5. bp-core/admin/bp-core-components.php +1 -1
  6. bp-core/admin/bp-core-functions.php +21 -11
  7. bp-core/bp-core-admin.php +48 -50
  8. bp-core/bp-core-classes.php +6 -2
  9. bp-core/bp-core-filters.php +5 -0
  10. bp-friends/bp-friends-activity.php +55 -68
  11. bp-friends/bp-friends-cache.php +0 -11
  12. bp-friends/bp-friends-functions.php +29 -72
  13. bp-friends/bp-friends-notifications.php +200 -4
  14. bp-friends/bp-friends-screens.php +0 -7
  15. bp-groups/bp-groups-activity.php +77 -232
  16. bp-groups/bp-groups-classes.php +23 -17
  17. bp-groups/bp-groups-forums.php +3 -0
  18. bp-groups/bp-groups-functions.php +32 -61
  19. bp-groups/bp-groups-notifications.php +352 -7
  20. bp-groups/bp-groups-screens.php +8 -30
  21. bp-languages/buddypress.pot +346 -351
  22. bp-loader.php +3 -3
  23. bp-members/bp-members-adminbar.php +16 -16
  24. bp-members/bp-members-notifications.php +54 -88
  25. bp-messages/bp-messages-functions.php +0 -53
  26. bp-messages/bp-messages-notifications.php +115 -5
  27. bp-messages/bp-messages-template.php +0 -4
  28. bp-notifications/bp-notifications-adminbar.php +2 -2
  29. bp-notifications/bp-notifications-buddybar.php +4 -4
  30. bp-notifications/bp-notifications-functions.php +1 -1
  31. bp-notifications/bp-notifications-loader.php +7 -6
  32. bp-notifications/bp-notifications-template.php +1 -1
  33. bp-settings/bp-settings-loader.php +1 -1
  34. bp-templates/bp-legacy/css/buddypress.css +44 -6
  35. bp-templates/bp-legacy/js/buddypress.js +1 -1
  36. bp-themes/bp-default/_inc/global.js +1 -1
  37. bp-themes/bp-default/rtl.css +1 -1
  38. bp-themes/bp-default/style.css +1 -1
  39. bp-xprofile/bp-xprofile-functions.php +1 -1
  40. bp-xprofile/bp-xprofile-template.php +7 -9
  41. readme.txt +4 -4
  42. tests/assets/group-extensions.php +148 -0
  43. tests/bootstrap.php +55 -0
  44. tests/includes/factory.php +165 -0
  45. tests/includes/install.php +74 -0
  46. tests/includes/loader.php +6 -0
  47. tests/includes/testcase.php +317 -0
  48. tests/multisite.xml +17 -0
  49. tests/phpunit.xml +14 -0
  50. tests/testcases/activity/class.BP_Activity_Activity.php +308 -0
  51. tests/testcases/activity/functions.php +208 -0
  52. tests/testcases/activity/template.php +256 -0
  53. tests/testcases/admin/functions.php +123 -0
  54. tests/testcases/blogs/class-bp-blogs-blog.php +67 -0
  55. tests/testcases/core/avatars.php +56 -0
  56. tests/testcases/core/class-bp-core-user.php +124 -0
  57. tests/testcases/core/class-bp-user-query.php +301 -0
  58. tests/testcases/core/functions.php +258 -0
  59. tests/testcases/friends/class-bp-friends-friendship.php +126 -0
  60. tests/testcases/groups/class-bp-group-extension.php +225 -0
  61. tests/testcases/groups/class-bp-group-member-query.php +337 -0
  62. tests/testcases/groups/class-bp-groups-group.php +657 -0
  63. tests/testcases/groups/class-bp-groups-member.php +131 -0
  64. tests/testcases/groups/functions.php +288 -0
  65. tests/testcases/groups/template.php +410 -0
  66. tests/testcases/members/functions.php +79 -0
  67. tests/testcases/members/template.php +102 -0
  68. tests/testcases/routing/activity.php +68 -0
  69. tests/testcases/routing/anonymous.php +29 -0
  70. tests/testcases/routing/core.php +31 -0
  71. tests/testcases/routing/friends.php +30 -0
  72. tests/testcases/routing/groups.php +30 -0
  73. tests/testcases/routing/members.php +30 -0
  74. tests/testcases/routing/messages.php +40 -0
  75. tests/testcases/routing/settings.php +40 -0
  76. tests/testcases/routing/xprofile.php +35 -0
  77. tests/testcases/url/url.php +65 -0
  78. tests/testcases/xprofile/class-bp-xprofile-field.php +29 -0
  79. tests/testcases/xprofile/functions.php +83 -0
.travis.yml ADDED
@@ -0,0 +1,52 @@
1
+ language: php
2
+
3
+ php:
4
+ - 5.2
5
+ - 5.3
6
+ - 5.4
7
+ - 5.5
8
+
9
+ env:
10
+ - WP_VERSION=master WP_MULTISITE=0
11
+ - WP_VERSION=3.7.1 WP_MULTISITE=0
12
+ - WP_VERSION=3.6.1 WP_MULTISITE=0
13
+ - WP_VERSION=3.5.2 WP_MULTISITE=0
14
+ - WP_VERSION=master WP_MULTISITE=1
15
+ - WP_VERSION=3.7.1 WP_MULTISITE=1
16
+ - WP_VERSION=3.6.1 WP_MULTISITE=1
17
+ - WP_VERSION=3.5.2 WP_MULTISITE=1
18
+
19
+ before_script:
20
+ # set up WP install
21
+ - WP_CORE_DIR=/tmp/wordpress/
22
+ - wget -nv -O /tmp/wordpress.tar.gz https://github.com/WordPress/WordPress/tarball/$WP_VERSION
23
+ - mkdir -p $WP_CORE_DIR
24
+ - tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
25
+ - plugin_slug=$(basename $(pwd))
26
+ - plugin_dir=$WP_CORE_DIR/wp-content/plugins/$plugin_slug
27
+ - cd ..
28
+ - mv $plugin_slug $plugin_dir
29
+ # set up testing suite
30
+ - export WP_TESTS_DIR=/tmp/wordpress-tests/
31
+ - svn co --ignore-externals http://unit-tests.svn.wordpress.org/trunk/ $WP_TESTS_DIR
32
+ - cd $WP_TESTS_DIR
33
+ - cp wp-tests-config-sample.php wp-tests-config.php
34
+ - sed -i "s:dirname( __FILE__ ) . '/wordpress/':'$WP_CORE_DIR':" wp-tests-config.php
35
+ - sed -i "s/yourdbnamehere/wordpress_test/" wp-tests-config.php
36
+ - sed -i "s/yourusernamehere/root/" wp-tests-config.php
37
+ - sed -i "s/yourpasswordhere//" wp-tests-config.php
38
+ # set up database
39
+ - mysql -e 'CREATE DATABASE wordpress_test;' -uroot
40
+ # prepare for running the tests
41
+ - cd $plugin_dir/tests
42
+
43
+ script: phpunit
44
+
45
+ notifications:
46
+ email: false
47
+
48
+ irc:
49
+ channels:
50
+ - "irc.freenode.net#buddypress-dev"
51
+ template:
52
+ - "Build %{build_number} (%{branch} - %{commit}): %{message} %{build_url}"
bp-activity/bp-activity-functions.php CHANGED
@@ -190,59 +190,6 @@ function bp_activity_update_mention_count_for_user( $user_id, $activity_id, $act
190
return true;
191
}
192
193
- /**
194
- * Format notifications related to activity.
195
- *
196
- * @since BuddyPress (1.5)
197
- *
198
- * @uses bp_loggedin_user_domain()
199
- * @uses bp_get_activity_slug()
200
- * @uses bp_core_get_user_displayname()
201
- * @uses apply_filters() To call the 'bp_activity_multiple_at_mentions_notification' hook.
202
- * @uses apply_filters() To call the 'bp_activity_single_at_mentions_notification' hook.
203
- * @uses do_action() To call 'activity_format_notifications' hook.
204
- *
205
- * @param string $action The type of activity item. Just 'new_at_mention' for now.
206
- * @param int $item_id The activity ID.
207
- * @param int $secondary_item_id In the case of at-mentions, this is the mentioner's ID.
208
- * @param int $total_items The total number of notifications to format.
209
- * @param string $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise.
210
- * @return string $return Formatted @mention notification.
211
- */
212
- function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
213
-
214
- switch ( $action ) {
215
- case 'new_at_mention':
216
- $activity_id = $item_id;
217
- $poster_user_id = $secondary_item_id;
218
- $at_mention_link = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
219
- $at_mention_title = sprintf( __( '@%s Mentions', 'buddypress' ), bp_get_loggedin_user_username() );
220
-
221
- if ( (int) $total_items > 1 ) {
222
- $text = sprintf( __( 'You have %1$d new mentions', 'buddypress' ), (int) $total_items );
223
- $filter = 'bp_activity_multiple_at_mentions_notification';
224
- } else {
225
- $user_fullname = bp_core_get_user_displayname( $poster_user_id );
226
- $text = sprintf( __( '%1$s mentioned you', 'buddypress' ), $user_fullname );
227
- $filter = 'bp_activity_single_at_mentions_notification';
228
- }
229
- break;
230
- }
231
-
232
- if ( 'string' == $format ) {
233
- $return = apply_filters( $filter, '<a href="' . $at_mention_link . '" title="' . $at_mention_title . '">' . $text . '</a>', $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
234
- } else {
235
- $return = apply_filters( $filter, array(
236
- 'text' => $text,
237
- 'link' => $at_mention_link
238
- ), $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
239
- }
240
-
241
- do_action( 'activity_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
242
-
243
- return $return;
244
- }
245
-
246
/**
247
* Determine a user's "mentionname", the name used for that user in @-mentions.
248
*
@@ -1266,27 +1213,29 @@ function bp_activity_post_update( $args = '' ) {
1266
* @return int|bool The ID of the comment on success, otherwise false.
1267
*/
1268
function bp_activity_new_comment( $args = '' ) {
1269
- global $bp;
1270
1271
- $defaults = array(
1272
'id' => false,
1273
'content' => false,
1274
'user_id' => bp_loggedin_user_id(),
1275
'activity_id' => false, // ID of the root activity item
1276
'parent_id' => false // ID of a parent comment (optional)
1277
- );
1278
1279
- $params = wp_parse_args( $args, $defaults );
1280
extract( $params, EXTR_SKIP );
1281
1282
- if ( empty( $content ) || empty( $user_id ) || empty( $activity_id ) )
1283
return false;
1284
1285
- if ( empty( $parent_id ) )
1286
$parent_id = $activity_id;
1287
1288
// Check to see if the parent activity is hidden, and if so, hide this comment publically.
1289
- $activity = new BP_Activity_Activity( $activity_id );
1290
$is_hidden = ( (int) $activity->hide_sitewide ) ? 1 : 0;
1291
1292
// Insert the activity comment
@@ -1294,7 +1243,7 @@ function bp_activity_new_comment( $args = '' ) {
1294
'id' => $id,
1295
'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
1296
'content' => apply_filters( 'bp_activity_comment_content', $content ),
1297
- 'component' => $bp->activity->id,
1298
'type' => 'activity_comment',
1299
'user_id' => $user_id,
1300
'item_id' => $activity_id,
@@ -1302,9 +1251,6 @@ function bp_activity_new_comment( $args = '' ) {
1302
'hide_sitewide' => $is_hidden
1303
) );
1304
1305
- // Send an email notification if settings allow
1306
- bp_activity_new_comment_notification( $comment_id, $user_id, $params );
1307
-
1308
// Clear the comment cache for this activity
1309
wp_cache_delete( 'bp_activity_comments_' . $parent_id );
1310
190
return true;
191
}
192
193
/**
194
* Determine a user's "mentionname", the name used for that user in @-mentions.
195
*
1213
* @return int|bool The ID of the comment on success, otherwise false.
1214
*/
1215
function bp_activity_new_comment( $args = '' ) {
1216
1217
+ $params = wp_parse_args( $args, array(
1218
'id' => false,
1219
'content' => false,
1220
'user_id' => bp_loggedin_user_id(),
1221
'activity_id' => false, // ID of the root activity item
1222
'parent_id' => false // ID of a parent comment (optional)
1223
+ ) );
1224
1225
extract( $params, EXTR_SKIP );
1226
1227
+ // Bail if missing necessary data
1228
+ if ( empty( $content ) || empty( $user_id ) || empty( $activity_id ) ) {
1229
return false;
1230
+ }
1231
1232
+ // Maybe set current activity ID as the parent
1233
+ if ( empty( $parent_id ) ) {
1234
$parent_id = $activity_id;
1235
+ }
1236
1237
// Check to see if the parent activity is hidden, and if so, hide this comment publically.
1238
+ $activity = new BP_Activity_Activity( $activity_id );
1239
$is_hidden = ( (int) $activity->hide_sitewide ) ? 1 : 0;
1240
1241
// Insert the activity comment
1243
'id' => $id,
1244
'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
1245
'content' => apply_filters( 'bp_activity_comment_content', $content ),
1246
+ 'component' => buddypress()->activity->id,
1247
'type' => 'activity_comment',
1248
'user_id' => $user_id,
1249
'item_id' => $activity_id,
1251
'hide_sitewide' => $is_hidden
1252
) );
1253
1254
// Clear the comment cache for this activity
1255
wp_cache_delete( 'bp_activity_comments_' . $parent_id );
1256
bp-activity/bp-activity-notifications.php CHANGED
@@ -10,12 +10,14 @@
10
// Exit if accessed directly
11
if ( !defined( 'ABSPATH' ) ) exit;
12
13
/**
14
* Send email and BP notifications when a user is mentioned in an update.
15
*
16
* @since BuddyPress (1.2)
17
*
18
- * @uses bp_core_add_notification()
19
* @uses bp_get_user_meta()
20
* @uses bp_core_get_user_displayname()
21
* @uses bp_activity_get_permalink()
@@ -54,9 +56,6 @@ function bp_activity_at_message_notification( $activity_id, $receiver_user_id )
54
$message = '';
55
$content = '';
56
57
- // Add the BP notification
58
- bp_core_add_notification( $activity_id, $receiver_user_id, 'activity', 'new_at_mention', $activity->user_id );
59
-
60
// Now email the user with the contents of the message (if they have enabled email notifications)
61
if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
62
$poster_name = bp_core_get_user_displayname( $activity->user_id );
@@ -100,7 +99,7 @@ To view and respond to the message, log in and visit: %3$s
100
$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
101
}
102
103
- /* Send the message */
104
$to = apply_filters( 'bp_activity_at_message_notification_to', $to );
105
$subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
106
$message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
@@ -108,7 +107,7 @@ To view and respond to the message, log in and visit: %3$s
108
wp_mail( $to, $subject, $message );
109
}
110
111
- do_action( 'bp_activity_sent_mention_email', $activity, $subject, $message, $content );
112
}
113
114
/**
@@ -140,7 +139,7 @@ To view and respond to the message, log in and visit: %3$s
140
* @param int $commenter_id The ID of the user who posted the comment.
141
* @param array $params {@link bp_activity_new_comment()}
142
*/
143
- function bp_activity_new_comment_notification( $comment_id, $commenter_id, $params ) {
144
145
// Set some default parameters
146
$activity_id = 0;
@@ -192,8 +191,9 @@ To view your original update and all comments, log in and visit: %3$s
192
* If this is a reply to another comment, send an email notification to the
193
* author of the immediate parent comment.
194
*/
195
- if ( empty( $parent_id ) || ( $activity_id == $parent_id ) )
196
return false;
197
198
$parent_comment = new BP_Activity_Activity( $parent_id );
199
@@ -236,3 +236,118 @@ To view the original activity, your comment and all replies, log in and visit: %
236
do_action( 'bp_activity_sent_reply_to_reply_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
237
}
238
}
10
// Exit if accessed directly
11
if ( !defined( 'ABSPATH' ) ) exit;
12
13
+ /* Emails *********************************************************************/
14
+
15
/**
16
* Send email and BP notifications when a user is mentioned in an update.
17
*
18
* @since BuddyPress (1.2)
19
*
20
+ * @uses bp_notifications_add_notification()
21
* @uses bp_get_user_meta()
22
* @uses bp_core_get_user_displayname()
23
* @uses bp_activity_get_permalink()
56
$message = '';
57
$content = '';
58
59
// Now email the user with the contents of the message (if they have enabled email notifications)
60
if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
61
$poster_name = bp_core_get_user_displayname( $activity->user_id );
99
$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
100
}
101
102
+ // Send the message
103
$to = apply_filters( 'bp_activity_at_message_notification_to', $to );
104
$subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
105
$message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
107
wp_mail( $to, $subject, $message );
108
}
109
110
+ do_action( 'bp_activity_sent_mention_email', $activity, $subject, $message, $content, $receiver_user_id );
111
}
112
113
/**
139
* @param int $commenter_id The ID of the user who posted the comment.
140
* @param array $params {@link bp_activity_new_comment()}
141
*/
142
+ function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) {
143
144
// Set some default parameters
145
$activity_id = 0;
191
* If this is a reply to another comment, send an email notification to the
192
* author of the immediate parent comment.
193
*/
194
+ if ( empty( $parent_id ) || ( $activity_id == $parent_id ) ) {
195
return false;
196
+ }
197
198
$parent_comment = new BP_Activity_Activity( $parent_id );
199
236
do_action( 'bp_activity_sent_reply_to_reply_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
237
}
238
}
239
+
240
+ /**
241
+ * Helper method to map action arguments to function parameters
242
+ *
243
+ * @since BuddyPress (1.9.0)
244
+ * @param int $comment_id
245
+ * @param array $params
246
+ */
247
+ function bp_activity_new_comment_notification_helper( $comment_id, $params ) {
248
+ bp_activity_new_comment_notification( $comment_id, $params['user_id'], $params );
249
+ }
250
+ add_action( 'bp_activity_comment_posted', 'bp_activity_new_comment_notification_helper', 10, 2 );
251
+
252
+ /** Notifications *************************************************************/
253
+
254
+ /**
255
+ * Format notifications related to activity.
256
+ *
257
+ * @since BuddyPress (1.5)
258
+ *
259
+ * @uses bp_loggedin_user_domain()
260
+ * @uses bp_get_activity_slug()
261
+ * @uses bp_core_get_user_displayname()
262
+ * @uses apply_filters() To call the 'bp_activity_multiple_at_mentions_notification' hook.
263
+ * @uses apply_filters() To call the 'bp_activity_single_at_mentions_notification' hook.
264
+ * @uses do_action() To call 'activity_format_notifications' hook.
265
+ *
266
+ * @param string $action The type of activity item. Just 'new_at_mention' for now.
267
+ * @param int $item_id The activity ID.
268
+ * @param int $secondary_item_id In the case of at-mentions, this is the mentioner's ID.
269
+ * @param int $total_items The total number of notifications to format.
270
+ * @param string $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise.
271
+ * @return string $return Formatted @mention notification.
272
+ */
273
+ function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
274
+
275
+ switch ( $action ) {
276
+ case 'new_at_mention':
277
+ $activity_id = $item_id;
278
+ $poster_user_id = $secondary_item_id;
279
+ $at_mention_link = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
280
+ $at_mention_title = sprintf( __( '@%s Mentions', 'buddypress' ), bp_get_loggedin_user_username() );
281
+
282
+ if ( (int) $total_items > 1 ) {
283
+ $text = sprintf( __( 'You have %1$d new mentions', 'buddypress' ), (int) $total_items );
284
+ $filter = 'bp_activity_multiple_at_mentions_notification';
285
+ } else {
286
+ $user_fullname = bp_core_get_user_displayname( $poster_user_id );
287
+ $text = sprintf( __( '%1$s mentioned you', 'buddypress' ), $user_fullname );
288
+ $filter = 'bp_activity_single_at_mentions_notification';
289
+ }
290
+ break;
291
+ }
292
+
293
+ if ( 'string' == $format ) {
294
+ $return = apply_filters( $filter, '<a href="' . esc_url( $at_mention_link ) . '" title="' . esc_attr( $at_mention_title ) . '">' . esc_html( $text ) . '</a>', $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
295
+ } else {
296
+ $return = apply_filters( $filter, array(
297
+ 'text' => $text,
298
+ 'link' => $at_mention_link
299
+ ), $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
300
+ }
301
+
302
+ do_action( 'activity_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
303
+
304
+ return $return;
305
+ }
306
+
307
+ /**
308
+ * Notify a member when their nicename is mentioned in an activity stream item.
309
+ *
310
+ * Hooked to the 'bp_activity_sent_mention_email' action, we piggy back off the
311
+ * existing email code for now, since it does the heavy lifting for us. In the
312
+ * future when we separate emails from Notifications, this will need its own
313
+ * 'bp_activity_at_name_send_emails' equivalent helper function.
314
+ *
315
+ * @since BuddyPress (1.9.0)
316
+ *
317
+ * @param obj $activity
318
+ * @param string $subject (not used)
319
+ * @param string $message (not used)
320
+ * @param string $content (not used)
321
+ * @param int $receiver_user_id
322
+ */
323
+ function bp_activity_at_mention_add_notification( $activity, $subject, $message, $content, $receiver_user_id ) {
324
+ if ( bp_is_active( 'notifications' ) ) {
325
+ bp_notifications_add_notification( array(
326
+ 'user_id' => $receiver_user_id,
327
+ 'item_id' => $activity->id,
328
+ 'secondary_item_id' => $activity->user_id,
329
+ 'component_name' => buddypress()->activity->id,
330
+ 'component_action' => 'new_at_mention',
331
+ 'date_notified' => bp_core_current_time(),
332
+ 'is_new' => 1,
333
+ ) );
334
+ }
335
+ }
336
+ add_action( 'bp_activity_sent_mention_email', 'bp_activity_at_mention_add_notification', 10, 5 );
337
+
338
+ /**
339
+ * Remove activity notifications when a user clicks on them.
340
+ *
341
+ * @since BuddyPress (1.5)
342
+ *
343
+ * @uses bp_notifications_mark_all_notifications_by_type()
344
+ */
345
+ function bp_activity_remove_screen_notifications() {
346
+ if ( bp_is_active( 'notifications' ) ) {
347
+ bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->activity->id, 'new_at_mention' );
348
+ }
349
+ }
350
+ add_action( 'bp_activity_screen_my_activity', 'bp_activity_remove_screen_notifications' );
351
+ add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications' );
352
+ add_action( 'bp_activity_screen_mentions', 'bp_activity_remove_screen_notifications' );
353
+
bp-activity/bp-activity-screens.php CHANGED
@@ -128,20 +128,6 @@ function bp_activity_screen_mentions() {
128
bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
129
}
130
131
- /**
132
- * Remove activity notifications when a user clicks on them.
133
- *
134
- * @since BuddyPress (1.5)
135
- *
136
- * @uses bp_core_mark_all_notifications_by_type()
137
- */
138
- function bp_activity_remove_screen_notifications() {
139
- bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->activity->id, 'new_at_mention' );
140
- }
141
- add_action( 'bp_activity_screen_my_activity', 'bp_activity_remove_screen_notifications' );
142
- add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications' );
143
- add_action( 'bp_activity_screen_mentions', 'bp_activity_remove_screen_notifications' );
144
-
145
/**
146
* Reset the logged-in user's new mentions data when he visits his mentions screen.
147
*
128
bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
129
}
130
131
/**
132
* Reset the logged-in user's new mentions data when he visits his mentions screen.
133
*
bp-core/admin/bp-core-components.php CHANGED
@@ -377,7 +377,7 @@ function bp_core_admin_get_components( $type = 'all' ) {
377
),
378
'activity' => array(
379
'title' => __( 'Activity Streams', 'buddypress' ),
380
- 'description' => __( 'Global, personal, and group activity streams with threaded commenting, direct posting, favoriting and @mentions, all with full RSS feed and email notification support.', 'buddypress' )
381
),
382
'notifications' => array(
383
'title' => __( 'Notifications', 'buddypress' ),
377
),
378
'activity' => array(
379
'title' => __( 'Activity Streams', 'buddypress' ),
380
+ 'description' => __( 'Global, personal, and group activity streams with threaded commenting, direct posting, favoriting, and @mentions, all with full RSS feed and email notification support.', 'buddypress' )
381
),
382
'notifications' => array(
383
'title' => __( 'Notifications', 'buddypress' ),
bp-core/admin/bp-core-functions.php CHANGED
@@ -383,6 +383,7 @@ function bp_core_admin_tabs( $active_tab = '' ) {
383
384
// If forums component is active, add additional tab
385
if ( bp_is_active( 'forums' ) && class_exists( 'BP_Forums_Component' ) ) {
386
// enqueue thickbox
387
wp_enqueue_script( 'thickbox' );
388
wp_enqueue_style( 'thickbox' );
@@ -393,11 +394,14 @@ function bp_core_admin_tabs( $active_tab = '' ) {
393
);
394
}
395
396
// Loop through tabs and build navigation
397
foreach ( array_values( $tabs ) as $tab_data ) {
398
$is_current = (bool) ( $tab_data['name'] == $active_tab );
399
$tab_class = $is_current ? $active_class : $idle_class;
400
- $tabs_html .= '<a href="' . $tab_data['href'] . '" class="' . $tab_class . '">' . $tab_data['name'] . '</a>';
401
}
402
403
// Output the tabs
@@ -508,25 +512,32 @@ function bp_core_add_contextual_help_content( $tab = '' ) {
508
509
switch ( $tab ) {
510
case 'bp-comp-overview' :
511
- return '<p>' . __( 'By default, all BuddyPress components are enabled. You can selectively disable any of the components by using the form. Your BuddyPress installation will continue to function. However, the features of the disabled components will no longer be accessible to anyone using the site.', 'buddypress' ) . '</p>';
512
break;
513
514
- case'bp-page-overview' :
515
- return '<p>' . __( 'BuddyPress Components use WordPress Pages for their root directory/archive pages. Here you can change the page associations for each active component.', 'buddypress' ) . '</p>';
516
break;
517
518
case 'bp-settings-overview' :
519
- return '<p>' . __( 'Extra configuration settings.', 'buddypress' ) . '</p>';
520
break;
521
522
case 'bp-profile-overview' :
523
- return '<p>' . __( 'Your users will distinguish themselves through their profile page. Create relevant profile fields that will show on each users profile.</br></br>Note: Any fields in the first group will appear on the signup page.', 'buddypress' ) . '</p>';
524
break;
525
526
default:
527
- return false;
528
break;
529
}
530
}
531
532
/** Separator *****************************************************************/
@@ -692,7 +703,6 @@ function bp_admin_do_wp_nav_menu_meta_box() {
692
$args = array( 'walker' => $walker );
693
694
$post_type_name = 'buddypress';
695
- $current_tab = 'loggedin';
696
697
$tabs = array();
698
@@ -751,17 +761,17 @@ function bp_admin_do_wp_nav_menu_meta_box() {
751
* @since BuddyPress (1.9.0)
752
*/
753
function bp_admin_wp_nav_menu_restrict_items() {
754
- ?>
755
<script type="text/javascript">
756
jQuery( '#menu-to-edit').on( 'click', 'a.item-edit', function() {
757
var settings = jQuery(this).closest( '.menu-item-bar' ).next( '.menu-item-settings' );
758
var css_class = settings.find( '.edit-menu-item-classes' );
759
760
- if( css_class.val().indexOf( 'bp-menu' ) == 0 ) {
761
css_class.attr( 'readonly', 'readonly' );
762
settings.find( '.field-url' ).css( 'display', 'none' );
763
}
764
});
765
</script>
766
- <?php
767
}
383
384
// If forums component is active, add additional tab
385
if ( bp_is_active( 'forums' ) && class_exists( 'BP_Forums_Component' ) ) {
386
+
387
// enqueue thickbox
388
wp_enqueue_script( 'thickbox' );
389
wp_enqueue_style( 'thickbox' );
394
);
395
}
396
397
+ // Allow the tabs to be filtered
398
+ $tabs = apply_filters( 'bp_core_admin_tabs', $tabs );
399
+
400
// Loop through tabs and build navigation
401
foreach ( array_values( $tabs ) as $tab_data ) {
402
$is_current = (bool) ( $tab_data['name'] == $active_tab );
403
$tab_class = $is_current ? $active_class : $idle_class;
404
+ $tabs_html .= '<a href="' . esc_url( $tab_data['href'] ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab_data['name'] ) . '</a>';
405
}
406
407
// Output the tabs
512
513
switch ( $tab ) {
514
case 'bp-comp-overview' :
515
+ $retval = __( 'By default, all BuddyPress components are enabled. You can selectively disable any of the components by using the form. Your BuddyPress installation will continue to function. However, the features of the disabled components will no longer be accessible to anyone using the site.', 'buddypress' );
516
break;
517
518
+ case 'bp-page-overview' :
519
+ $retval = __( 'BuddyPress Components use WordPress Pages for their root directory/archive pages. Here you can change the page associations for each active component.', 'buddypress' );
520
break;
521
522
case 'bp-settings-overview' :
523
+ $retval = __( 'Extra configuration settings.', 'buddypress' );
524
break;
525
526
case 'bp-profile-overview' :
527
+ $retval = __( 'Your users will distinguish themselves through their profile page. Create relevant profile fields that will show on each users profile.</br></br>Note: Any fields in the first group will appear on the signup page.', 'buddypress' );
528
break;
529
530
default:
531
+ $retval = false;
532
break;
533
}
534
+
535
+ // Wrap text in a paragraph tag
536
+ if ( !empty( $retval ) ) {
537
+ $retval = '<p>' . $retval . '</p>';
538
+ }
539
+
540
+ return $retval;
541
}
542
543
/** Separator *****************************************************************/
703
$args = array( 'walker' => $walker );
704
705
$post_type_name = 'buddypress';
706
707
$tabs = array();
708
761
* @since BuddyPress (1.9.0)
762
*/
763
function bp_admin_wp_nav_menu_restrict_items() {
764
+ ?>
765
<script type="text/javascript">
766
jQuery( '#menu-to-edit').on( 'click', 'a.item-edit', function() {
767
var settings = jQuery(this).closest( '.menu-item-bar' ).next( '.menu-item-settings' );
768
var css_class = settings.find( '.edit-menu-item-classes' );
769
770
+ if( css_class.val().indexOf( 'bp-menu' ) === 0 ) {
771
css_class.attr( 'readonly', 'readonly' );
772
settings.find( '.field-url' ).css( 'display', 'none' );
773
}
774
});
775
</script>
776
+ <?php
777
}
bp-core/bp-core-admin.php CHANGED
@@ -570,64 +570,62 @@ class BP_Admin {
570
571
<h4 class="wp-people-group"><?php _e( 'Recent Rockstars', 'buddypress' ); ?></h4>
572
<ul class="wp-people-group " id="wp-people-group-rockstars">
573
- <li class="wp-person" id="wp-person-karmatosed">
574
- <a href="http://profiles.wordpress.org/karmatosed"><img src="http://0.gravatar.com/avatar/d36d2c1821af9249b69ff7f5ed60529b?s=60" class="gravatar" alt="Tammie Lister" /></a>
575
- <a class="web" href="http://profiles.wordpress.org/karmatosed">Tammie Lister</a>
576
- <span class="title"><?php _e( 'Design Officer', 'buddypress' ); ?></span>
577
</li>
578
<li class="wp-person" id="wp-person-mercime">
579
<a href="http://profiles.wordpress.org/mercime"><img src="http://0.gravatar.com/avatar/fae451be6708241627983570a1a1817a?s=60" class="gravatar" alt="Mercime" /></a>
580
<a class="web" href="http://profiles.wordpress.org/mercime">Mercime</a>
581
- <span class="title"><?php _e( 'Support Officer', 'buddypress' ); ?></span>
582
</li>
583
</ul>
584
585
- <h4 class="wp-people-group"><?php _e( 'Core Contributors to BuddyPress 1.8', 'buddypress' ); ?></h4>
586
<p class="wp-credits-list">
587
- <a href="http://profiles.wordpress.org/boonebgorges">boonebgorges</a>,
588
- <a href="http://profiles.wordpress.org/borkweb">borkweb</a>,
589
- <a href="http://profiles.wordpress.org/chouf1">chouf1</a>,
590
- <a href="http://profiles.wordpress.org/chriskeeble">chriskeeble</a>,
591
- <a href="http://profiles.wordpress.org/chroniko">chroniko</a>,
592
- <a href="http://profiles.wordpress.org/czarate">czarate</a>,
593
- <a href="http://profiles.wordpress.org/danbp">danbp</a>,
594
- <a href="http://profiles.wordpress.org/dcavins">dcavins</a>,
595
- <a href="http://profiles.wordpress.org/dcowgill">dcowgill</a>,
596
- <a href="http://profiles.wordpress.org/ddean">ddean</a>,
597
- <a href="http://profiles.wordpress.org/djpaul">djpaul</a>,
598
- <a href="http://profiles.wordpress.org/dontdream">dontdream</a>,
599
- <a href="http://profiles.wordpress.org/eggproject">eggproject</a>,
600
- <a href="http://profiles.wordpress.org/ericlewis">ericlewis</a>,
601
- grahamwashbroo,
602
- <a href="http://profiles.wordpress.org/hnla">hnla</a>,
603
- <a href="http://profiles.wordpress.org/imath">imath</a>,
604
- <a href="http://profiles.wordpress.org/johnjamesjacoby">johnjamesjacoby</a>,
605
- <a href="http://profiles.wordpress.org/karmatosed">karmatosed</a>,
606
- <a href="http://profiles.wordpress.org/lenasterg">lenasterg</a>,
607
- <a href="http://profiles.wordpress.org/magnus78">magnus78</a>,
608
- <a href="http://profiles.wordpress.org/megainfo">megainfo</a>,
609
- <a href="http://profiles.wordpress.org/rogercoathup">rogercoathup</a>,
610
- <a href="http://profiles.wordpress.org/mercime">mercime</a>,
611
- <a href="http://profiles.wordpress.org/merty">merty</a>,
612
- <a href="http://profiles.wordpress.org/mjustice">mjustice</a>,
613
- <a href="http://profiles.wordpress.org/modemlooper">modemlooper</a>,
614
- <a href="http://profiles.wordpress.org/mort3n">mort3n</a>,
615
- <a href="http://profiles.wordpress.org/mukkundthanki">mukkundthanki</a>,
616
- <a href="http://profiles.wordpress.org/nacin">nacin</a>,
617
- <a href="http://profiles.wordpress.org/needle">needle</a>,
618
- <a href="http://profiles.wordpress.org/r-a-y">r-a-y</a>,
619
- <a href="http://profiles.wordpress.org/saurabhshukla">saurabhshukla</a>,
620
- <a href="http://profiles.wordpress.org/sbrajesh">sbrajesh</a>,
621
- <a href="http://profiles.wordpress.org/SergeyBiryukov">SergeyBiryukov</a>,
622
- <a href="http://profiles.wordpress.org/SGr33n">SGr33n</a>,
623
- <a href="http://profiles.wordpress.org/shanebp">shanebp</a>,
624
- <a href="http://profiles.wordpress.org/splatte">splatte</a>,
625
- <a href="http://profiles.wordpress.org/thebrandonallen">thebrandonallen</a>,
626
- <a href="http://profiles.wordpress.org/themightymo">themightymo</a>,
627
- <a href="http://profiles.wordpress.org/tivnet">tivnet</a>,
628
- <a href="http://profiles.wordpress.org/trishasalas">trishasalas</a>,
629
- <a href="http://profiles.wordpress.org/vegasgeek">vegasgeek</a>,
630
- <a href="http://profiles.wordpress.org/wpdennis">wpdennis</a>
631
</p>
632
633
<div class="return-to-dashboard">
570
571
<h4 class="wp-people-group"><?php _e( 'Recent Rockstars', 'buddypress' ); ?></h4>
572
<ul class="wp-people-group " id="wp-people-group-rockstars">
573
+ <li class="wp-person" id="wp-person-imath">
574
+ <a href="http://profiles.wordpress.org/imath"><img src="http://0.gravatar.com/avatar/8b208ca408dad63888253ee1800d6a03?s=60" class="gravatar" alt="Mathieu Viet" /></a>
575
+ <a class="web" href="http://profiles.wordpress.org/imath">Mathieu Viet</a>
576
+ </li>
577
+ <li class="wp-person" id="wp-person-hnla">
578
+ <a href="http://profiles.wordpress.org/hnla"><img src="http://0.gravatar.com/avatar/3860c955aa3f79f13b92826ae47d07fe?s=60" class="gravatar" alt="Hugo Ashmore" /></a>
579
+ <a class="web" href="http://profiles.wordpress.org/hnla">Hugo Ashmore</a>
580
</li>
581
<li class="wp-person" id="wp-person-mercime">
582
<a href="http://profiles.wordpress.org/mercime"><img src="http://0.gravatar.com/avatar/fae451be6708241627983570a1a1817a?s=60" class="gravatar" alt="Mercime" /></a>
583
<a class="web" href="http://profiles.wordpress.org/mercime">Mercime</a>
584
+ </li>
585
+ <li class="wp-person" id="wp-person-karmatosed">
586
+ <a href="http://profiles.wordpress.org/karmatosed"><img src="http://0.gravatar.com/avatar/d36d2c1821af9249b69ff7f5ed60529b?s=60" class="gravatar" alt="Tammie Lister" /></a>
587
+ <a class="web" href="http://profiles.wordpress.org/karmatosed">Tammie Lister</a>
588
</li>
589
</ul>
590
591
+ <h4 class="wp-people-group"><?php _e( 'Contributors to BuddyPress 1.9', 'buddypress' ); ?></h4>
592
<p class="wp-credits-list">
593
+ <a href="http://profiles.wordpress.org/AliMH/">AliMH</a>,
594
+ <a href="http://profiles.wordpress.org/asakurayoh/">asakurayoh</a>,
595
+ <a href="http://profiles.wordpress.org/boonebgorges/">boonebgorges</a>,
596
+ <a href="http://profiles.wordpress.org/burakali/">burakali</a>,
597
+ <a href="http://profiles.wordpress.org/dcavins/">dcavins</a>,
598
+ <a href="http://profiles.wordpress.org/ddean/">ddean</a>,
599
+ <a href="http://profiles.wordpress.org/DennisSmolek/">DennisSmolek</a>,
600
+ <a href="http://profiles.wordpress.org/dimensionmedia/">dimensionmedia</a>,
601
+ <a href="http://profiles.wordpress.org/dtc7240/">dtc7240</a>,
602
+ <a href="http://profiles.wordpress.org/ericlewis/">ericlewis</a>,
603
+ <a href="http://profiles.wordpress.org/gametako/">gametako</a>,
604
+ <a href="http://profiles.wordpress.org/geoffroycochard/">geoffroycochard</a>,
605
+ <a href="http://profiles.wordpress.org/hanni/">hanni</a>,
606
+ <a href="http://profiles.wordpress.org/henrywright/">henrywright</a>,
607
+ <a href="http://profiles.wordpress.org/hnla/">hnla</a>,
608
+ <a href="http://profiles.wordpress.org/imath/">imath</a>,
609
+ <a href="http://profiles.wordpress.org/johnjamesjacoby/">johnjamesjacoby</a>,
610
+ <a href="http://profiles.wordpress.org/lenasterg/">lenasterg</a>,
611
+ <a href="http://profiles.wordpress.org/mboynes/">mboynes</a>,
612
+ <a href="http://profiles.wordpress.org/megainfo/">megainfo</a>,
613
+ <a href="http://profiles.wordpress.org/Mike_Cowobo/">Mike_Cowobo</a>,
614
+ <a href="http://profiles.wordpress.org/modemlooper/">modemlooper</a>,
615
+ <a href="http://profiles.wordpress.org/olivM/">olivM</a>,
616
+ <a href="http://profiles.wordpress.org/needle/">needle</a>,
617
+ <a href="http://profiles.wordpress.org/netweblogic/">netweblogic</a>,
618
+ <a href="http://profiles.wordpress.org/r-a-y/">r-a-y</a>,
619
+ <a href="http://profiles.wordpress.org/ryderlewis/">ryderlewis</a>,
620
+ <a href="http://profiles.wordpress.org/sbrajesh/">sbrajesh</a>,
621
+ <a href="http://profiles.wordpress.org/sgr33n/">sgr33n</a>,
622
+ <a href="http://profiles.wordpress.org/sooskriszta/">sooskriszta</a>,
623
+ <a href="http://profiles.wordpress.org/terraling/">terraling</a>,
624
+ <a href="http://profiles.wordpress.org/tomdxw/">tomdxw</a>,
625
+ <a href="http://profiles.wordpress.org/trishasalas/">trishasalas</a>,
626
+ <a href="http://profiles.wordpress.org/vhauri/">vhauri</a>,
627
+ <a href="http://profiles.wordpress.org/williamsba1/">williamsba1</a>,
628
+ <a href="http://profiles.wordpress.org/wpdennis/">wpdennis</a>
629
</p>
630
631
<div class="return-to-dashboard">
bp-core/bp-core-classes.php CHANGED
@@ -23,8 +23,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
23
* @type string $type Determines sort order. Select from 'newest', 'active',
24
* 'online', 'random', 'popular', 'alphabetical'. Default: 'newest'.
25
* @type int $per_page Number of results to return. Default: 0 (no limit).
26
- * @type int $page Page offset (together with $per_page). Default: 0 (no
27
- * limit).
28
* @type int $user_id ID of a user. If present, and if the friends
29
* component is activated, results will be limited to the friends of
30
* that user. Default: 0.
@@ -311,6 +310,11 @@ class BP_User_Query {
311
$sql['order'] = "ASC";
312
}
313
314
break;
315
316
// Any other 'type' falls through
23
* @type string $type Determines sort order. Select from 'newest', 'active',
24
* 'online', 'random', 'popular', 'alphabetical'. Default: 'newest'.
25
* @type int $per_page Number of results to return. Default: 0 (no limit).
26
+ * @type int $page Page offset (together with $per_page). Default: 1.
27
* @type int $user_id ID of a user. If present, and if the friends
28
* component is activated, results will be limited to the friends of
29
* that user. Default: 0.
310
$sql['order'] = "ASC";
311
}
312
313
+ // Alphabetical queries ignore last_activity, while BP uses last_activity
314
+ // to infer spam/deleted/non-activated users. To ensure that these users
315
+ // are filtered out, we add an appropriate sub-query.
316
+ $sql['where'][] = "u.{$this->uid_name} IN ( SELECT ID FROM {$wpdb->users} WHERE " . bp_core_get_status_sql( '' ) . " )";
317
+
318
break;
319
320
// Any other 'type' falls through
bp-core/bp-core-filters.php CHANGED
@@ -348,6 +348,11 @@ function bp_modify_page_title( $title, $sep, $seplocation ) {
348
if ( bp_is_blog_page() )
349
return $title;
350
351
// If this is the front page of the site, return WP's title
352
if ( is_front_page() || is_home() )
353
return $title;
348
if ( bp_is_blog_page() )
349
return $title;
350
351
+ // If this is a 404, let WordPress handle it
352
+ if ( is_404() ) {
353
+ return $title;
354
+ }
355
+
356
// If this is the front page of the site, return WP's title
357
if ( is_front_page() || is_home() )
358
return $title;
bp-friends/bp-friends-activity.php CHANGED
@@ -32,28 +32,25 @@ if ( !defined( 'ABSPATH' ) ) exit;
32
* @return bool See {@link bp_activity_add()}.
33
*/
34
function friends_record_activity( $args = '' ) {
35
- global $bp;
36
37
- if ( !bp_is_active( 'activity' ) )
38
return false;
39
40
- $defaults = array (
41
'user_id' => bp_loggedin_user_id(),
42
'action' => '',
43
'content' => '',
44
'primary_link' => '',
45
- 'component' => $bp->friends->id,
46
'type' => false,
47
'item_id' => false,
48
'secondary_item_id' => false,
49
'recorded_time' => bp_core_current_time(),
50
'hide_sitewide' => false
51
- );
52
-
53
- $r = wp_parse_args( $args, $defaults );
54
- extract( $r, EXTR_SKIP );
55
56
- return bp_activity_add( array( '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 ) );
57
}
58
59
/**
@@ -71,26 +68,32 @@ function friends_record_activity( $args = '' ) {
71
* @return bool True on success, false on failure.
72
*/
73
function friends_delete_activity( $args ) {
74
- global $bp;
75
-
76
- if ( bp_is_active( 'activity' ) ) {
77
- extract( (array) $args );
78
- bp_activity_delete_by_item_id( array( 'item_id' => $item_id, 'component' => $bp->friends->id, 'type' => $type, 'user_id' => $user_id ) );
79
}
80
}
81
82
/**
83
* Register the activity actions for bp-friends.
84
*/
85
function friends_register_activity_actions() {
86
- global $bp;
87
88
- if ( !bp_is_active( 'activity' ) )
89
return false;
90
91
// These two added in BP 1.6
92
bp_activity_set_action( $bp->friends->id, 'friendship_accepted', __( 'Friendships accepted', 'buddypress' ) );
93
- bp_activity_set_action( $bp->friends->id, 'friendship_created', __( 'New friendships', 'buddypress' ) );
94
95
// < BP 1.6 backpat
96
bp_activity_set_action( $bp->friends->id, 'friends_register_activity_action', __( 'New friendship created', 'buddypress' ) );
@@ -100,60 +103,44 @@ function friends_register_activity_actions() {
100
add_action( 'bp_register_activity_actions', 'friends_register_activity_actions' );
101
102
/**
103
- * Notification formatting callback for bp-friends notifications.
104
*
105
- * @param string $action The kind of notification being rendered.
106
- * @param int $item_id The primary item ID.
107
- * @param int $secondary_item_id The secondary item ID.
108
- * @param int $total_items The total number of messaging-related notifications
109
- * waiting for the user.
110
- * @param string $format 'string' for BuddyBar-compatible notifications;
111
- * 'array' for WP Toolbar. Default: 'string'.
112
- * @return array|string
113
*/
114
- function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
115
-
116
- switch ( $action ) {
117
- case 'friendship_accepted':
118
- $link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends' );
119
-
120
- // Set up the string and the filter
121
- if ( (int) $total_items > 1 ) {
122
- $text = sprintf( __( '%d friends accepted your friendship requests', 'buddypress' ), (int) $total_items );
123
- $filter = 'bp_friends_multiple_friendship_accepted_notification';
124
- } else {
125
- $text = sprintf( __( '%s accepted your friendship request', 'buddypress' ), bp_core_get_user_displayname( $item_id ) );
126
- $filter = 'bp_friends_single_friendship_accepted_notification';
127
- }
128
-
129
- break;
130
-
131
- case 'friendship_request':
132
- $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/?new';
133
-
134
- // Set up the string and the filter
135
- if ( (int) $total_items > 1 ) {
136
- $text = sprintf( __( 'You have %d pending friendship requests', 'buddypress' ), (int) $total_items );
137
- $filter = 'bp_friends_multiple_friendship_request_notification';
138
- } else {
139
- $text = sprintf( __( 'You have a friendship request from %s', 'buddypress' ), bp_core_get_user_displayname( $item_id ) );
140
- $filter = 'bp_friends_single_friendship_request_notification';
141
- }
142
-
143
- break;
144
- }
145
146
- // Return either an HTML link or an array, depending on the requested format
147
- if ( 'string' == $format ) {
148
- $return = apply_filters( $filter, '<a href="' . $link . '">' . $text . '</a>', (int) $total_items );
149
- } else {
150
- $return = apply_filters( $filter, array(
151
- 'link' => $link,
152
- 'text' => $text
153
- ), (int) $total_items );
154
}
155
156
- do_action( 'friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $return );
157
-
158
- return $return;
159
}
32
* @return bool See {@link bp_activity_add()}.
33
*/
34
function friends_record_activity( $args = '' ) {
35
36
+ if ( ! bp_is_active( 'activity' ) ) {
37
return false;
38
+ }
39
40
+ $r = wp_parse_args( $args, array(
41
'user_id' => bp_loggedin_user_id(),
42
'action' => '',
43
'content' => '',
44
'primary_link' => '',
45
+ 'component' => buddypress()->friends->id,
46
'type' => false,
47
'item_id' => false,
48
'secondary_item_id' => false,
49
'recorded_time' => bp_core_current_time(),
50
'hide_sitewide' => false
51
+ ) );
52
53
+ return bp_activity_add( $r );
54
}
55
56
/**
68
* @return bool True on success, false on failure.
69
*/
70
function friends_delete_activity( $args ) {
71
+ if ( ! bp_is_active( 'activity' ) ) {
72
+ return;
73
}
74
+
75
+ bp_activity_delete_by_item_id( array(
76
+ 'component' => buddypress()->friends->id,
77
+ 'item_id' => $args['item_id'],
78
+ 'type' => $args['type'],
79
+ 'user_id' => $args['user_id']
80
+ ) );
81
}
82
83
/**
84
* Register the activity actions for bp-friends.
85
*/
86
function friends_register_activity_actions() {
87
88
+ if ( !bp_is_active( 'activity' ) ) {
89
return false;
90
+ }
91
+
92
+ $bp = buddypress();
93
94
// These two added in BP 1.6
95
bp_activity_set_action( $bp->friends->id, 'friendship_accepted', __( 'Friendships accepted', 'buddypress' ) );
96
+ bp_activity_set_action( $bp->friends->id, 'friendship_created', __( 'New friendships', 'buddypress' ) );
97
98
// < BP 1.6 backpat
99
bp_activity_set_action( $bp->friends->id, 'friends_register_activity_action', __( 'New friendship created', 'buddypress' ) );
103
add_action( 'bp_register_activity_actions', 'friends_register_activity_actions' );
104
105
/**
106
+ * Add activity stream items when one members accepts another members request
107
+ * for virtual friendship.
108
+ *
109
+ * @since BuddyPress (1.9.0)
110
*
111
+ * @param int $friendship_id
112
+ * @param int $initiator_user_id
113
+ * @param int $friend_user_id
114
+ * @param object $friendship Optional
115
*/
116
+ function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_user_id, $friend_user_id, $friendship = false ) {
117
118
+ // Bail if Activity component is not active
119
+ if ( ! bp_is_active( 'activity' ) ) {
120
+ return;
121
}
122
123
+ // Get links to both members profiles
124
+ $initiator_link = bp_core_get_userlink( $initiator_user_id );
125
+ $friend_link = bp_core_get_userlink( $friend_user_id );
126
+
127
+ // Record in activity streams for the initiator
128
+ friends_record_activity( array(
129
+ 'user_id' => $initiator_user_id,
130
+ 'type' => 'friendship_created',
131
+ 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), $friendship ),
132
+ 'item_id' => $friendship_id,
133
+ 'secondary_item_id' => $friend_user_id
134
+ ) );
135
+
136
+ // Record in activity streams for the friend
137
+ friends_record_activity( array(
138
+ 'user_id' => $friend_user_id,
139
+ 'type' => 'friendship_created',
140
+ 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), $friendship ),
141
+ 'item_id' => $friendship_id,
142
+ 'secondary_item_id' => $initiator_user_id,
143
+ 'hide_sitewide' => true // We've already got the first entry site wide
144
+ ) );
145
}
146
+ add_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4 );
bp-friends/bp-friends-cache.php CHANGED
@@ -10,7 +10,6 @@
10
* @subpackage FriendsCaching
11
*/
12
13
-
14
// Exit if accessed directly
15
if ( !defined( 'ABSPATH' ) ) exit;
16
@@ -28,16 +27,6 @@ function friends_clear_friend_object_cache( $friendship_id ) {
28
wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' );
29
}
30
31
- /**
32
- * Clear friend-related notifications when ?new=1.
33
- */
34
- function friends_clear_friend_notifications() {
35
- if ( isset( $_GET['new'] ) ) {
36
- bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
37
- }
38
- }
39
- add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
40
-
41
// List actions to clear object caches on
42
add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' );
43
add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' );
10
* @subpackage FriendsCaching
11
*/
12
13
// Exit if accessed directly
14
if ( !defined( 'ABSPATH' ) ) exit;
15
27
wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' );
28
}
29
30
// List actions to clear object caches on
31
add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' );
32
add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' );
bp-friends/bp-friends-functions.php CHANGED
@@ -29,43 +29,43 @@ if ( !defined( 'ABSPATH' ) ) exit;
29
* @return bool True on success, false on failure.
30
*/
31
function friends_add_friend( $initiator_userid, $friend_userid, $force_accept = false ) {
32
- global $bp;
33
34
$friendship = new BP_Friends_Friendship;
35
-
36
- if ( (int) $friendship->is_confirmed )
37
return true;
38
39
$friendship->initiator_user_id = $initiator_userid;
40
$friendship->friend_user_id = $friend_userid;
41
$friendship->is_confirmed = 0;
42
$friendship->is_limited = 0;
43
$friendship->date_created = bp_core_current_time();
44
45
- if ( $force_accept )
46
$friendship->is_confirmed = 1;
47
48
- if ( $friendship->save() ) {
49
-
50
- if ( !$force_accept ) {
51
- // Add the on screen notification
52
- bp_core_add_notification( $friendship->initiator_user_id, $friendship->friend_user_id, $bp->friends->id, 'friendship_request' );
53
-
54
- // Send the email notification
55
- friends_notification_new_request( $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
56
-
57
- do_action( 'friends_friendship_requested', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
58
- } else {
59
- // Update friend totals
60
- friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id, 'add' );
61
62
- do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
63
- }
64
65
- return true;
66
}
67
68
- return false;
69
}
70
71
/**
@@ -111,45 +111,17 @@ function friends_remove_friend( $initiator_userid, $friend_userid ) {
111
* @return bool True on success, false on failure.
112
*/
113
function friends_accept_friendship( $friendship_id ) {
114
- global $bp;
115
116
$friendship = new BP_Friends_Friendship( $friendship_id, true, false );
117
118
- if ( !$friendship->is_confirmed && BP_Friends_Friendship::accept( $friendship_id ) ) {
119
- friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id );
120
-
121
- // Remove the friend request notice
122
- bp_core_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
123
-
124
- // Add a friend accepted notice for the initiating user
125
- bp_core_add_notification( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_accepted' );
126
-
127
- $initiator_link = bp_core_get_userlink( $friendship->initiator_user_id );
128
- $friend_link = bp_core_get_userlink( $friendship->friend_user_id );
129
130
- // Record in activity streams for the initiator
131
- friends_record_activity( array(
132
- 'user_id' => $friendship->initiator_user_id,
133
- 'type' => 'friendship_created',
134
- 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), $friendship ),
135
- 'item_id' => $friendship_id,
136
- 'secondary_item_id' => $friendship->friend_user_id
137
- ) );
138
-
139
- // Record in activity streams for the friend
140
- friends_record_activity( array(
141
- 'user_id' => $friendship->friend_user_id,
142
- 'type' => 'friendship_created',
143
- 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), $friendship ),
144
- 'item_id' => $friendship_id,
145
- 'secondary_item_id' => $friendship->initiator_user_id,
146
- 'hide_sitewide' => true // We've already got the first entry site wide
147
- ) );
148
-
149
- // Send the email notification
150
- friends_notification_accepted_request( $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
151
152
- do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
153
154
return true;
155
}
@@ -164,15 +136,9 @@ function friends_accept_friendship( $friendship_id ) {
164
* @return bool True on success, false on failure.
165
*/
166
function friends_reject_friendship( $friendship_id ) {
167
- global $bp;
168
-
169
$friendship = new BP_Friends_Friendship( $friendship_id, true, false );
170
171
- if ( !$friendship->is_confirmed && BP_Friends_Friendship::reject( $friendship_id ) ) {
172
-
173
- // Remove the friend request notice
174
- bp_core_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
175
-
176
do_action_ref_array( 'friends_friendship_rejected', array( $friendship_id, &$friendship ) );
177
return true;
178
}
@@ -189,15 +155,10 @@ function friends_reject_friendship( $friendship_id ) {
189
* @return bool True on success, false on failure.
190
*/
191
function friends_withdraw_friendship( $initiator_userid, $friend_userid ) {
192
- global $bp;
193
-
194
$friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
195
$friendship = new BP_Friends_Friendship( $friendship_id, true, false );
196
197
- if ( !$friendship->is_confirmed && BP_Friends_Friendship::withdraw( $friendship_id ) ) {
198
- // Remove the friend request notice
199
- bp_core_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
200
-
201
do_action_ref_array( 'friends_friendship_whithdrawn', array( $friendship_id, &$friendship ) );
202
return true;
203
}
@@ -566,7 +527,6 @@ function friends_update_friend_totals( $initiator_user_id, $friend_user_id, $sta
566
* @param int $user_id ID of the user whose friend data is being removed.
567
*/
568
function friends_remove_data( $user_id ) {
569
- global $bp;
570
571
do_action( 'friends_before_remove_data', $user_id );
572
@@ -575,9 +535,6 @@ function friends_remove_data( $user_id ) {
575
// Remove usermeta
576
bp_delete_user_meta( $user_id, 'total_friend_count' );
577
578
- // Remove friendship requests FROM user
579
- bp_core_delete_notifications_from_user( $user_id, $bp->friends->id, 'friendship_request' );
580
-
581
do_action( 'friends_remove_data', $user_id );
582
}
583
add_action( 'wpmu_delete_user', 'friends_remove_data' );
29
* @return bool True on success, false on failure.
30
*/
31
function friends_add_friend( $initiator_userid, $friend_userid, $force_accept = false ) {
32
33
+ // Check if already friends, and bail if so
34
$friendship = new BP_Friends_Friendship;
35
+ if ( (int) $friendship->is_confirmed ) {
36
return true;
37
+ }
38
39
+ // Setup the friendship data
40
$friendship->initiator_user_id = $initiator_userid;
41
$friendship->friend_user_id = $friend_userid;
42
$friendship->is_confirmed = 0;
43
$friendship->is_limited = 0;
44
$friendship->date_created = bp_core_current_time();
45
46
+ if ( !empty( $force_accept ) ) {
47
$friendship->is_confirmed = 1;
48
+ }
49
50
+ // Bail if friendship could not be saved (how sad!)
51
+ if ( ! $friendship->save() ) {
52
+ return false;
53
+ }
54
55
+ // Send notifications
56
+ if ( empty( $force_accept ) ) {
57
+ $action = 'friends_friendship_requested';
58
59
+ // Update friend totals
60
+ } else {
61
+ $action = 'friends_friendship_accepted';
62
+ friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id, 'add' );
63
}
64
65
+ // Call the above titled action and pass friendship data into it
66
+ do_action( $action, $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship );
67
+
68
+ return true;
69
}
70
71
/**
111
* @return bool True on success, false on failure.
112
*/
113
function friends_accept_friendship( $friendship_id ) {
114
115
+ // Get the friesdhip data
116
$friendship = new BP_Friends_Friendship( $friendship_id, true, false );
117
118
+ // Accepting friendship
119
+ if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::accept( $friendship_id ) ) {
120
121
+ // Bump the friendship counts
122
+ friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id );
123
124
+ do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship );
125
126
return true;
127
}
136
* @return bool True on success, false on failure.
137
*/
138
function friends_reject_friendship( $friendship_id ) {
139
$friendship = new BP_Friends_Friendship( $friendship_id, true, false );
140
141
+ if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::reject( $friendship_id ) ) {
142
do_action_ref_array( 'friends_friendship_rejected', array( $friendship_id, &$friendship ) );
143
return true;
144
}
155
* @return bool True on success, false on failure.
156
*/
157
function friends_withdraw_friendship( $initiator_userid, $friend_userid ) {
158
$friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
159
$friendship = new BP_Friends_Friendship( $friendship_id, true, false );
160
161
+ if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::withdraw( $friendship_id ) ) {
162
do_action_ref_array( 'friends_friendship_whithdrawn', array( $friendship_id, &$friendship ) );
163
return true;
164
}
527
* @param int $user_id ID of the user whose friend data is being removed.
528
*/
529
function friends_remove_data( $user_id ) {
530
531
do_action( 'friends_before_remove_data', $user_id );
532
535
// Remove usermeta
536
bp_delete_user_meta( $user_id, 'total_friend_count' );
537
538
do_action( 'friends_remove_data', $user_id );
539
}
540
add_action( 'wpmu_delete_user', 'friends_remove_data' );
bp-friends/bp-friends-notifications.php CHANGED
@@ -13,6 +13,8 @@
13
// Exit if accessed directly
14
if ( !defined( 'ABSPATH' ) ) exit;
15
16
/**
17
* Send notifications related to a new friendship request.
18
*
@@ -54,8 +56,8 @@ To view %3$s\'s profile: %4$s
54
$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
55
}
56
57
- /* Send the message */
58
- $to = apply_filters( 'friends_notification_new_request_to', $to );
59
$subject = apply_filters( 'friends_notification_new_request_subject', $subject, $initiator_name );
60
$message = apply_filters( 'friends_notification_new_request_message', $message, $initiator_name, $initiator_link, $all_requests_link, $settings_link );
61
@@ -63,6 +65,7 @@ To view %3$s\'s profile: %4$s
63
64
do_action( 'bp_friends_sent_request_email', $friend_id, $subject, $message, $friendship_id, $initiator_id );
65
}
66
67
/**
68
* Send notifications related to the acceptance of a friendship request.
@@ -102,8 +105,8 @@ To view %2$s\'s profile: %3$s
102
$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
103
}
104
105
- /* Send the message */
106
- $to = apply_filters( 'friends_notification_accepted_request_to', $to );
107
$subject = apply_filters( 'friends_notification_accepted_request_subject', $subject, $friend_name );
108
$message = apply_filters( 'friends_notification_accepted_request_message', $message, $friend_name, $friend_link, $settings_link );
109
@@ -111,3 +114,196 @@ To view %2$s\'s profile: %3$s
111
112
do_action( 'bp_friends_sent_accepted_email', $initiator_id, $subject, $message, $friendship_id, $friend_id );
113
}
13
// Exit if accessed directly
14
if ( !defined( 'ABSPATH' ) ) exit;
15
16
+ /** Emails ********************************************************************/
17
+
18
/**
19
* Send notifications related to a new friendship request.
20
*
56
$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
57
}
58
59
+ // Send the message
60
+ $to = apply_filters( 'friends_notification_new_request_to', $to );
61
$subject = apply_filters( 'friends_notification_new_request_subject', $subject, $initiator_name );
62
$message = apply_filters( 'friends_notification_new_request_message', $message, $initiator_name, $initiator_link, $all_requests_link, $settings_link );
63
65
66
do_action( 'bp_friends_sent_request_email', $friend_id, $subject, $message, $friendship_id, $initiator_id );
67
}
68
+ add_action( 'friends_friendship_requested', 'friends_notification_new_request', 10, 3 );
69
70
/**
71
* Send notifications related to the acceptance of a friendship request.
105
$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
106
}
107
108
+ // Send the message
109
+ $to = apply_filters( 'friends_notification_accepted_request_to', $to );
110
$subject = apply_filters( 'friends_notification_accepted_request_subject', $subject, $friend_name );
111
$message = apply_filters( 'friends_notification_accepted_request_message', $message, $friend_name, $friend_link, $settings_link );
112
114
115
do_action( 'bp_friends_sent_accepted_email', $initiator_id, $subject, $message, $friendship_id, $friend_id );
116
}
117
+ add_action( 'friends_friendship_accepted', 'friends_notification_accepted_request', 10, 3 );
118
+
119
+ /** Notifications *************************************************************/
120
+
121
+ /**
122
+ * Notification formatting callback for bp-friends notifications.
123
+ *
124
+ * @param string $action The kind of notification being rendered.
125
+ * @param int $item_id The primary item ID.
126
+ * @param int $secondary_item_id The secondary item ID.
127
+ * @param int $total_items The total number of messaging-related notifications
128
+ * waiting for the user.
129
+ * @param string $format 'string' for BuddyBar-compatible notifications;
130
+ * 'array' for WP Toolbar. Default: 'string'.
131
+ * @return array|string
132
+ */
133
+ function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
134
+
135
+ switch ( $action ) {
136
+ case 'friendship_accepted':
137
+ $link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends' );
138
+
139
+ // Set up the string and the filter
140
+ if ( (int) $total_items > 1 ) {
141
+ $text = sprintf( __( '%d friends accepted your friendship requests', 'buddypress' ), (int) $total_items );
142
+ $filter = 'bp_friends_multiple_friendship_accepted_notification';
143
+ } else {
144
+ $text = sprintf( __( '%s accepted your friendship request', 'buddypress' ), bp_core_get_user_displayname( $item_id ) );
145
+ $filter = 'bp_friends_single_friendship_accepted_notification';
146
+ }
147
+
148
+ break;
149
+
150
+ case 'friendship_request':
151
+ $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/?new';
152
+
153
+ // Set up the string and the filter
154
+ if ( (int) $total_items > 1 ) {
155
+ $text = sprintf( __( 'You have %d pending friendship requests', 'buddypress' ), (int) $total_items );
156
+ $filter = 'bp_friends_multiple_friendship_request_notification';
157
+ } else {
158
+ $text = sprintf( __( 'You have a friendship request from %s', 'buddypress' ), bp_core_get_user_displayname( $item_id ) );
159
+ $filter = 'bp_friends_single_friendship_request_notification';
160
+ }
161
+
162
+ break;
163
+ }
164
+
165
+ // Return either an HTML link or an array, depending on the requested format
166
+ if ( 'string' == $format ) {
167
+ $return = apply_filters( $filter, '<a href="' . esc_url( $link ) . '">' . esc_html( $text ) . '</a>', (int) $total_items );
168
+ } else {
169
+ $return = apply_filters( $filter, array(
170
+ 'link' => $link,
171
+ 'text' => $text
172
+ ), (int) $total_items );
173
+ }
174
+
175
+ do_action( 'friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $return );
176
+
177
+ return $return;
178
+ }
179
+
180
+ /**
181
+ * Clear friend-related notifications when ?new=1
182
+ */
183
+ function friends_clear_friend_notifications() {
184
+ if ( isset( $_GET['new'] ) && bp_is_active( 'notifications' ) ) {
185
+ bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
186
+ }
187
+ }
188
+ add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
189
+
190
+ /**
191
+ * Delete any friendship request notifications for the logged in user.
192
+ *
193
+ * @since BuddyPress (1.9.0)
194
+ */
195
+ function bp_friends_mark_friendship_request_notifications_by_type() {
196
+ if ( isset( $_GET['new'] ) && bp_is_active( 'notifications' ) ) {
197
+ bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' );
198
+ }
199
+ }
200
+ add_action( 'friends_screen_requests', 'bp_friends_mark_friendship_request_notifications_by_type' );
201
+
202
+ /**
203
+ * Delete any friendship acceptance notifications for the logged in user.
204
+ *
205
+ * @since BuddyPress (1.9.0)
206
+ */
207
+ function bp_friends_mark_friendship_accepted_notifications_by_type() {
208
+ if ( bp_is_active( 'notifications' ) ) {
209
+ bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
210
+ }
211
+ }
212
+ add_action( 'friends_screen_my_friends', 'bp_friends_mark_friendship_accepted_notifications_by_type' );
213
+
214
+ /**
215
+ * Notify one use that another user has requested their virtual friendship.
216
+ *
217
+ * @since BuddyPress (1.9.0)
218
+ * @param int $friendship_id The unique ID of the friendship
219
+ * @param int $initiator_user_id The friendship initiator user ID
220
+ * @param int $friend_user_id The friendship request reciever user ID
221
+ */
222
+ function bp_friends_friendship_requested_notification( $friendship_id, $initiator_user_id, $friend_user_id ) {
223
+ if ( bp_is_active( 'notifications' ) ) {
224
+ bp_notifications_add_notification( array(
225
+ 'user_id' => $friend_user_id,
226
+ 'item_id' => $initiator_user_id,
227
+ 'secondary_item_id' => $friendship_id,
228
+ 'component_name' => buddypress()->friends->id,
229
+ 'component_action' => 'friendship_request',
230
+ 'date_notified' => bp_core_current_time(),
231
+ 'is_new' => 1,
232
+ ) );
233
+ }
234
+ }
235
+ add_action( 'friends_friendship_requested', 'bp_friends_friendship_requested_notification', 10, 3 );
236
+
237
+ /**
238
+ * Remove friend request notice when a member rejects another members
239
+ *
240
+ * @since BuddyPress (1.9.0)
241
+ *
242
+ * @param int $friendship_id (not used)
243
+ * @param object $friendship
244
+ */
245
+ function bp_friends_mark_friendship_rejected_notifications_by_item_id( $friendship_id, $friendship ) {
246
+ if ( bp_is_active( 'notifications' ) ) {
247
+ bp_notifications_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' );
248
+ }
249
+ }
250
+ add_action( 'friends_friendship_rejected', 'bp_friends_mark_friendship_rejected_notifications_by_item_id', 10, 2 );
251
+
252
+ /**
253
+ * Notify a member when another member accepts their virtual friendship request.
254
+ *
255
+ * @since BuddyPress (1.9.0)
256
+ * @param int $friendship_id The unique ID of the friendship
257
+ * @param int $initiator_user_id The friendship initiator user ID
258
+ * @param int $friend_user_id The friendship request reciever user ID
259
+ */
260
+ function bp_friends_add_friendship_accepted_notification( $friendship_id, $initiator_user_id, $friend_user_id ) {
261
+
262
+ // Bail if notifications is not active
263
+ if ( ! bp_is_active( 'notifications' ) ) {
264
+ return;
265
+ }
266
+
267
+ // Remove the friend request notice
268
+ bp_notifications_mark_notifications_by_item_id( $friend_user_id, $initiator_user_id, buddypress()->friends->id, 'friendship_request' );
269
+
270
+ // Add a friend accepted notice for the initiating user
271
+ bp_notifications_add_notification( array(
272
+ 'user_id' => $initiator_user_id,
273
+ 'item_id' => $friend_user_id,
274
+ 'secondary_item_id' => $friendship_id,
275
+ 'component_name' => buddypress()->friends->id,
276
+ 'component_action' => 'friendship_accepted',
277
+ 'date_notified' => bp_core_current_time(),
278
+ 'is_new' => 1,
279
+ ) );
280
+ }
281
+ add_action( 'friends_friendship_accepted', 'bp_friends_add_friendship_accepted_notification', 10, 3 );
282
+
283
+ /**
284
+ * Remove friend request notice when a member withdraws their friend request
285
+ *
286
+ * @since BuddyPress (1.9.0)
287
+ *
288
+ * @param int $friendship_id (not used)
289
+ * @param object $friendship
290
+ */
291
+ function bp_friends_mark_friendship_withdrawn_notifications_by_item_id( $friendship_id, $friendship ) {
292
+ if ( bp_is_active( 'notifications' ) ) {
293
+ bp_notifications_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' );
294
+ }
295
+ }
296
+ add_action( 'friends_friendship_withdrawn', 'bp_friends_mark_friendship_withdrawn_notifications_by_item_id', 10, 2 );
297
+
298
+ /**
299
+ * Remove friendship requests FROM user, used primarily when a user is deleted
300
+ *
301
+ * @since BuddyPress (1.9.0)
302
+ * @param int $user_id
303
+ */
304
+ function bp_friends_remove_notifications_data( $user_id = 0 ) {
305
+ if ( bp_is_active( 'notifications' ) ) {
306
+ bp_notifications_delete_notifications_from_user( $user_id, buddypress()->friends->id, 'friendship_request' );
307
+ }
308
+ }
309
+ add_action( 'friends_remove_data', 'bp_friends_remove_notifications_data', 10, 1 );
bp-friends/bp-friends-screens.php CHANGED
@@ -19,9 +19,6 @@ if ( !defined( 'ABSPATH' ) ) exit;
19
*/
20
function friends_screen_my_friends() {
21
22
- // Delete any friendship acceptance notifications for the user when viewing a profile
23
- bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
24
-
25
do_action( 'friends_screen_my_friends' );
26
27
bp_core_load_template( apply_filters( 'friends_template_my_friends', 'members/single/home' ) );
@@ -67,10 +64,6 @@ function friends_screen_requests() {
67
68
do_action( 'friends_screen_requests' );
69
70
- if ( isset( $_GET['new'] ) ) {
71
- bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' );
72
- }
73
-
74
bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/home' ) );
75
}
76
19
*/
20
function friends_screen_my_friends() {
21
22
do_action( 'friends_screen_my_friends' );
23
24
bp_core_load_template( apply_filters( 'friends_template_my_friends', 'members/single/home' ) );
64
65
do_action( 'friends_screen_requests' );
66
67
bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/home' ) );
68
}
69
bp-groups/bp-groups-activity.php CHANGED
@@ -59,10 +59,10 @@ add_action( 'bp_register_activity_actions', 'groups_register_activity_actions' )
59
* @return bool See {@link bp_activity_add()}.
60
*/
61
function groups_record_activity( $args = '' ) {
62
- global $bp;
63
64
- if ( !bp_is_active( 'activity' ) )
65
return false;
66
67
// Set the default for hide_sitewide by checking the status of the group
68
$hide_sitewide = false;
@@ -78,24 +78,21 @@ function groups_record_activity( $args = '' ) {
78
}
79
}
80
81
- $defaults = array (
82
'id' => false,
83
'user_id' => bp_loggedin_user_id(),
84
'action' => '',
85
'content' => '',
86
'primary_link' => '',
87
- 'component' => $bp->groups->id,
88
'type' => false,
89
'item_id' => false,
90
'secondary_item_id' => false,
91
'recorded_time' => bp_core_current_time(),
92
'hide_sitewide' => $hide_sitewide
93
- );
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 ) );
99
}
100
101
/**
@@ -105,13 +102,14 @@ function groups_record_activity( $args = '' ) {
105
* being updated. Default: the current group's ID.
106
*/
107
function groups_update_last_activity( $group_id = 0 ) {
108
- global $bp;
109
110
- if ( empty( $group_id ) )
111
- $group_id = $bp->groups->current_group->id;
112
113
- if ( empty( $group_id ) )
114
return false;
115
116
groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );
117
}
@@ -120,231 +118,78 @@ add_action( 'groups_created_group', 'groups_update_last_activity' );
120
add_action( 'groups_new_forum_topic', 'groups_update_last_activity' );
121
add_action( 'groups_new_forum_topic_post', 'groups_update_last_activity' );
122
123
- function groups_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
124
-
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;
345
}
346
347
- do_action( 'groups_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
348
-
349
- return false;
350
}
59
* @return bool See {@link bp_activity_add()}.
60
*/
61
function groups_record_activity( $args = '' ) {
62
63
+ if ( ! bp_is_active( 'activity' ) ) {
64
return false;
65
+ }
66
67
// Set the default for hide_sitewide by checking the status of the group
68
$hide_sitewide = false;
78
}
79
}
80
81
+ $r = wp_parse_args( $args, array(
82
'id' => false,
83
'user_id' => bp_loggedin_user_id(),
84
'action' => '',
85
'content' => '',
86
'primary_link' => '',
87
+ 'component' => buddypress()->groups->id,
88
'type' => false,
89
'item_id' => false,
90
'secondary_item_id' => false,
91
'recorded_time' => bp_core_current_time(),
92
'hide_sitewide' => $hide_sitewide
93
+ ) );
94
95
+ return bp_activity_add( $r );
96
}
97
98
/**
102
* being updated. Default: the current group's ID.
103
*/
104
function groups_update_last_activity( $group_id = 0 ) {
105
106
+ if ( empty( $group_id ) ) {
107
+ $group_id = buddypress()->groups->current_group->id;
108
+ }
109
110
+ if ( empty( $group_id ) ) {
111
return false;
112
+ }
113
114
groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );
115
}
118
add_action( 'groups_new_forum_topic', 'groups_update_last_activity' );
119
add_action( 'groups_new_forum_topic_post', 'groups_update_last_activity' );
120
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 ) {
129
130
+ // Bail if Activity is not active
131
+ if ( ! bp_is_active( 'activity' ) ) {
132
+ return false;
133
+ }
134
135
+ // Get the group so we can get it's name
136
+ $group = groups_get_group( array( 'group_id' => $group_id ) );
137
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
+ ) );
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 );
bp-groups/bp-groups-classes.php CHANGED
@@ -854,31 +854,37 @@ class BP_Groups_Group {
854
$group_ids = implode( ',', wp_parse_id_list( $group_ids ) );
855
856
// Fetch the logged-in user's status within each group
857
- $user_status = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, is_confirmed, invite_sent FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_banned = 0", bp_loggedin_user_id() ) );
858
859
for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
860
- foreach ( (array) $user_status as $group ) {
861
- if ( $group->group_id == $paged_groups[ $i ]->id ) {
862
- $is_member = $is_invited = $is_pending = '0';
863
864
- // is_confirmed means the user is a member
865
- if ( $group->is_confirmed ) {
866
- $is_member = '1';
867
868
- // invite_sent means the user has been invited
869
- } else if ( $group->invite_sent ) {
870
- $is_invited = '1';
871
872
- // User has sent request, but has not been confirmed
873
- } else {
874
- $is_pending = '1';
875
- }
876
877
- $paged_groups[ $i ]->is_member = $is_member;
878
- $paged_groups[ $i ]->is_invited = $is_invited;
879
- $paged_groups[ $i ]->is_pending = $is_pending;
880
}
881
}
882
}
883
884
$user_banned = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE is_banned = 1 AND user_id = %d AND group_id IN ( {$group_ids} )", bp_loggedin_user_id() ) );
854
$group_ids = implode( ',', wp_parse_id_list( $group_ids ) );
855
856
// Fetch the logged-in user's status within each group
857
+ $user_status_results = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, is_confirmed, invite_sent FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_banned = 0", bp_loggedin_user_id() ) );
858
+
859
+ // Reindex
860
+ $user_status = array();
861
+ foreach ( $user_status_results as $user_status_result ) {
862
+ $user_status[ $user_status_result->group_id ] = $user_status_result;
863
+ }
864
865
for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
866
+ $is_member = $is_invited = $is_pending = '0';
867
+ $gid = $paged_groups[ $i ]->id;
868
869
+ if ( isset( $user_status[ $gid ] ) ) {
870
871
+ // is_confirmed means the user is a member
872
+ if ( $user_status[ $gid ]->is_confirmed ) {
873
+ $is_member = '1';
874
875
+ // invite_sent means the user has been invited
876
+ } else if ( $user_status[ $gid ]->invite_sent ) {
877
+ $is_invited = '1';
878
879
+ // User has sent request, but has not been confirmed
880
+ } else {
881
+ $is_pending = '1';
882
}
883
}
884
+
885
+ $paged_groups[ $i ]->is_member = $is_member;
886
+ $paged_groups[ $i ]->is_invited = $is_invited;
887
+ $paged_groups[ $i ]->is_pending = $is_pending;
888
}
889
890
$user_banned = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE is_banned = 1 AND user_id = %d AND group_id IN ( {$group_ids} )", bp_loggedin_user_id() ) );
bp-groups/bp-groups-forums.php CHANGED
@@ -7,6 +7,9 @@
7
* have a template screen associated with them. Usually they will send the user
8
* back to the default screen after execution.
9
*
10
* @package BuddyPress
11
* @subpackage GroupsForums
12
*/
7
* have a template screen associated with them. Usually they will send the user
8
* back to the default screen after execution.
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
+ *
13
* @package BuddyPress
14
* @subpackage GroupsForums
15
*/
bp-groups/bp-groups-functions.php CHANGED
@@ -200,26 +200,21 @@ function groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_
200
* @since BuddyPress (1.0)
201
*/
202
function groups_delete_group( $group_id ) {
203
- global $bp;
204
205
do_action( 'groups_before_delete_group', $group_id );
206
207
// Get the group object
208
$group = groups_get_group( array( 'group_id' => $group_id ) );
209
- if ( !$group->delete() )
210
- return false;
211
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 ) );
215
216
// Remove all outstanding invites for this group
217
groups_delete_all_group_invites( $group_id );
218
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);
223
224
return true;
225
}
@@ -288,19 +283,10 @@ function groups_leave_group( $group_id, $user_id = 0 ) {
288
}
289
}
290
291
- $membership = new BP_Groups_Member( $user_id, $group_id );
292
-
293
// This is exactly the same as deleting an invite, just is_confirmed = 1 NOT 0.
294
- if ( !groups_uninvite_user( $user_id, $group_id ) )
295
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 ) );
304
305
bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) );
306
@@ -696,11 +682,13 @@ function groups_accept_invite( $user_id, $group_id ) {
696
// If the user is already a member (because BP at one point allowed two invitations to
697
// slip through), delete all existing invitations/requests and return true
698
if ( groups_is_user_member( $user_id, $group_id ) ) {
699
- if ( groups_check_user_has_invite( $user_id, $group_id ) )
700
groups_delete_invite( $user_id, $group_id );
701
702
- if ( groups_check_for_membership_request( $user_id, $group_id ) )
703
groups_delete_membership_request( $user_id, $group_id );
704
705
return true;
706
}
@@ -708,24 +696,25 @@ function groups_accept_invite( $user_id, $group_id ) {
708
$member = new BP_Groups_Member( $user_id, $group_id );
709
$member->accept_invite();
710
711
- if ( !$member->save() )
712
return false;
713
714
// Remove request to join
715
- if ( $member->check_for_membership_request( $user_id, $group_id ) )
716
$member->delete_request( $user_id, $group_id );
717
718
// Modify group meta
719
groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );
720
721
- bp_core_mark_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'group_invite' );
722
-
723
do_action( 'groups_accept_invite', $user_id, $group_id );
724
return true;
725
}
726
727
function groups_reject_invite( $user_id, $group_id ) {
728
- if ( !BP_Groups_Member::delete( $user_id, $group_id ) )
729
return false;
730
731
do_action( 'groups_reject_invite', $user_id, $group_id );
@@ -734,14 +723,12 @@ function groups_reject_invite( $user_id, $group_id ) {
734
}
735
736
function groups_delete_invite( $user_id, $group_id ) {
737
738
- $delete = BP_Groups_Member::delete_invite( $user_id, $group_id );
739
-
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;
745
}
746
747
function groups_send_invites( $user_id, $group_id ) {
@@ -905,46 +892,34 @@ function groups_send_membership_request( $requesting_user_id, $group_id ) {
905
906
function groups_accept_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) {
907
908
- if ( !empty( $user_id ) && !empty( $group_id ) )
909
$membership = new BP_Groups_Member( $user_id, $group_id );
910
- else
911
$membership = new BP_Groups_Member( false, false, $membership_id );
912
913
$membership->accept_request();
914
915
- if ( !$membership->save() )
916
return false;
917
918
// 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 ) )
920
groups_delete_invite( $membership->user_id, $membership->group_id );
921
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 );
936
937
return true;
938
}
939
940
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 ) )
942
return false;
943
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 );
948
949
return true;
950
}
@@ -1074,12 +1049,8 @@ function groups_update_groupmeta( $group_id, $meta_key, $meta_value ) {
1074
/*** Group Cleanup Functions ****************************************************/
1075
1076
function groups_remove_data_for_user( $user_id ) {
1077
- global $bp;
1078
-
1079
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
-
1083
do_action( 'groups_remove_data_for_user', $user_id );
1084
}
1085
add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' );
200
* @since BuddyPress (1.0)
201
*/
202
function groups_delete_group( $group_id ) {
203
204
do_action( 'groups_before_delete_group', $group_id );
205
206
// Get the group object
207
$group = groups_get_group( array( 'group_id' => $group_id ) );
208
209
+ // Bail if group cannot be deleted
210
+ if ( ! $group->delete() ) {
211
+ return false;
212
+ }
213
214
// Remove all outstanding invites for this group
215
groups_delete_all_group_invites( $group_id );
216
217
+ do_action( 'groups_delete_group', $group_id );
218
219
return true;
220
}
283
}
284
}
285
286
// This is exactly the same as deleting an invite, just is_confirmed = 1 NOT 0.
287
+ if ( !groups_uninvite_user( $user_id, $group_id ) ) {
288
return false;
289
+ }
290
291
bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) );
292
682
// If the user is already a member (because BP at one point allowed two invitations to
683
// slip through), delete all existing invitations/requests and return true
684
if ( groups_is_user_member( $user_id, $group_id ) ) {
685
+ if ( groups_check_user_has_invite( $user_id, $group_id ) ) {
686
groups_delete_invite( $user_id, $group_id );
687
+ }
688
689
+ if ( groups_check_for_membership_request( $user_id, $group_id ) ) {
690
groups_delete_membership_request( $user_id, $group_id );
691
+ }
692
693
return true;
694
}
696
$member = new BP_Groups_Member( $user_id, $group_id );
697
$member->accept_invite();
698
699
+ if ( !$member->save() ) {
700
return false;
701
+ }
702
703
// Remove request to join
704
+ if ( $member->check_for_membership_request( $user_id, $group_id ) ) {
705
$member->delete_request( $user_id, $group_id );
706
+ }
707
708
// Modify group meta
709
groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );
710
711
do_action( 'groups_accept_invite', $user_id, $group_id );
712
+
713
return true;
714
}
715
716
function groups_reject_invite( $user_id, $group_id ) {
717
+ if ( ! BP_Groups_Member::delete( $user_id, $group_id ) )
718
return false;
719
720
do_action( 'groups_reject_invite', $user_id, $group_id );
723
<