[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Messages: Bulk-manage action handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage MessageActions
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Handle bulk management (mark as read/unread, delete) of message threads.
  12   *
  13   * @since 2.2.0
  14   *
  15   * @return bool Returns false on failure. Otherwise redirects back to the
  16   *              message box URL.
  17   */
  18  function bp_messages_action_bulk_manage() {
  19  
  20      if ( ! bp_is_messages_component() || bp_is_current_action( 'notices' ) || ! bp_is_action_variable( 'bulk-manage', 0 ) ) {
  21          return false;
  22      }
  23  
  24      $action   = ! empty( $_POST['messages_bulk_action'] ) ? $_POST['messages_bulk_action'] : '';
  25      $nonce    = ! empty( $_POST['messages_bulk_nonce'] ) ? $_POST['messages_bulk_nonce'] : '';
  26      $messages = ! empty( $_POST['message_ids'] ) ? $_POST['message_ids'] : '';
  27  
  28      $messages = wp_parse_id_list( $messages );
  29  
  30      // Bail if no action or no IDs.
  31      if ( ( ! in_array( $action, array( 'delete', 'read', 'unread' ) ) ) || empty( $messages ) || empty( $nonce ) ) {
  32          bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
  33      }
  34  
  35      // Check the nonce.
  36      if ( ! wp_verify_nonce( $nonce, 'messages_bulk_nonce' ) ) {
  37          return false;
  38      }
  39  
  40      // Make sure the user has access to all notifications before managing them.
  41      foreach ( $messages as $message ) {
  42          if ( ! messages_check_thread_access( $message ) && ! bp_current_user_can( 'bp_moderate' ) ) {
  43              bp_core_add_message( __( 'There was a problem managing your messages.', 'buddypress' ), 'error' );
  44              bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
  45          }
  46      }
  47  
  48      // Delete, mark as read or unread depending on the user 'action'.
  49      switch ( $action ) {
  50          case 'delete' :
  51              foreach ( $messages as $message ) {
  52                  messages_delete_thread( $message );
  53              }
  54              bp_core_add_message( __( 'Messages deleted.', 'buddypress' ) );
  55          break;
  56  
  57          case 'read' :
  58              foreach ( $messages as $message ) {
  59                  messages_mark_thread_read( $message );
  60              }
  61              bp_core_add_message( __( 'Messages marked as read', 'buddypress' ) );
  62          break;
  63  
  64          case 'unread' :
  65              foreach ( $messages as $message ) {
  66                  messages_mark_thread_unread( $message );
  67              }
  68              bp_core_add_message( __( 'Messages marked as unread.', 'buddypress' ) );
  69          break;
  70      }
  71  
  72      // Redirect back to message box.
  73      bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
  74  }
  75  add_action( 'bp_actions', 'bp_messages_action_bulk_manage' );


Generated: Sun Dec 15 01:01:38 2019 Cross-referenced by PHPXref 0.7.1