ror(); } $notices = $this->dismiss_global( $post['id'] ); $level = self::DISMISS_GLOBAL; } else { $notices = $this->dismiss_user( $post['id'] ); $level = self::DISMISS_USER; } /** * Allows developers to apply additional logic to the dismissing notice process. * Executes after updating option or user meta (according to the notice level). * * @since 1.6.7.1 * * @param string $notice_id Notice ID (slug). * @param integer $level Notice level. * @param array $notices Dismissed notices. */ do_action( 'wpforms_admin_notice_dismiss_ajax', $post['id'], $level, $notices ); if ( ! wpforms_debug() ) { wp_send_json_success(); } wp_send_json_success( [ 'id' => $post['id'], 'time' => time(), 'level' => $level, 'notices' => $notices, ] ); } /** * AJAX sub-routine that updates dismissed notices option. * * @since 1.6.7.1 * * @param string $id Notice Id. * * @return array Notices. */ private function dismiss_global( $id ) { $id = str_replace( 'global-', '', $id ); $notices = get_option( 'wpforms_admin_notices', [] ); $notices[ $id ] = [ 'time' => time(), 'dismissed' => true, ]; update_option( 'wpforms_admin_notices', $notices, true ); return $notices; } /** * AJAX sub-routine that updates dismissed notices user meta. * * @since 1.6.7.1 * * @param string $id Notice Id. * * @return array Notices. */ private function dismiss_user( $id ) { $user_id = get_current_user_id(); $notices = get_user_meta( $user_id, 'wpforms_admin_notices', true ); $notices = ! is_array( $notices ) ? [] : $notices; $notices[ $id ] = [ 'time' => time(), 'dismissed' => true, ]; update_user_meta( $user_id, 'wpforms_admin_notices', $notices ); return $notices; } }