bp_nouveau_ajax_readunread_thread_messages()
AJAX mark message as read/unread
Description
Source
File: bp-templates/bp-nouveau/includes/messages/ajax.php
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 | 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.