admin_page = $admin_page; $this->menu_slug = $menu_slug; $this->css_prefix = $css_prefix; } /** * Override render funtion * * @return void */ public function render() { ?>
<?php src="//en.wordpress.com/i/loading/loading-64.gif" />
menu_slug ) ) { return; } $asset_handle = self::SCRIPT_HANDLE; $asset_name = 'build.min'; $dashboard_config = new Dashboard_Config_Data( $this->admin_page, $this->menu_slug ); $config_data = $dashboard_config->get_data(); if ( file_exists( __DIR__ . "/../dist/{$asset_name}.js" ) ) { // Load local assets for the convenience of development. Assets::register_script( $asset_handle, "../dist/{$asset_name}.js", __FILE__, array( 'enqueue' => true, 'in_footer' => true, 'textdomain' => 'jetpack-blaze', ) ); } else { $css_url = $asset_name . ( is_rtl() ? '.rtl' : '' ) . '.css'; $css_handle = $asset_handle . '-style'; wp_enqueue_script( $asset_handle, sprintf( self::CDN_URL, self::BLAZEDASH_VERSION, "{$asset_name}.js" ), self::JS_DEPENDENCIES, $this->get_cdn_asset_cache_buster(), true ); wp_enqueue_style( $css_handle, sprintf( self::CDN_URL, self::BLAZEDASH_VERSION, $css_url ), array(), $this->get_cdn_asset_cache_buster() ); } wp_add_inline_script( $asset_handle, $dashboard_config->get_js_config_data( $config_data ), 'before' ); } /** * Returns cache buster string for assets. * Development mode doesn't need this, as it's handled by `Assets` class. */ protected function get_cdn_asset_cache_buster() { // Use cached cache buster in production. $remote_asset_version = get_transient( self::BLAZEDASH_CACHE_BUSTER_CACHE_KEY ); if ( ! empty( $remote_asset_version ) ) { return $remote_asset_version; } // If no cached cache buster, we fetch it from CDN and set to transient. $response = wp_remote_get( sprintf( self::CDN_URL, self::BLAZEDASH_VERSION, 'build_meta.json' ), array( 'timeout' => 5 ) ); if ( is_wp_error( $response ) ) { // fallback to the package version. return self::PACKAGE_VERSION; } $build_meta = json_decode( wp_remote_retrieve_body( $response ), true ); if ( ! empty( $build_meta['cache_buster'] ) ) { // Cache the cache buster for 15 mins. set_transient( self::BLAZEDASH_CACHE_BUSTER_CACHE_KEY, $build_meta['cache_buster'], 15 * MINUTE_IN_SECONDS ); return $build_meta['cache_buster']; } // fallback to the package version. return self::PACKAGE_VERSION; } }