$preloaded_api_requests = rawurlencode( wp_json_encode( $this->preloaded_api_requests ) ); $preloaded_api_requests_script = "wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( JSON.parse( decodeURIComponent( '" . esc_js( $preloaded_api_requests ) . "' ) ) ) );"; } wp_add_inline_script( $this->handle, $wc_settings_script . $preloaded_api_requests_script, 'before' ); } } /** * See self::add() for docs. * * @param string $key Key for the data. * @param mixed $data Value for the data. * * @throws InvalidArgumentException If key is not a string or already * exists in internal data cache. */ protected function add_data( $key, $data ) { if ( ! is_string( $key ) ) { if ( $this->debug() ) { throw new InvalidArgumentException( 'Key for the data being registered must be a string' ); } } if ( isset( $this->data[ $key ] ) ) { if ( $this->debug() ) { throw new InvalidArgumentException( 'Overriding existing data with an already registered key is not allowed' ); } return; } if ( \is_callable( $data ) ) { $this->lazy_data[ $key ] = $data; return; } $this->data[ $key ] = $data; } /** * Exposes whether the current site is in debug mode or not. * * @return boolean True means the site is in debug mode. */ protected function debug() { return defined( 'WP_DEBUG' ) && WP_DEBUG; } }