File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 141141 'health-check-get-sizes ' ,
142142 'toggle-auto-updates ' ,
143143 'send-password-reset ' ,
144+ 'dismiss-notice ' ,
144145);
145146
146147// Deprecated.
Original file line number Diff line number Diff line change @@ -5610,3 +5610,40 @@ function wp_ajax_send_password_reset() {
56105610 wp_send_json_error ( $ results ->get_error_message () );
56115611 }
56125612}
5613+
5614+ /**
5615+ * Handles dismissing a notice via AJAX.
5616+ *
5617+ * @since 6.5.0
5618+ */
5619+ function wp_ajax_dismiss_notice () {
5620+ check_ajax_referer ( 'dismiss-notice ' , 'nonce ' );
5621+
5622+ if ( ! isset ( $ _POST ['slug ' ] ) ) {
5623+ wp_send_json_error ( __ ( 'Failed to dismiss notice: The notice does not have a slug. ' ) );
5624+ }
5625+
5626+ $ slug = trim ( sanitize_text_field ( $ _POST ['slug ' ] ) );
5627+ if ( '' === $ slug ) {
5628+ wp_send_json_error ( __ ( "Failed to dismiss notice: The notice's slug must not be an empty string. " ) );
5629+ }
5630+
5631+ $ expiration = 0 ;
5632+ if ( isset ( $ _POST ['expiration ' ] ) ) {
5633+ if ( ! is_numeric ( $ _POST ['expiration ' ] ) ) {
5634+ wp_send_json_error ( __ ( 'Failed to dismiss notice: The expiration time must be a number of seconds. ' ) );
5635+ }
5636+
5637+ $ expiration = (int ) $ _POST ['expiration ' ];
5638+
5639+ if ( 0 > $ _POST ['expiration ' ] ) {
5640+ wp_send_json_error ( __ ( 'Failed to dismiss notice: The expiration time must be greater than or equal to 0. ' ) );
5641+ }
5642+ }
5643+
5644+ if ( false === set_site_transient ( "wp_admin_notice_dismissed_ {$ slug }" , 1 , $ expiration ) ) {
5645+ wp_send_json_error ( __ ( 'Failed to dismiss notice: The notice could not be dismissed. ' ) );
5646+ }
5647+
5648+ wp_send_json_success ( __ ( 'The notice was successfully dismissed. ' ) );
5649+ }
You can’t perform that action at this time.
0 commit comments