bp_messages_action_bulk_manage()
Handle bulk management (mark as read/unread, delete) of message threads.
Description
Return
(bool) Returns false on failure. Otherwise redirects back to the message box URL.
Source
File: bp-messages/actions/bulk-manage.php
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | function bp_messages_action_bulk_manage() { if ( ! bp_is_messages_component() || bp_is_current_action( 'notices' ) || ! bp_is_action_variable( 'bulk-manage' , 0 ) ) { return false; } $action = ! empty ( $_POST [ 'messages_bulk_action' ] ) ? $_POST [ 'messages_bulk_action' ] : '' ; $nonce = ! empty ( $_POST [ 'messages_bulk_nonce' ] ) ? $_POST [ 'messages_bulk_nonce' ] : '' ; $messages = ! empty ( $_POST [ 'message_ids' ] ) ? $_POST [ 'message_ids' ] : '' ; $messages = wp_parse_id_list( $messages ); // Bail if no action or no IDs. if ( ( ! in_array( $action , array ( 'delete' , 'read' , 'unread' ) ) ) || empty ( $messages ) || empty ( $nonce ) ) { bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' ); } // Check the nonce. if ( ! wp_verify_nonce( $nonce , 'messages_bulk_nonce' ) ) { return false; } // Make sure the user has access to all notifications before managing them. foreach ( $messages as $message ) { if ( ! messages_check_thread_access( $message ) && ! bp_current_user_can( 'bp_moderate' ) ) { bp_core_add_message( __( 'There was a problem managing your messages.' , 'buddyboss' ), 'error' ); bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' ); } } // Delete, mark as read or unread depending on the user 'action'. switch ( $action ) { case 'delete' : foreach ( $messages as $message ) { messages_delete_thread( $message ); } bp_core_add_message( __( 'Messages deleted.' , 'buddyboss' ) ); break ; case 'read' : foreach ( $messages as $message ) { messages_mark_thread_read( $message ); } bp_core_add_message( __( 'Messages marked as read' , 'buddyboss' ) ); break ; case 'unread' : foreach ( $messages as $message ) { messages_mark_thread_unread( $message ); } bp_core_add_message( __( 'Messages marked as unread.' , 'buddyboss' ) ); break ; } // Redirect back to message box. bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' ); } |
Changelog
Version | Description |
---|---|
BuddyPress 2.2.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.