Created
January 10, 2018 02:46
-
-
Save cameronjonesweb/49560a13d9d66cd35c9cc14c2ee5db4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cameronjonesweb_bp_mark_notifications_read() { | |
// Get the action. | |
$action = !empty( $_GET['action'] ) ? $_GET['action'] : ''; | |
$nonce = !empty( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : ''; | |
$id = !empty( $_GET['notification_id'] ) ? $_GET['notification_id'] : ''; | |
// Bail if no action or no ID. | |
if ( ( 'cameronjonesweb-read-notification' !== $action ) || empty( $id ) || empty( $nonce ) ) { | |
return false; | |
} | |
// Check the nonce and mark the notification. | |
if ( bp_verify_nonce_request( 'bp_notification_mark_read_' . $id ) ) { | |
BP_Notifications_Notification::update( | |
array( 'is_new' => false ), | |
array( 'id' => $id ) | |
); | |
} | |
$target = remove_query_arg( array( | |
'_wpnonce', 'action', 'notification_id' | |
) ); | |
// Redirect. | |
wp_redirect( $target ); | |
} | |
add_action( 'bp_actions', 'cameronjonesweb_bp_mark_notifications_read' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment