bp_legacy_theme_ajax_close_notice()

Close and keep closed site wide notices from an admin in the sidebar, via a POST request.


Description Description


Return Return

(mixed) String on error, void on success.


Top ↑

Source Source

File: bp-templates/bp-legacy/buddypress-functions.php

function bp_legacy_theme_ajax_close_notice() {
	if ( ! bp_is_post_request() ) {
		return;
	}

	$nonce_check = isset( $_POST['nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['nonce'] ), 'bp_messages_close_notice' );

	if ( ! $nonce_check || ! isset( $_POST['notice_id'] ) ) {
		echo "-1<div id='message' class='error'><p>" . __( 'There was a problem closing the notice.', 'buddypress' ) . '</p></div>';

	} else {
		$user_id    = get_current_user_id();
		$notice_ids = bp_get_user_meta( $user_id, 'closed_notices', true );
		if ( ! is_array( $notice_ids ) ) {
			$notice_ids = array();
		}

		$notice_ids[] = (int) $_POST['notice_id'];

		bp_update_user_meta( $user_id, 'closed_notices', $notice_ids );
	}

	exit;
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.