PHP 8.2.31
Preview: NoticeHandler.php Size: 2.02 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/StoreApi/Utilities/NoticeHandler.php

<?php
namespace Automattic\WooCommerce\StoreApi\Utilities;

use Automattic\WooCommerce\StoreApi\Exceptions\RouteException;
use WP_Error;

/**
 * NoticeHandler class.
 * Helper class to handle notices.
 */
class NoticeHandler {

	/**
	 * Convert queued error notices into an exception.
	 *
	 * For example, Payment methods may add error notices during validate_fields call to prevent checkout.
	 * Since we're not rendering notices at all, we need to convert them to exceptions.
	 *
	 * This method will find the first error message and thrown an exception instead. Discards notices once complete.
	 *
	 * @throws RouteException If an error notice is detected, Exception is thrown.
	 *
	 * @param string $error_code Error code for the thrown exceptions.
	 */
	public static function convert_notices_to_exceptions( $error_code = 'unknown_server_error' ) {
		if ( 0 === wc_notice_count( 'error' ) ) {
			wc_clear_notices();
			return;
		}

		$error_notices = wc_get_notices( 'error' );

		// Prevent notices from being output later on.
		wc_clear_notices();

		foreach ( $error_notices as $error_notice ) {
			throw new RouteException( $error_code, wp_strip_all_tags( $error_notice['notice'] ), 400 );
		}
	}

	/**
	 * Collects queued error notices into a \WP_Error.
	 *
	 * For example, cart validation processes may add error notices to prevent checkout.
	 * Since we're not rendering notices at all, we need to catch them and group them in a single WP_Error instance.
	 *
	 * This method will discard notices once complete.
	 *
	 * @param string $error_code Error code for the thrown exceptions.
	 *
	 * @return \WP_Error The WP_Error object containing all error notices.
	 */
	public static function convert_notices_to_wp_errors( $error_code = 'unknown_server_error' ) {
		$errors = new WP_Error();

		if ( 0 === wc_notice_count( 'error' ) ) {
			return $errors;
		}

		$error_notices = wc_get_notices( 'error' );

		foreach ( $error_notices as $error_notice ) {
			$errors->add( $error_code, wp_strip_all_tags( $error_notice['notice'] ) );
		}

		return $errors;
	}
}

Directory Contents

Dirs: 0 × Files: 21

Name Size Perms Modified Actions
14.76 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
1.49 KB lrw-r--r-- 2024-04-30 19:35:34
Edit Download
48.42 KB lrw-r--r-- 2026-03-12 20:10:34
Edit Download
1.81 KB lrw-r--r-- 2025-06-23 19:46:28
Edit Download
10.82 KB lrw-r--r-- 2025-06-23 19:46:28
Edit Download
1.76 KB lrw-r--r-- 2024-09-04 20:34:26
Edit Download
5.45 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
5.67 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
2.02 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
3.29 KB lrw-r--r-- 2025-12-22 17:20:32
Edit Download
32.10 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
2.05 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
3.65 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
3.54 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
1.82 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
21.61 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
9.25 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
10.11 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
6.14 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
794 B lrw-r--r-- 2024-02-27 18:59:46
Edit Download
1.73 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).