Yoast_Notification_Center::ajax_dismiss_notification()public staticYoast 1.0

Dismiss a notification.

Метод класса: Yoast_Notification_Center{}

Хуков нет.

Возвращает

null. Ничего.

Использование

$result = Yoast_Notification_Center::ajax_dismiss_notification();

Код Yoast_Notification_Center::ajax_dismiss_notification() Yoast 20.4

public static function ajax_dismiss_notification() {
	$notification_center = self::get();

	if ( ! isset( $_POST['notification'] ) || ! is_string( $_POST['notification'] ) ) {
		die( '-1' );
	}

	$notification_id = sanitize_text_field( wp_unslash( $_POST['notification'] ) );

	if ( empty( $notification_id ) ) {
		die( '-1' );
	}

	// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are using the variable as a nonce.
	if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['nonce'] ), $notification_id ) ) {
		die( '-1' );
	}

	$notification = $notification_center->get_notification_by_id( $notification_id );
	if ( ( $notification instanceof Yoast_Notification ) === false ) {

		// Permit legacy.
		$options      = [
			'id'            => $notification_id,
			'dismissal_key' => $notification_id,
		];
		$notification = new Yoast_Notification( '', $options );
	}

	if ( self::maybe_dismiss_notification( $notification ) ) {
		die( '1' );
	}

	die( '-1' );
}