Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Created January 10, 2018 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/49560a13d9d66cd35c9cc14c2ee5db4e to your computer and use it in GitHub Desktop.
Save cameronjonesweb/49560a13d9d66cd35c9cc14c2ee5db4e to your computer and use it in GitHub Desktop.
<?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