[ 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 false|void
  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' ), true ) ) || 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              bp_notifications_delete_notifications_by_ids( $notifications );
  46              bp_core_add_message( __( 'Notifications deleted.', 'buddypress' ) );
  47              break;
  48  
  49          case 'read':
  50              bp_notifications_mark_notifications_by_ids( $notifications, false );
  51              bp_core_add_message( __( 'Notifications marked as read', 'buddypress' ) );
  52              break;
  53  
  54          case 'unread':
  55              bp_notifications_mark_notifications_by_ids( $notifications, true );
  56              bp_core_add_message( __( 'Notifications marked as unread.', 'buddypress' ) );
  57              break;
  58      }
  59  
  60      // URL to redirect to.
  61      if ( bp_is_current_action( 'unread' ) ) {
  62          $redirect = bp_get_notifications_unread_permalink( bp_displayed_user_id() );
  63      } elseif ( bp_is_current_action( 'read' ) ) {
  64          $redirect = bp_get_notifications_read_permalink( bp_displayed_user_id() );
  65      }
  66  
  67      // Redirect.
  68      bp_core_redirect( $redirect );
  69  }
  70  add_action( 'bp_actions', 'bp_notifications_action_bulk_manage' );


Generated: Thu Dec 2 01:00:58 2021 Cross-referenced by PHPXref 0.7.1