>wc_version . $this->package->get_path() ); } /** * Initialize and load cached script data from the transient cache. * * @return array */ private function get_cached_script_data() { if ( $this->disable_cache ) { return []; } $transient_value = json_decode( (string) get_transient( $this->script_data_transient_key ), true ); if ( json_last_error() !== JSON_ERROR_NONE || empty( $transient_value ) || empty( $transient_value['script_data'] ) || empty( $transient_value['version'] ) || $transient_value['version'] !== $this->wc_version || empty( $transient_value['hash'] ) || $transient_value['hash'] !== $this->script_data_hash ) { return []; } return (array) ( $transient_value['script_data'] ?? [] ); } /** * Store all cached script data in the transient cache. */ public function update_script_data_cache() { if ( is_null( $this->script_data ) || $this->disable_cache ) { return; } set_transient( $this->script_data_transient_key, wp_json_encode( array( 'script_data' => $this->script_data, 'version' => $this->wc_version, 'hash' => $this->script_data_hash, ) ), DAY_IN_SECONDS * 30 ); } /** * Get src, version and dependencies given a script relative src. * * @param string $relative_src Relative src to the script. * @param array $dependencies Optional. An array of registered script handles this script depends on. Default empty array. * * @return array src, version and dependencies of the script. */ public function get_script_data( $relative_src, $dependencies = [] ) { if ( ! $relative_src ) { return array( 'src' => '', 'version' => '1', 'dependencies' => $dependencies, ); } if ( is_null( $this->script_data ) ) { $this->script_data = $this->get_cached_script_data(); } if ( empty( $this->script_data[ $relative_src ] ) ) { $asset_path = $this->package->get_path( str_replace( '.js', '.asset.php', $relative_src ) ); // The following require is safe because we are checking if the file exists and it is not a user input. // nosemgrep audit.php.lang.security.file.inclusion-arg. $asset = file_exists( $asset_path ) ? require $asset_path : []; $this->script_data[ $relative_src ] = array( 'src' => $this->get_asset_url( $relative_src ), 'version' => ! empty( $asset['version'] ) ? $asset['version'] : $this->get_file_version( $relative_src ), 'dependencies' => ! empty( $asset['dependencies'] ) ? $asset['dependencies'] : [], ); } // Return asset details as well as the requested dependencies array. return [ 'src' => $this->script_data[ $relative_src ]['src'], 'version' => $this->script_data[ $relative_src ]['version'], 'dependencies' => array_merge( $this->script_data[ $relative_src ]['dependencies'], $dependencies ), ]; } /** * Registers a script according to `wp_register_script`, adding the correct prefix, and additionally loading translations. * * When creating script assets, the following rules should be followed: * 1. All asset handles should have a `wc-` prefix. * 2. If the asset handle is for a Block (in editor context) use the `-block` suffix. * 3. If the asset handle is for a Block (in frontend context) use the `-block-frontend` suffix. * 4. If the asset is for any other script being consumed or enqueued by the blocks plugin, use the `wc-blocks-` prefix. * * @since 2.5.0 * @throws Exception If the registered script has a dependency on itself. * * @param string $handle Unique name of the script. * @param string $relative_src Relative url for the script to the path from plugin root. * @param array $dependencies Optional. An array of registered script handles this script depends on. Default empty array. * @param bool $has_i18n Optional. Whether to add a script translation call to this file. Default: true. */ public function register_script( $handle, $relative_src, $dependencies = [], $has_i18n = true ) { $script_data = $this->get_script_data( $relative_src, $dependencies ); if ( in_array( $handle, $script_data['dependencies'], true ) ) { if ( $this->package->feature()->is_development_environment() ) { $dependencies = array_diff( $script_data['dependencies'], [ $handle ] ); add_action( 'admin_notices', function() use ( $handle ) { echo '

'; /* translators: %s file handle name. */ printf( esc_html__( 'Script with handle %s had a dependency on itself which has been removed. This is an indicator that your JS code has a circular dependency that can cause bugs.', 'woocommerce' ), esc_html( $handle ) ); echo '

'; } ); } else { throw new Exception( sprintf( 'Script with handle %s had a dependency on itself. This is an indicator that your JS code has a circular dependency that can cause bugs.', $handle ) ); } } /** * Filters the list of script dependencies. * * @since 3.0.0 * * @param array $dependencies The list of script dependencies. * @param string $handle The script's handle. * @return array */ $script_dependencies = apply_filters( 'woocommerce_blocks_register_script_dependencies', $script_data['dependencies'], $handle ); wp_register_script( $handle, $script_data['src'], $script_dependencies, $script_data['version'], true ); if ( $has_i18n && function_exists( 'wp_set_script_translations' ) ) { wp_set_script_translations( $handle, 'woocommerce', $this->package->get_path( 'languages' ) ); } } /** * Registers a style according to `wp_register_style`. * * @since 2.5.0 * @since 2.6.0 Change src to be relative source. * * @param string $handle Name of the stylesheet. Should be unique. * @param string $relative_src Relative source of the stylesheet to the plugin path. * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array. * @param string $media Optional. The media for which this stylesheet has been defined. Default 'all'. Accepts media types like * 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'. * @param boolean $rtl Optional. Whether or not to register RTL styles. */ public function register_style( $handle, $relative_src, $deps = [], $media = 'all', $rtl = false ) { $filename = str_replace( plugins_url( '/', dirname( __DIR__ ) ), '', $relative_src ); $src = $this->get_asset_url( $relative_src ); $ver = $this->get_file_version( $filename ); wp_register_style( $handle, $src, $deps, $ver, $media ); if ( $rtl ) { wp_style_add_data( $handle, 'rtl', 'replace' ); } } /** * Returns the appropriate asset path for current builds. * * @param string $filename Filename for asset path (without extension). * @param string $type File type (.css or .js). * @return string The generated path. */ public function get_block_asset_build_path( $filename, $type = 'js' ) { return "assets/client/blocks/$filename.$type"; } /** * Adds an inline script, once. * * @param string $handle Script handle. * @param string $script Script contents. */ public function add_inline_script( $handle, $script ) { if ( ! empty( $this->inline_scripts[ $handle ] ) && in_array( $script, $this->inline_scripts[ $handle ], true ) ) { return; } wp_add_inline_script( $handle, $script ); if ( isset( $this->inline_scripts[ $handle ] ) ) { $this->inline_scripts[ $handle ][] = $script; } else { $this->inline_scripts[ $handle ] = array( $script ); } } }
Fatal error: Uncaught Error: Class "Automattic\WooCommerce\Blocks\Assets\Api" not found in /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php:222 Stack trace: #0 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Domain\Bootstrap->Automattic\WooCommerce\Blocks\Domain\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #1 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #2 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #3 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php(228): Automattic\WooCommerce\Blocks\Registry\Container->get('Automattic\\WooC...') #4 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Domain\Bootstrap->Automattic\WooCommerce\Blocks\Domain\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #5 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #6 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #7 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php(343): Automattic\WooCommerce\Blocks\Registry\Container->get('Automattic\\WooC...') #8 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Domain\Bootstrap->Automattic\WooCommerce\Blocks\Domain\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #9 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #10 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #11 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php(131): Automattic\WooCommerce\Blocks\Registry\Container->get('Automattic\\WooC...') #12 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php(84): Automattic\WooCommerce\Blocks\Domain\Bootstrap->init() #13 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Package.php(106): Automattic\WooCommerce\Blocks\Domain\Bootstrap->__construct(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #14 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Package::Automattic\WooCommerce\Blocks\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #15 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #16 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #17 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Package.php(44): Automattic\WooCommerce\Blocks\Registry\Container->get('Automattic\\WooC...') #18 [internal function]: Automattic\WooCommerce\Blocks\Package::init() #19 /htdocs/wp-content/plugins/woocommerce/src/Packages.php(128): call_user_func(Array) #20 /htdocs/wp-content/plugins/woocommerce/src/Packages.php(64): Automattic\WooCommerce\Packages::initialize_packages() #21 /htdocs/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Packages::on_init('') #22 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #23 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #24 /htdocs/wp-settings.php(555): do_action('plugins_loaded') #25 /htdocs/wp-config.php(178): require_once('/htdocs/wp-sett...') #26 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #27 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #28 /htdocs/index.php(17): require('/htdocs/wp-blog...') #29 {main} thrown in /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php on line 222