providers; } /** * Returns the Provider which controls a given key. */ public function get_provider_for_key( $key ) { foreach ( $this->providers as $provider ) { if ( $provider::owns_key( $key ) ) { return $provider; } } return null; } /** * Get all critical CSS storage keys that are available for the current request. * Caches the result. * * @return array */ public function get_current_request_css_keys() { static $keys = null; if ( null !== $keys ) { return $keys; } $keys = array(); foreach ( $this->providers as $provider ) { $provider_keys = $provider::get_current_storage_keys(); if ( empty( $provider_keys ) ) { continue; } $keys = array_merge( $keys, $provider_keys ); } return $keys; } /** * Get critical CSS for the current request. * * @return string|false */ public function get_current_request_css() { if ( null !== $this->request_cached_css ) { return $this->request_cached_css; } $storage = new Critical_CSS_Storage(); $data = $storage->get_css( $this->get_current_request_css_keys() ); if ( false === $data ) { return false; } $this->request_cached_css = $data['css']; $this->current_critical_css_key = $data['key']; return $this->request_cached_css; } /** * Get providers sources. * * @return array */ public function get_provider_sources() { $sources = array(); $wp_core_provider_urls = WP_Core_Provider::get_critical_source_urls(); $flat_wp_core_urls = array(); foreach ( $wp_core_provider_urls as $urls ) { $flat_wp_core_urls = array_merge( $flat_wp_core_urls, $urls ); } foreach ( $this->get_providers() as $provider ) { $provider_name = $provider::get_provider_name(); // For each provider, // Gather a list of URLs that are going to be used as Critical CSS source. foreach ( $provider::get_critical_source_urls() as $group => $urls ) { if ( empty( $urls ) ) { continue; } // This removes the home and blog pages from the list of pages, // so they don't belong to two separate groups. if ( $provider !== WP_Core_Provider::class ) { $urls = array_values( array_diff( $urls, $flat_wp_core_urls ) ); } if ( empty( $urls ) ) { continue; } $key = $provider_name . '_' . $group; // For each URL // Track the state and errors in a state array. $sources[] = array( 'key' => $key, 'label' => $provider::describe_key( $key ), /** * Filters the URLs used by Critical CSS * * @param array $urls The list of URLs to be used to generate critical CSS * * @since 1.0.0 */ 'urls' => apply_filters( 'jetpack_boost_critical_css_urls', $urls ), 'success_ratio' => $provider::get_success_ratio(), ); } } return $sources; } }