[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
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 $messages = wp_parse_id_list( $messages ); 28 29 // Bail if no action or no IDs. 30 if ( ( ! in_array( $action, array( 'delete', 'read', 'unread' ), true ) ) || empty( $messages ) || empty( $nonce ) ) { 31 bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' ); 32 } 33 34 // Check the nonce. 35 if ( ! wp_verify_nonce( $nonce, 'messages_bulk_nonce' ) ) { 36 return false; 37 } 38 39 // Make sure the user has access to all notifications before managing them. 40 foreach ( $messages as $message ) { 41 if ( ! messages_check_thread_access( $message ) && ! bp_current_user_can( 'bp_moderate' ) ) { 42 bp_core_add_message( __( 'There was a problem managing your messages.', 'buddypress' ), 'error' ); 43 bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' ); 44 } 45 } 46 47 // Delete, mark as read or unread depending on the user 'action'. 48 switch ( $action ) { 49 case 'delete': 50 foreach ( $messages as $message ) { 51 messages_delete_thread( $message ); 52 } 53 bp_core_add_message( __( 'Messages deleted.', 'buddypress' ) ); 54 break; 55 56 case 'read': 57 foreach ( $messages as $message ) { 58 messages_mark_thread_read( $message ); 59 } 60 bp_core_add_message( __( 'Messages marked as read', 'buddypress' ) ); 61 break; 62 63 case 'unread': 64 foreach ( $messages as $message ) { 65 messages_mark_thread_unread( $message ); 66 } 67 bp_core_add_message( __( 'Messages marked as unread.', 'buddypress' ) ); 68 break; 69 } 70 71 // Redirect back to message box. 72 bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' ); 73 } 74 add_action( 'bp_actions', 'bp_messages_action_bulk_manage' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |