[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-notifications/actions/ -> bulk-manage.php (source)

   1  <?php
   2  /**
   3   * Notifications: Bulk-manage action handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage NotificationsActions
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Handles bulk management (mark as read/unread, delete) of notifications.
  12   *
  13   * @since 2.2.0
  14   *
  15   * @return bool
  16   */
  17  function bp_notifications_action_bulk_manage() {
  18  
  19      // Bail if not the read or unread screen.
  20      if ( ! bp_is_notifications_component() || ! ( bp_is_current_action( 'read' ) || bp_is_current_action( 'unread' ) ) ) {
  21          return false;
  22      }
  23  
  24      // Get the action.
  25      $action = !empty( $_POST['notification_bulk_action'] ) ? $_POST['notification_bulk_action'] : '';
  26      $nonce  = !empty( $_POST['notifications_bulk_nonce'] ) ? $_POST['notifications_bulk_nonce'] : '';
  27      $notifications = !empty( $_POST['notifications'] ) ? $_POST['notifications'] : '';
  28  
  29      // Bail if no action or no IDs.
  30      if ( ( ! in_array( $action, array( 'delete', 'read', 'unread' ) ) ) || empty( $notifications ) || empty( $nonce ) ) {
  31          return false;
  32      }
  33  
  34      // Check the nonce.
  35      if ( ! wp_verify_nonce( $nonce, 'notifications_bulk_nonce' ) ) {
  36          bp_core_add_message( __( 'There was a problem managing your notifications.', 'buddypress' ), 'error' );
  37          return false;
  38      }
  39  
  40      $notifications = wp_parse_id_list( $notifications );
  41  
  42      // Delete, mark as read or unread depending on the user 'action'.
  43      switch ( $action ) {
  44          case 'delete' :
  45              foreach ( $notifications as $notification ) {
  46                  bp_notifications_delete_notification( $notification );
  47              }
  48              bp_core_add_message( __( 'Notifications deleted.', 'buddypress' ) );
  49          break;
  50  
  51          case 'read' :
  52              foreach ( $notifications as $notification ) {
  53                  bp_notifications_mark_notification( $notification, false );
  54              }
  55              bp_core_add_message( __( 'Notifications marked as read', 'buddypress' ) );
  56          break;
  57  
  58          case 'unread' :
  59              foreach ( $notifications as $notification ) {
  60                  bp_notifications_mark_notification( $notification, true );
  61              }
  62              bp_core_add_message( __( 'Notifications marked as unread.', 'buddypress' ) );
  63          break;
  64      }
  65  
  66      // Redirect.
  67      bp_core_redirect( bp_displayed_user_domain() . bp_get_notifications_slug() . '/' . bp_current_action() . '/' );
  68  }
  69  add_action( 'bp_actions', 'bp_notifications_action_bulk_manage' );


Generated: Wed Oct 23 01:01:50 2019 Cross-referenced by PHPXref 0.7.1