Completed
Push — master ( fc7440...d56d93 )
by
unknown
19:37
created
src/bp-notifications/bp-notifications-functions.php 1 patch
Switch Indentation   +350 added lines, -350 removed lines patch added patch discarded remove patch
@@ -34,47 +34,47 @@  discard block
 block discarded – undo
34 34
  */
35 35
 function bp_notifications_add_notification( $args = array() ) {
36 36
 
37
-	$r = bp_parse_args( $args, array(
38
-		'user_id'           => 0,
39
-		'item_id'           => 0,
40
-		'secondary_item_id' => 0,
41
-		'component_name'    => '',
42
-		'component_action'  => '',
43
-		'date_notified'     => bp_core_current_time(),
44
-		'is_new'            => 1,
45
-		'allow_duplicate'   => false,
46
-	), 'notifications_add_notification' );
47
-
48
-	// Check for existing duplicate notifications.
49
-	if ( ! $r['allow_duplicate'] ) {
50
-		// Date_notified, allow_duplicate don't count toward
51
-		// duplicate status.
52
-		$existing = BP_Notifications_Notification::get( array(
53
-			'user_id'           => $r['user_id'],
54
-			'item_id'           => $r['item_id'],
55
-			'secondary_item_id' => $r['secondary_item_id'],
56
-			'component_name'    => $r['component_name'],
57
-			'component_action'  => $r['component_action'],
58
-			'is_new'            => $r['is_new'],
59
-		) );
60
-
61
-		if ( ! empty( $existing ) ) {
62
-			return false;
63
-		}
64
-	}
65
-
66
-	// Setup the new notification.
67
-	$notification                    = new BP_Notifications_Notification;
68
-	$notification->user_id           = $r['user_id'];
69
-	$notification->item_id           = $r['item_id'];
70
-	$notification->secondary_item_id = $r['secondary_item_id'];
71
-	$notification->component_name    = $r['component_name'];
72
-	$notification->component_action  = $r['component_action'];
73
-	$notification->date_notified     = $r['date_notified'];
74
-	$notification->is_new            = $r['is_new'];
75
-
76
-	// Save the new notification.
77
-	return $notification->save();
37
+$r = bp_parse_args( $args, array(
38
+'user_id'           => 0,
39
+'item_id'           => 0,
40
+'secondary_item_id' => 0,
41
+'component_name'    => '',
42
+'component_action'  => '',
43
+'date_notified'     => bp_core_current_time(),
44
+'is_new'            => 1,
45
+'allow_duplicate'   => false,
46
+), 'notifications_add_notification' );
47
+
48
+// Check for existing duplicate notifications.
49
+if ( ! $r['allow_duplicate'] ) {
50
+// Date_notified, allow_duplicate don't count toward
51
+// duplicate status.
52
+$existing = BP_Notifications_Notification::get( array(
53
+'user_id'           => $r['user_id'],
54
+'item_id'           => $r['item_id'],
55
+'secondary_item_id' => $r['secondary_item_id'],
56
+'component_name'    => $r['component_name'],
57
+'component_action'  => $r['component_action'],
58
+'is_new'            => $r['is_new'],
59
+) );
60
+
61
+if ( ! empty( $existing ) ) {
62
+return false;
63
+}
64
+}
65
+
66
+// Setup the new notification.
67
+$notification                    = new BP_Notifications_Notification;
68
+$notification->user_id           = $r['user_id'];
69
+$notification->item_id           = $r['item_id'];
70
+$notification->secondary_item_id = $r['secondary_item_id'];
71
+$notification->component_name    = $r['component_name'];
72
+$notification->component_action  = $r['component_action'];
73
+$notification->date_notified     = $r['date_notified'];
74
+$notification->is_new            = $r['is_new'];
75
+
76
+// Save the new notification.
77
+return $notification->save();
78 78
 }
79 79
 
80 80
 /**
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
  * @return BP_Notifications_Notification Notification object for ID specified.
87 87
  */
88 88
 function bp_notifications_get_notification( $id ) {
89
-	return new BP_Notifications_Notification( $id );
89
+return new BP_Notifications_Notification( $id );
90 90
 }
91 91
 
92 92
 /**
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
  * @return false|int True on success, false on failure.
99 99
  */
100 100
 function bp_notifications_delete_notification( $id ) {
101
-	if ( ! bp_notifications_check_notification_access( bp_displayed_user_id(), $id ) ) {
102
-		return false;
103
-	}
101
+if ( ! bp_notifications_check_notification_access( bp_displayed_user_id(), $id ) ) {
102
+return false;
103
+}
104 104
 
105
-	return BP_Notifications_Notification::delete( array( 'id' => $id ) );
105
+return BP_Notifications_Notification::delete( array( 'id' => $id ) );
106 106
 }
107 107
 
108 108
 /**
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
  * @return false|int True on success, false on failure.
118 118
  */
119 119
 function bp_notifications_mark_notification( $id, $is_new = false ) {
120
-	if ( ! bp_notifications_check_notification_access( bp_displayed_user_id(), $id ) ) {
121
-		return false;
122
-	}
120
+if ( ! bp_notifications_check_notification_access( bp_displayed_user_id(), $id ) ) {
121
+return false;
122
+}
123 123
 
124
-	return BP_Notifications_Notification::update(
125
-		array( 'is_new' => $is_new ),
126
-		array( 'id'     => $id     )
127
-	);
124
+return BP_Notifications_Notification::update(
125
+array( 'is_new' => $is_new ),
126
+array( 'id'     => $id     )
127
+);
128 128
 }
129 129
 
130 130
 /**
@@ -137,21 +137,21 @@  discard block
 block discarded – undo
137 137
  */
138 138
 function bp_notifications_get_all_notifications_for_user( $user_id = 0 ) {
139 139
 
140
-	// Default to displayed user if no ID is passed.
141
-	if ( empty( $user_id ) ) {
142
-		$user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
143
-	}
144
-
145
-	// Get notifications out of the cache, or query if necessary.
146
-	$notifications = wp_cache_get( 'all_for_user_' . $user_id, 'bp_notifications' );
147
-	if ( false === $notifications ) {
148
-		$notifications = BP_Notifications_Notification::get( array(
149
-			'user_id' => $user_id
150
-		) );
151
-		wp_cache_set( 'all_for_user_' . $user_id, $notifications, 'bp_notifications' );
152
-	}
153
-
154
-	/**
140
+// Default to displayed user if no ID is passed.
141
+if ( empty( $user_id ) ) {
142
+$user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
143
+}
144
+
145
+// Get notifications out of the cache, or query if necessary.
146
+$notifications = wp_cache_get( 'all_for_user_' . $user_id, 'bp_notifications' );
147
+if ( false === $notifications ) {
148
+$notifications = BP_Notifications_Notification::get( array(
149
+'user_id' => $user_id
150
+) );
151
+wp_cache_set( 'all_for_user_' . $user_id, $notifications, 'bp_notifications' );
152
+}
153
+
154
+/**
155 155
 	 * Filters all notifications for a user.
156 156
 	 *
157 157
 	 * @since 2.1.0
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param array $notifications Array of notifications for user.
160 160
 	 * @param int   $user_id       ID of the user being fetched.
161 161
 	 */
162
-	return apply_filters( 'bp_notifications_get_all_notifications_for_user', $notifications, $user_id );
162
+return apply_filters( 'bp_notifications_get_all_notifications_for_user', $notifications, $user_id );
163 163
 }
164 164
 
165 165
 /**
@@ -174,113 +174,113 @@  discard block
 block discarded – undo
174 174
  */
175 175
 function bp_notifications_get_notifications_for_user( $user_id, $format = 'string' ) {
176 176
 
177
-	// Setup local variables.
178
-	$bp = buddypress();
179
-
180
-	// Get notifications (out of the cache, or query if necessary).
181
-	$notifications         = bp_notifications_get_all_notifications_for_user( $user_id );
182
-	$grouped_notifications = array(); // Notification groups.
183
-	$renderable            = array(); // Renderable notifications.
184
-
185
-	// Group notifications by component and component_action and provide totals.
186
-	for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) {
187
-		$notification = $notifications[$i];
188
-		$grouped_notifications[$notification->component_name][$notification->component_action][] = $notification;
189
-	}
190
-
191
-	// Bail if no notification groups.
192
-	if ( empty( $grouped_notifications ) ) {
193
-		return false;
194
-	}
195
-
196
-	// Calculate a renderable output for each notification type.
197
-	foreach ( $grouped_notifications as $component_name => $action_arrays ) {
198
-
199
-		// We prefer that extended profile component-related notifications use
200
-		// the component_name of 'xprofile'. However, the extended profile child
201
-		// object in the $bp object is keyed as 'profile', which is where we need
202
-		// to look for the registered notification callback.
203
-		if ( 'xprofile' == $component_name ) {
204
-			$component_name = 'profile';
205
-		}
206
-
207
-		// Skip if group is empty.
208
-		if ( empty( $action_arrays ) ) {
209
-			continue;
210
-		}
211
-
212
-		// Loop through each actionable item and try to map it to a component.
213
-		foreach ( (array) $action_arrays as $component_action_name => $component_action_items ) {
214
-
215
-			// Get the number of actionable items.
216
-			$action_item_count = count( $component_action_items );
217
-
218
-			// Skip if the count is less than 1.
219
-			if ( $action_item_count < 1 ) {
220
-				continue;
221
-			}
222
-
223
-			// Callback function exists.
224
-			if ( isset( $bp->{$component_name}->notification_callback ) && is_callable( $bp->{$component_name}->notification_callback ) ) {
225
-
226
-				// Function should return an object.
227
-				if ( 'object' === $format ) {
228
-
229
-					// Retrieve the content of the notification using the callback.
230
-					$content = call_user_func(
231
-						$bp->{$component_name}->notification_callback,
232
-						$component_action_name,
233
-						$component_action_items[0]->item_id,
234
-						$component_action_items[0]->secondary_item_id,
235
-						$action_item_count,
236
-						'array',
237
-						$component_action_items[0]->id
238
-					);
239
-
240
-					// Create the object to be returned.
241
-					$notification_object = $component_action_items[0];
242
-
243
-					// Minimal backpat with non-compatible notification
244
-					// callback functions.
245
-					if ( is_string( $content ) ) {
246
-						$notification_object->content = $content;
247
-						$notification_object->href    = bp_loggedin_user_domain();
248
-					} else {
249
-						$notification_object->content = $content['text'];
250
-						$notification_object->href    = $content['link'];
251
-					}
252
-
253
-					$renderable[] = $notification_object;
254
-
255
-				// Return an array of content strings.
256
-				} else {
257
-					$content      = call_user_func( $bp->{$component_name}->notification_callback, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count, 'string', $component_action_items[0]->id );
258
-					$renderable[] = $content;
259
-				}
260
-
261
-			// @deprecated format_notification_function - 1.5
262
-			} elseif ( isset( $bp->{$component_name}->format_notification_function ) && function_exists( $bp->{$component_name}->format_notification_function ) ) {
263
-				$renderable[] = call_user_func( $bp->{$component_name}->format_notification_function, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count );
264
-
265
-			// Allow non BuddyPress components to hook in.
266
-			} else {
267
-
268
-				// The array to reference with apply_filters_ref_array().
269
-				$ref_array = array(
270
-					$component_action_name,
271
-					$component_action_items[0]->item_id,
272
-					$component_action_items[0]->secondary_item_id,
273
-					$action_item_count,
274
-					$format,
275
-					$component_action_name, // Duplicated so plugins can check the canonical action name.
276
-					$component_name,
277
-					$component_action_items[0]->id
278
-				);
279
-
280
-				// Function should return an object.
281
-				if ( 'object' === $format ) {
282
-
283
-					/**
177
+// Setup local variables.
178
+$bp = buddypress();
179
+
180
+// Get notifications (out of the cache, or query if necessary).
181
+$notifications         = bp_notifications_get_all_notifications_for_user( $user_id );
182
+$grouped_notifications = array(); // Notification groups.
183
+$renderable            = array(); // Renderable notifications.
184
+
185
+// Group notifications by component and component_action and provide totals.
186
+for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) {
187
+$notification = $notifications[$i];
188
+$grouped_notifications[$notification->component_name][$notification->component_action][] = $notification;
189
+}
190
+
191
+// Bail if no notification groups.
192
+if ( empty( $grouped_notifications ) ) {
193
+return false;
194
+}
195
+
196
+// Calculate a renderable output for each notification type.
197
+foreach ( $grouped_notifications as $component_name => $action_arrays ) {
198
+
199
+// We prefer that extended profile component-related notifications use
200
+// the component_name of 'xprofile'. However, the extended profile child
201
+// object in the $bp object is keyed as 'profile', which is where we need
202
+// to look for the registered notification callback.
203
+if ( 'xprofile' == $component_name ) {
204
+$component_name = 'profile';
205
+}
206
+
207
+// Skip if group is empty.
208
+if ( empty( $action_arrays ) ) {
209
+continue;
210
+}
211
+
212
+// Loop through each actionable item and try to map it to a component.
213
+foreach ( (array) $action_arrays as $component_action_name => $component_action_items ) {
214
+
215
+// Get the number of actionable items.
216
+$action_item_count = count( $component_action_items );
217
+
218
+// Skip if the count is less than 1.
219
+if ( $action_item_count < 1 ) {
220
+continue;
221
+}
222
+
223
+// Callback function exists.
224
+if ( isset( $bp->{$component_name}->notification_callback ) && is_callable( $bp->{$component_name}->notification_callback ) ) {
225
+
226
+// Function should return an object.
227
+if ( 'object' === $format ) {
228
+
229
+// Retrieve the content of the notification using the callback.
230
+$content = call_user_func(
231
+$bp->{$component_name}->notification_callback,
232
+$component_action_name,
233
+$component_action_items[0]->item_id,
234
+$component_action_items[0]->secondary_item_id,
235
+$action_item_count,
236
+'array',
237
+$component_action_items[0]->id
238
+);
239
+
240
+// Create the object to be returned.
241
+$notification_object = $component_action_items[0];
242
+
243
+// Minimal backpat with non-compatible notification
244
+// callback functions.
245
+if ( is_string( $content ) ) {
246
+$notification_object->content = $content;
247
+$notification_object->href    = bp_loggedin_user_domain();
248
+} else {
249
+$notification_object->content = $content['text'];
250
+$notification_object->href    = $content['link'];
251
+}
252
+
253
+$renderable[] = $notification_object;
254
+
255
+// Return an array of content strings.
256
+} else {
257
+$content      = call_user_func( $bp->{$component_name}->notification_callback, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count, 'string', $component_action_items[0]->id );
258
+$renderable[] = $content;
259
+}
260
+
261
+// @deprecated format_notification_function - 1.5
262
+} elseif ( isset( $bp->{$component_name}->format_notification_function ) && function_exists( $bp->{$component_name}->format_notification_function ) ) {
263
+$renderable[] = call_user_func( $bp->{$component_name}->format_notification_function, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count );
264
+
265
+// Allow non BuddyPress components to hook in.
266
+} else {
267
+
268
+// The array to reference with apply_filters_ref_array().
269
+$ref_array = array(
270
+$component_action_name,
271
+$component_action_items[0]->item_id,
272
+$component_action_items[0]->secondary_item_id,
273
+$action_item_count,
274
+$format,
275
+$component_action_name, // Duplicated so plugins can check the canonical action name.
276
+$component_name,
277
+$component_action_items[0]->id
278
+);
279
+
280
+// Function should return an object.
281
+if ( 'object' === $format ) {
282
+
283
+/**
284 284
 					 * Filters the notification content for notifications created by plugins.
285 285
 					 *
286 286
 					 * If your plugin extends the {@link BP_Component} class, you should use the
@@ -304,39 +304,39 @@  discard block
 block discarded – undo
304 304
 					 *                      If $format is 'object', return an array formatted like:
305 305
 					 *                      array( 'text' => 'CONTENT', 'link' => 'LINK' )
306 306
 					 */
307
-					$content = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', $ref_array );
308
-
309
-					// Create the object to be returned.
310
-					$notification_object = $component_action_items[0];
311
-
312
-					// Minimal backpat with non-compatible notification
313
-					// callback functions.
314
-					if ( is_string( $content ) ) {
315
-						$notification_object->content = $content;
316
-						$notification_object->href    = bp_loggedin_user_domain();
317
-					} else {
318
-						$notification_object->content = $content['text'];
319
-						$notification_object->href    = $content['link'];
320
-					}
321
-
322
-					$renderable[] = $notification_object;
323
-
324
-				// Return an array of content strings.
325
-				} else {
326
-
327
-					/** This filters is documented in bp-notifications/bp-notifications-functions.php */
328
-					$renderable[] = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', $ref_array );
329
-				}
330
-			}
331
-		}
332
-	}
333
-
334
-	// If renderable is empty array, set to false.
335
-	if ( empty( $renderable ) ) {
336
-		$renderable = false;
337
-	}
338
-
339
-	/**
307
+$content = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', $ref_array );
308
+
309
+// Create the object to be returned.
310
+$notification_object = $component_action_items[0];
311
+
312
+// Minimal backpat with non-compatible notification
313
+// callback functions.
314
+if ( is_string( $content ) ) {
315
+$notification_object->content = $content;
316
+$notification_object->href    = bp_loggedin_user_domain();
317
+} else {
318
+$notification_object->content = $content['text'];
319
+$notification_object->href    = $content['link'];
320
+}
321
+
322
+$renderable[] = $notification_object;
323
+
324
+// Return an array of content strings.
325
+} else {
326
+
327
+/** This filters is documented in bp-notifications/bp-notifications-functions.php */
328
+$renderable[] = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', $ref_array );
329
+}
330
+}
331
+}
332
+}
333
+
334
+// If renderable is empty array, set to false.
335
+if ( empty( $renderable ) ) {
336
+$renderable = false;
337
+}
338
+
339
+/**
340 340
 	 * Filters the final array of notifications to be displayed for a user.
341 341
 	 *
342 342
 	 * @since 1.6.0
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	 * @param int        $user_id    ID of the user whose notifications are being displayed.
346 346
 	 * @param string     $format     Display format requested for the notifications.
347 347
 	 */
348
-	return apply_filters( 'bp_core_get_notifications_for_user', $renderable, $user_id, $format );
348
+return apply_filters( 'bp_core_get_notifications_for_user', $renderable, $user_id, $format );
349 349
 }
350 350
 
351 351
 /** Delete ********************************************************************/
@@ -364,11 +364,11 @@  discard block
 block discarded – undo
364 364
  * @return int|false True on success, false on failure.
365 365
  */
366 366
 function bp_notifications_delete_notifications_by_type( $user_id, $component_name, $component_action ) {
367
-	return BP_Notifications_Notification::delete( array(
368
-		'user_id'          => $user_id,
369
-		'component_name'   => $component_name,
370
-		'component_action' => $component_action,
371
-	) );
367
+return BP_Notifications_Notification::delete( array(
368
+'user_id'          => $user_id,
369
+'component_name'   => $component_name,
370
+'component_action' => $component_action,
371
+) );
372 372
 }
373 373
 
374 374
 /**
@@ -387,13 +387,13 @@  discard block
 block discarded – undo
387 387
  * @return int|false True on success, false on failure.
388 388
  */
389 389
 function bp_notifications_delete_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
390
-	return BP_Notifications_Notification::delete( array(
391
-		'user_id'           => $user_id,
392
-		'item_id'           => $item_id,
393
-		'secondary_item_id' => $secondary_item_id,
394
-		'component_name'    => $component_name,
395
-		'component_action'  => $component_action,
396
-	) );
390
+return BP_Notifications_Notification::delete( array(
391
+'user_id'           => $user_id,
392
+'item_id'           => $item_id,
393
+'secondary_item_id' => $secondary_item_id,
394
+'component_name'    => $component_name,
395
+'component_action'  => $component_action,
396
+) );
397 397
 }
398 398
 
399 399
 /**
@@ -410,12 +410,12 @@  discard block
 block discarded – undo
410 410
  * @return int|false True on success, false on failure.
411 411
  */
412 412
 function bp_notifications_delete_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false ) {
413
-	return BP_Notifications_Notification::delete( array(
414
-		'item_id'           => $item_id,
415
-		'secondary_item_id' => $secondary_item_id,
416
-		'component_name'    => $component_name,
417
-		'component_action'  => $component_action,
418
-	) );
413
+return BP_Notifications_Notification::delete( array(
414
+'item_id'           => $item_id,
415
+'secondary_item_id' => $secondary_item_id,
416
+'component_name'    => $component_name,
417
+'component_action'  => $component_action,
418
+) );
419 419
 }
420 420
 
421 421
 /**
@@ -435,11 +435,11 @@  discard block
 block discarded – undo
435 435
  * @return int|false True on success, false on failure.
436 436
  */
437 437
 function bp_notifications_delete_notifications_from_user( $user_id, $component_name, $component_action ) {
438
-	return BP_Notifications_Notification::delete( array(
439
-		'item_id'           => $user_id,
440
-		'component_name'    => $component_name,
441
-		'component_action'  => $component_action,
442
-	) );
438
+return BP_Notifications_Notification::delete( array(
439
+'item_id'           => $user_id,
440
+'component_name'    => $component_name,
441
+'component_action'  => $component_action,
442
+) );
443 443
 }
444 444
 
445 445
 /**
@@ -451,13 +451,13 @@  discard block
 block discarded – undo
451 451
  * @return int|false The number of rows deleted, or false on error.
452 452
  */
453 453
 function bp_notifications_delete_notifications_on_user_delete( $user_id ) {
454
-	return BP_Notifications_Notification::delete( array(
455
-		'user_id'           => $user_id,
456
-		'item_id'           => false,
457
-		'secondary_item_id' => false,
458
-		'component_action'  => false,
459
-		'component_name'    => false,
460
-	) );
454
+return BP_Notifications_Notification::delete( array(
455
+'user_id'           => $user_id,
456
+'item_id'           => false,
457
+'secondary_item_id' => false,
458
+'component_action'  => false,
459
+'component_name'    => false,
460
+) );
461 461
 }
462 462
 add_action( 'wpmu_delete_user', 'bp_notifications_delete_notifications_on_user_delete' );
463 463
 add_action( 'delete_user', 'bp_notifications_delete_notifications_on_user_delete' );
@@ -479,16 +479,16 @@  discard block
 block discarded – undo
479 479
  * @return int|false True on success, false on failure.
480 480
  */
481 481
 function bp_notifications_mark_notifications_by_type( $user_id, $component_name, $component_action, $is_new = false ) {
482
-	return BP_Notifications_Notification::update(
483
-		array(
484
-			'is_new' => $is_new
485
-		),
486
-		array(
487
-			'user_id'          => $user_id,
488
-			'component_name'   => $component_name,
489
-			'component_action' => $component_action
490
-		)
491
-	);
482
+return BP_Notifications_Notification::update(
483
+array(
484
+'is_new' => $is_new
485
+),
486
+array(
487
+'user_id'          => $user_id,
488
+'component_name'   => $component_name,
489
+'component_action' => $component_action
490
+)
491
+);
492 492
 }
493 493
 
494 494
 /**
@@ -508,18 +508,18 @@  discard block
 block discarded – undo
508 508
  * @return int|false True on success, false on failure.
509 509
  */
510 510
 function bp_notifications_mark_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false, $is_new = false ) {
511
-	return BP_Notifications_Notification::update(
512
-		array(
513
-			'is_new' => $is_new
514
-		),
515
-		array(
516
-			'user_id'           => $user_id,
517
-			'item_id'           => $item_id,
518
-			'secondary_item_id' => $secondary_item_id,
519
-			'component_name'    => $component_name,
520
-			'component_action'  => $component_action
521
-		)
522
-	);
511
+return BP_Notifications_Notification::update(
512
+array(
513
+'is_new' => $is_new
514
+),
515
+array(
516
+'user_id'           => $user_id,
517
+'item_id'           => $item_id,
518
+'secondary_item_id' => $secondary_item_id,
519
+'component_name'    => $component_name,
520
+'component_action'  => $component_action
521
+)
522
+);
523 523
 }
524 524
 
525 525
 /**
@@ -537,17 +537,17 @@  discard block
 block discarded – undo
537 537
  * @return int|false True on success, false on failure.
538 538
  */
539 539
 function bp_notifications_mark_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false, $is_new = false ) {
540
-	return BP_Notifications_Notification::update(
541
-		array(
542
-			'is_new' => $is_new
543
-		),
544
-		array(
545
-			'item_id'           => $item_id,
546
-			'secondary_item_id' => $secondary_item_id,
547
-			'component_name'    => $component_name,
548
-			'component_action'  => $component_action
549
-		)
550
-	);
540
+return BP_Notifications_Notification::update(
541
+array(
542
+'is_new' => $is_new
543
+),
544
+array(
545
+'item_id'           => $item_id,
546
+'secondary_item_id' => $secondary_item_id,
547
+'component_name'    => $component_name,
548
+'component_action'  => $component_action
549
+)
550
+);
551 551
 }
552 552
 
553 553
 /**
@@ -568,16 +568,16 @@  discard block
 block discarded – undo
568 568
  * @return int|false True on success, false on failure.
569 569
  */
570 570
 function bp_notifications_mark_notifications_from_user( $user_id, $component_name, $component_action, $is_new = false ) {
571
-	return BP_Notifications_Notification::update(
572
-		array(
573
-			'is_new' => $is_new
574
-		),
575
-		array(
576
-			'item_id'          => $user_id,
577
-			'component_name'   => $component_name,
578
-			'component_action' => $component_action
579
-		)
580
-	);
571
+return BP_Notifications_Notification::update(
572
+array(
573
+'is_new' => $is_new
574
+),
575
+array(
576
+'item_id'          => $user_id,
577
+'component_name'   => $component_name,
578
+'component_action' => $component_action
579
+)
580
+);
581 581
 }
582 582
 
583 583
 /** Helpers *******************************************************************/
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
  * @return bool True if the notification belongs to the user, otherwise false.
595 595
  */
596 596
 function bp_notifications_check_notification_access( $user_id, $notification_id ) {
597
-	return (bool) BP_Notifications_Notification::check_access( $user_id, $notification_id );
597
+return (bool) BP_Notifications_Notification::check_access( $user_id, $notification_id );
598 598
 }
599 599
 
600 600
 /**
@@ -607,20 +607,20 @@  discard block
 block discarded – undo
607 607
  * @return int Unread notification count.
608 608
  */
609 609
 function bp_notifications_get_unread_notification_count( $user_id = 0 ) {
610
-	if ( empty( $user_id ) ) {
611
-		$user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
612
-	}
613
-
614
-	$count = wp_cache_get( $user_id, 'bp_notifications_unread_count' );
615
-	if ( false === $count ) {
616
-		$count = BP_Notifications_Notification::get_total_count( array(
617
-			'user_id' => $user_id,
618
-			'is_new'  => true,
619
-		) );
620
-		wp_cache_set( $user_id, $count, 'bp_notifications_unread_count' );
621
-	}
622
-
623
-	/**
610
+if ( empty( $user_id ) ) {
611
+$user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
612
+}
613
+
614
+$count = wp_cache_get( $user_id, 'bp_notifications_unread_count' );
615
+if ( false === $count ) {
616
+$count = BP_Notifications_Notification::get_total_count( array(
617
+'user_id' => $user_id,
618
+'is_new'  => true,
619
+) );
620
+wp_cache_set( $user_id, $count, 'bp_notifications_unread_count' );
621
+}
622
+
623
+/**
624 624
 	 * Filters the count of unread notification items for a user.
625 625
 	 *
626 626
 	 * @since 1.9.0
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 	 * @param int $count   Count of unread notification items for a user.
630 630
 	 * @param int $user_id User ID for notifications count.
631 631
 	 */
632
-	return apply_filters( 'bp_notifications_get_total_notification_count', (int) $count, $user_id );
632
+return apply_filters( 'bp_notifications_get_total_notification_count', (int) $count, $user_id );
633 633
 }
634 634
 
635 635
 /**
@@ -644,28 +644,28 @@  discard block
 block discarded – undo
644 644
  */
645 645
 function bp_notifications_get_registered_components() {
646 646
 
647
-	// Load BuddyPress.
648
-	$bp = buddypress();
647
+// Load BuddyPress.
648
+$bp = buddypress();
649 649
 
650
-	// Setup return value.
651
-	$component_names = array();
650
+// Setup return value.
651
+$component_names = array();
652 652
 
653
-	// Get the active components.
654
-	$active_components = array_keys( $bp->active_components );
653
+// Get the active components.
654
+$active_components = array_keys( $bp->active_components );
655 655
 
656
-	// Loop through components, look for callbacks, add to return value.
657
-	foreach ( $active_components as $component ) {
658
-		if ( !empty( $bp->$component->notification_callback ) ) {
659
-			$component_names[] = $component;
660
-		}
661
-		// The extended profile component is identified in the active_components array as 'xprofile'.
662
-		// However, the extended profile child object has the key 'profile' in the $bp object.
663
-		if ( 'xprofile' == $component && ! empty( $bp->profile->notification_callback ) ) {
664
-			$component_names[] = $component;
665
-		}
666
-	}
656
+// Loop through components, look for callbacks, add to return value.
657
+foreach ( $active_components as $component ) {
658
+if ( !empty( $bp->$component->notification_callback ) ) {
659
+$component_names[] = $component;
660
+}
661
+// The extended profile component is identified in the active_components array as 'xprofile'.
662
+// However, the extended profile child object has the key 'profile' in the $bp object.
663
+if ( 'xprofile' == $component && ! empty( $bp->profile->notification_callback ) ) {
664
+$component_names[] = $component;
665
+}
666
+}
667 667
 
668
-	/**
668
+/**
669 669
 	 * Filters active components with registered notifications callbacks.
670 670
 	 *
671 671
 	 * @since 1.9.1
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
 	 * @param array $component_names   Array of registered component names.
674 674
 	 * @param array $active_components Array of active components.
675 675
 	 */
676
-	return apply_filters( 'bp_notifications_get_registered_components', $component_names, $active_components );
676
+return apply_filters( 'bp_notifications_get_registered_components', $component_names, $active_components );
677 677
 }
678 678
 
679 679
 /** Meta **********************************************************************/
@@ -699,28 +699,28 @@  discard block
 block discarded – undo
699 699
  */
700 700
 function bp_notifications_delete_meta( $notification_id, $meta_key = '', $meta_value = '', $delete_all = false ) {
701 701
 
702
-	// Legacy - if no meta_key is passed, delete all for the item.
703
-	if ( empty( $meta_key ) ) {
704
-		$all_meta = bp_notifications_get_meta( $notification_id );
705
-		$keys     = ! empty( $all_meta )
706
-			? array_keys( $all_meta )
707
-			: array();
708
-
709
-		// With no meta_key, ignore $delete_all.
710
-		$delete_all = false;
711
-	} else {
712
-		$keys = array( $meta_key );
713
-	}
702
+// Legacy - if no meta_key is passed, delete all for the item.
703
+if ( empty( $meta_key ) ) {
704
+$all_meta = bp_notifications_get_meta( $notification_id );
705
+$keys     = ! empty( $all_meta )
706
+? array_keys( $all_meta )
707
+: array();
708
+
709
+// With no meta_key, ignore $delete_all.
710
+$delete_all = false;
711
+} else {
712
+$keys = array( $meta_key );
713
+}
714 714
 
715
-	$retval = true;
715
+$retval = true;
716 716
 
717
-	add_filter( 'query', 'bp_filter_metaid_column_name' );
718
-	foreach ( $keys as $key ) {
719
-		$retval = delete_metadata( 'notification', $notification_id, $key, $meta_value, $delete_all );
720
-	}
721
-	remove_filter( 'query', 'bp_filter_metaid_column_name' );
717
+add_filter( 'query', 'bp_filter_metaid_column_name' );
718
+foreach ( $keys as $key ) {
719
+$retval = delete_metadata( 'notification', $notification_id, $key, $meta_value, $delete_all );
720
+}
721
+remove_filter( 'query', 'bp_filter_metaid_column_name' );
722 722
 
723
-	return $retval;
723
+return $retval;
724 724
 }
725 725
 
726 726
 /**
@@ -738,11 +738,11 @@  discard block
 block discarded – undo
738 738
  * @return mixed                  The meta value(s) being requested.
739 739
  */
740 740
 function bp_notifications_get_meta( $notification_id = 0, $meta_key = '', $single = true ) {
741
-	add_filter( 'query', 'bp_filter_metaid_column_name' );
742
-	$retval = get_metadata( 'notification', $notification_id, $meta_key, $single );
743
-	remove_filter( 'query', 'bp_filter_metaid_column_name' );
741
+add_filter( 'query', 'bp_filter_metaid_column_name' );
742
+$retval = get_metadata( 'notification', $notification_id, $meta_key, $single );
743
+remove_filter( 'query', 'bp_filter_metaid_column_name' );
744 744
 
745
-	/**
745
+/**
746 746
 	 * Filters the metadata for a specified notification item.
747 747
 	 *
748 748
 	 * @since 2.3.0
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 	 * @param string $meta_key        Meta key for the value being requested.
753 753
 	 * @param bool   $single          Whether to return one matched meta key row or all.
754 754
 	 */
755
-	return apply_filters( 'bp_notifications_get_meta', $retval, $notification_id, $meta_key, $single );
755
+return apply_filters( 'bp_notifications_get_meta', $retval, $notification_id, $meta_key, $single );
756 756
 }
757 757
 
758 758
 /**
@@ -773,11 +773,11 @@  discard block
 block discarded – undo
773 773
  *                                 the integer ID of the new metadata row.
774 774
  */
775 775
 function bp_notifications_update_meta( $notification_id, $meta_key, $meta_value, $prev_value = '' ) {
776
-	add_filter( 'query', 'bp_filter_metaid_column_name' );
777
-	$retval = update_metadata( 'notification', $notification_id, $meta_key, $meta_value, $prev_value );
778
-	remove_filter( 'query', 'bp_filter_metaid_column_name' );
776
+add_filter( 'query', 'bp_filter_metaid_column_name' );
777
+$retval = update_metadata( 'notification', $notification_id, $meta_key, $meta_value, $prev_value );
778
+remove_filter( 'query', 'bp_filter_metaid_column_name' );
779 779
 
780
-	return $retval;
780
+return $retval;
781 781
 }
782 782
 
783 783
 /**
@@ -794,9 +794,9 @@  discard block
 block discarded – undo
794 794
  * @return int|bool               The meta ID on successful update, false on failure.
795 795
  */
796