bp_nouveau_ajax_readunread_thread_messages()
AJAX mark message as read/unread
Description
Source
File: bp-templates/bp-nouveau/includes/messages/ajax.php
function bp_nouveau_ajax_readunread_thread_messages() { if ( empty( $_POST['action'] ) ) { wp_send_json_error(); } $action = str_replace( 'messages_', '', $_POST['action'] ); $response = array( 'feedback' => __( 'There was a problem marking your messages as read. Please try again.', 'buddyboss' ), 'type' => 'error', ); if ( 'unread' === $action ) { $response = array( 'feedback' => __( 'There was a problem marking your messages as unread. Please try again.', 'buddyboss' ), 'type' => 'error', ); } if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'bp_nouveau_messages' ) ) { wp_send_json_error( $response ); } if ( empty( $_POST['id'] ) ) { wp_send_json_error( $response ); } $thread_ids = wp_parse_id_list( $_POST['id'] ); $response['messages'] = array(); if ( 'unread' === $action ) { $response['feedback'] = __( 'Messages marked as unread.', 'buddyboss' ); } else { $response['feedback'] = __( 'Messages marked as read.', 'buddyboss' ); } foreach ( $thread_ids as $thread_id ) { if ( ! messages_check_thread_access( $thread_id ) && ! bp_current_user_can( 'bp_moderate' ) ) { wp_send_json_error( $response ); } if ( 'unread' === $action ) { // Mark unread messages_mark_thread_unread( $thread_id ); } else { // Mark read messages_mark_thread_read( $thread_id ); } $response['messages'][ $thread_id ] = array( 'unread' => 'unread' === $action, ); } $response['type'] = 'success'; wp_send_json_success( $response ); }
Changelog
Version | Description |
---|---|
BuddyPress 3.0.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.