- Timestamp:
- 10/22/2015 06:02:55 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-notifications/bp-notifications-functions.php
r10284 r10303 30 30 * } 31 31 * @return int|bool ID of the newly created notification on success, false 32 * on failure.32 * on failure. 33 33 */ 34 34 function bp_notifications_add_notification( $args = array() ) { … … 45 45 ), 'notifications_add_notification' );; 46 46 47 // Check for existing duplicate notifications 47 // Check for existing duplicate notifications. 48 48 if ( ! $r['allow_duplicate'] ) { 49 // date_notified, allow_duplicate don't count toward50 // duplicate status 49 // Date_notified, allow_duplicate don't count toward 50 // duplicate status. 51 51 $existing = BP_Notifications_Notification::get( array( 52 52 'user_id' => $r['user_id'], … … 63 63 } 64 64 65 // Setup the new notification 65 // Setup the new notification. 66 66 $notification = new BP_Notifications_Notification; 67 67 $notification->user_id = $r['user_id']; … … 73 73 $notification->is_new = $r['is_new']; 74 74 75 // Save the new notification 75 // Save the new notification. 76 76 return $notification->save(); 77 77 } … … 83 83 * 84 84 * @param int $id ID of the notification. 85 * 86 * @return BP_Notifications_Notification 85 * @return BP_Notifications_Notification Notification object for ID specified. 87 86 */ 88 87 function bp_notifications_get_notification( $id ) { … … 96 95 * 97 96 * @param int $id ID of the notification to delete. 98 *99 97 * @return bool True on success, false on failure. 100 98 */ … … 116 114 * @param int $id ID of the notification. 117 115 * @param int|bool $is_new 0 for read, 1 for unread. 118 *119 116 * @return bool True on success, false on failure. 120 117 */ … … 136 133 * 137 134 * @param int $user_id ID of the user whose notifications are being fetched. 138 * 139 * @return array 135 * @return array $notifications Array of notifications for user. 140 136 */ 141 137 function bp_notifications_get_all_notifications_for_user( $user_id = 0 ) { 142 138 143 // Default to displayed user if no ID is passed 139 // Default to displayed user if no ID is passed. 144 140 if ( empty( $user_id ) ) { 145 141 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 146 142 } 147 143 148 // Get notifications out of the cache, or query if necessary 144 // Get notifications out of the cache, or query if necessary. 149 145 $notifications = wp_cache_get( 'all_for_user_' . $user_id, 'bp_notifications' ); 150 146 if ( false === $notifications ) { … … 174 170 * @param string $format Format of the returned values. 'string' returns HTML, 175 171 * while 'object' returns a structured object for parsing. 176 *177 172 * @return mixed Object or array on success, false on failure. 178 173 */ 179 174 function bp_notifications_get_notifications_for_user( $user_id, $format = 'string' ) { 180 175 181 // Setup local variables 176 // Setup local variables. 182 177 $bp = buddypress(); 183 178 184 // Get notifications (out of the cache, or query if necessary) 179 // Get notifications (out of the cache, or query if necessary). 185 180 $notifications = bp_notifications_get_all_notifications_for_user( $user_id ); 186 $grouped_notifications = array(); // Notification groups 187 $renderable = array(); // Renderable notifications 188 189 // Group notifications by component and component_action and provide totals 181 $grouped_notifications = array(); // Notification groups. 182 $renderable = array(); // Renderable notifications. 183 184 // Group notifications by component and component_action and provide totals. 190 185 for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) { 191 186 $notification = $notifications[$i]; … … 193 188 } 194 189 195 // Bail if no notification groups 190 // Bail if no notification groups. 196 191 if ( empty( $grouped_notifications ) ) { 197 192 return false; 198 193 } 199 194 200 // Calculate a renderable output for each notification type 195 // Calculate a renderable output for each notification type. 201 196 foreach ( $grouped_notifications as $component_name => $action_arrays ) { 202 197 … … 209 204 } 210 205 211 // Skip if group is empty 206 // Skip if group is empty. 212 207 if ( empty( $action_arrays ) ) { 213 208 continue; 214 209 } 215 210 216 // Loop through each actionable item and try to map it to a component 211 // Loop through each actionable item and try to map it to a component. 217 212 foreach ( (array) $action_arrays as $component_action_name => $component_action_items ) { 218 213 219 // Get the number of actionable items 214 // Get the number of actionable items. 220 215 $action_item_count = count( $component_action_items ); 221 216 222 // Skip if the count is less than 1 217 // Skip if the count is less than 1. 223 218 if ( $action_item_count < 1 ) { 224 219 continue; 225 220 } 226 221 227 // Callback function exists 222 // Callback function exists. 228 223 if ( isset( $bp->{$component_name}->notification_callback ) && is_callable( $bp->{$component_name}->notification_callback ) ) { 229 224 230 // Function should return an object 225 // Function should return an object. 231 226 if ( 'object' === $format ) { 232 227 233 // Retrieve the content of the notification using the callback 228 // Retrieve the content of the notification using the callback. 234 229 $content = call_user_func( 235 230 $bp->{$component_name}->notification_callback, … … 241 236 ); 242 237 243 // Create the object to be returned 238 // Create the object to be returned. 244 239 $notification_object = $component_action_items[0]; 245 240 246 241 // Minimal backpat with non-compatible notification 247 // callback functions 242 // callback functions. 248 243 if ( is_string( $content ) ) { 249 244 $notification_object->content = $content; … … 256 251 $renderable[] = $notification_object; 257 252 258 // Return an array of content strings 253 // Return an array of content strings. 259 254 } else { 260 255 $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 ); … … 266 261 $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 ); 267 262 268 // Allow non BuddyPress components to hook in 263 // Allow non BuddyPress components to hook in. 269 264 } else { 270 265 271 // The array to reference with apply_filters_ref_array() 266 // The array to reference with apply_filters_ref_array(). 272 267 $ref_array = array( 273 268 $component_action_name, … … 278 273 ); 279 274 280 // Function should return an object 275 // Function should return an object. 281 276 if ( 'object' === $format ) { 282 277 … … 290 285 $content = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', $ref_array ); 291 286 292 // Create the object to be returned 287 // Create the object to be returned. 293 288 $notification_object = $component_action_items[0]; 294 289 295 290 // Minimal backpat with non-compatible notification 296 // callback functions 291 // callback functions. 297 292 if ( is_string( $content ) ) { 298 293 $notification_object->content = $content; … … 305 300 $renderable[] = $notification_object; 306 301 307 // Return an array of content strings 302 // Return an array of content strings. 308 303 } else { 309 304 … … 315 310 } 316 311 317 // If renderable is empty array, set to false 312 // If renderable is empty array, set to false. 318 313 if ( empty( $renderable ) ) { 319 314 $renderable = false; … … 345 340 * @param string $component_name Name of the associated component. 346 341 * @param string $component_action Name of the associated action. 347 *348 342 * @return bool True on success, false on failure. 349 343 */ … … 369 363 * @param string $component_action Name of the associated action. 370 364 * @param int|bool $secondary_item_id ID of the secondary associated item. 371 *372 365 * @return bool True on success, false on failure. 373 366 */ … … 393 386 * @param string|bool $component_action Optional. Name of the associated action. 394 387 * @param int|bool $secondary_item_id Optional. ID of the secondary associated item. 395 *396 388 * @return bool True on success, false on failure. 397 389 */ … … 419 411 * @param string $component_name Name of the associated component. 420 412 * @param string $component_action Name of the associated action. 421 *422 413 * @return bool True on success, false on failure. 423 414 */ … … 444 435 * @param string $component_action Name of the associated action. 445 436 * @param int|bool $is_new 0 for read, 1 for unread. 446 *447 437 * @return bool True on success, false on failure. 448 438 */ … … 474 464 * @param int|bool $secondary_item_id ID of the secondary associated item. 475 465 * @param int|bool $is_new 0 for read, 1 for unread. 476 *477 466 * @return bool True on success, false on failure. 478 467 */ … … 504 493 * @param int|bool $secondary_item_id Optional. ID of the secondary associated item. 505 494 * @param int|bool $is_new 0 for read, 1 for unread. 506 *507 495 * @return bool True on success, false on failure. 508 496 */ … … 536 524 * @param string $component_action Name of the associated action. 537 525 * @param int|bool $is_new 0 for read, 1 for unread. 538 *539 526 * @return bool True on success, false on failure. 540 527 */ … … 563 550 * @param int $user_id ID of the user being checked. 564 551 * @param int $notification_id ID of the notification being checked. 565 *566 552 * @return bool True if the notification belongs to the user, otherwise false. 567 553 */ … … 577 563 * @param int $user_id ID of the user whose unread notifications are being 578 564 * counted. 579 *580 565 * @return int Unread notification count. 581 566 */ … … 602 587 * @see http://buddypress.trac.wordpress.org/ticket/5300 603 588 * 604 * @return array 589 * @return array $component_names Array of registered components. 605 590 */ 606 591 function bp_notifications_get_registered_components() { 607 592 608 // Load BuddyPress 593 // Load BuddyPress. 609 594 $bp = buddypress(); 610 595 611 // Setup return value 596 // Setup return value. 612 597 $component_names = array(); 613 598 614 // Get the active components 599 // Get the active components. 615 600 $active_components = array_keys( $bp->active_components ); 616 601 617 // Loop through components, look for callbacks, add to return value 602 // Loop through components, look for callbacks, add to return value. 618 603 foreach ( $active_components as $component ) { 619 604 if ( !empty( $bp->$component->notification_callback ) ) { … … 654 639 * deleted if the meta_value matches this parameter. 655 640 * @param bool $delete_all Optional. If true, delete matching metadata entries 656 * for all objects, ignoring the specified object_id. Otherwise, 657 * only delete matching metadata entries for the specified 658 * notification item. Default: false. 659 * 641 * for all objects, ignoring the specified object_id. Otherwise, 642 * only delete matching metadata entries for the specified 643 * notification item. Default: false. 660 644 * @return bool True on success, false on failure. 661 645 */ 662 646 function bp_notifications_delete_meta( $notification_id, $meta_key = '', $meta_value = '', $delete_all = false ) { 663 647 664 // Legacy - if no meta_key is passed, delete all for the item 648 // Legacy - if no meta_key is passed, delete all for the item. 665 649 if ( empty( $meta_key ) ) { 666 650 $all_meta = bp_notifications_get_meta( $notification_id ); … … 669 653 : array(); 670 654 671 // With no meta_key, ignore $delete_all 655 // With no meta_key, ignore $delete_all. 672 656 $delete_all = false; 673 657 } else { … … 698 682 * notification item will be fetched. 699 683 * @param bool $single Optional. If true, return only the first value of the 700 * specified meta_key. This parameter has no effect if meta_key is not 701 * specified. Default: true. 702 * 684 * specified meta_key. This parameter has no effect if meta_key is not 685 * specified. Default: true. 703 686 * @return mixed The meta value(s) being requested. 704 687 */ … … 733 716 * metadata entries with the specified value. 734 717 * Otherwise, update all entries. 735 *736 718 * @return bool|int Returns false on failure. On successful 737 719 * update of existing metadata, returns true. On … … 758 740 * for the given key. If true, and the object already has a value for 759 741 * the key, no change will be made. Default: false. 760 *761 742 * @return int|bool The meta ID on successful update, false on failure. 762 743 */
Note: See TracChangeset
for help on using the changeset viewer.