[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Messages: Bulk-manage star action handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage MessageActions
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Bulk manage handler to set the star status for multiple messages.
  12   *
  13   * @since 2.3.0
  14   */
  15  function bp_messages_star_bulk_manage_handler() {
  16      if ( empty( $_POST['messages_bulk_nonce' ] ) ) {
  17          return;
  18      }
  19  
  20      // Check the nonce.
  21      if ( ! wp_verify_nonce( $_POST['messages_bulk_nonce'], 'messages_bulk_nonce' ) ) {
  22          return;
  23      }
  24  
  25      // Check capability.
  26      if ( ! is_user_logged_in() || ! bp_core_can_edit_settings() ) {
  27          return;
  28      }
  29  
  30      $action  = ! empty( $_POST['messages_bulk_action'] ) ? $_POST['messages_bulk_action'] : '';
  31      $threads = ! empty( $_POST['message_ids'] ) ? $_POST['message_ids'] : '';
  32      $threads = wp_parse_id_list( $threads );
  33  
  34      // Bail if action doesn't match our star actions or no IDs.
  35      if ( false === in_array( $action, array( 'star', 'unstar' ), true ) || empty( $threads ) ) {
  36          return;
  37      }
  38  
  39      // It's star time!
  40      switch ( $action ) {
  41          case 'star' :
  42              $count = count( $threads );
  43  
  44              // If we're starring a thread, we only star the first message in the thread.
  45              foreach ( $threads as $thread ) {
  46                  $thread = new BP_Messages_thread( $thread );
  47                  $mids = wp_list_pluck( $thread->messages, 'id' );
  48  
  49                  bp_messages_star_set_action( array(
  50                      'action'     => 'star',
  51                      'message_id' => $mids[0],
  52                  ) );
  53              }
  54  
  55              bp_core_add_message( sprintf( _n( '%s message was successfully starred', '%s messages were successfully starred', $count, 'buddypress' ), $count ) );
  56              break;
  57  
  58          case 'unstar' :
  59              $count = count( $threads );
  60  
  61              foreach ( $threads as $thread ) {
  62                  bp_messages_star_set_action( array(
  63                      'action'    => 'unstar',
  64                      'thread_id' => $thread,
  65                      'bulk'      => true
  66                  ) );
  67              }
  68  
  69              bp_core_add_message( sprintf( _n( '%s message was successfully unstarred', '%s messages were successfully unstarred', $count, 'buddypress' ), $count ) );
  70              break;
  71      }
  72  
  73      // Redirect back to message box.
  74      bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
  75      die();
  76  }
  77  add_action( 'bp_actions', 'bp_messages_star_bulk_manage_handler', 5 );


Generated: Thu Dec 12 01:01:36 2019 Cross-referenced by PHPXref 0.7.1