芝麻web文件管理V1.00
编辑当前文件:/home/freeclou/optimyar/wp-content/plugins/google-site-kit/includes/Core/Assets/Assets.php
$instance pairs. * * @since 1.0.0 * @var array */ private $assets = array(); /** * Internal flag for whether assets have been registered yet. * * @since 1.2.0 * @var bool */ private $assets_registered = false; /** * Internal list of print callbacks already done. * * @since 1.2.0 * @var array */ private $print_callbacks_done = array(); /** * Constructor. * * @since 1.0.0 * * @param Context $context Plugin context. */ public function __construct( Context $context ) { $this->context = $context; } /** * Registers functionality through WordPress hooks. * * @since 1.0.0 * @since 1.37.0 Enqueues Block Editor assets. */ public function register() { $register_callback = function () { if ( ! is_admin() ) { return; } if ( $this->assets_registered ) { return; } $this->assets_registered = true; $this->register_assets(); }; add_action( 'admin_enqueue_scripts', $register_callback ); add_action( 'wp_enqueue_scripts', $register_callback ); add_filter( 'script_loader_tag', function ( $tag, $handle ) { return $this->add_async_defer_attribute( $tag, $handle ); }, 10, 2 ); // All other asset-related general logic should only be active when the // current user can actually use Site Kit. if ( false === ( current_user_can( Permissions::VIEW_SPLASH ) || current_user_can( Permissions::VIEW_DASHBOARD ) ) ) { return; } $this->add_amp_dev_mode_attributes( $this->get_assets() ); add_action( 'admin_print_scripts-edit.php', function () { global $post_type; if ( 'post' !== $post_type ) { // For CONTEXT_ADMIN_POSTS we only load scripts for the 'post' post type. return; } $assets = $this->get_assets(); array_walk( $assets, function ( Asset $asset ) { if ( $asset->has_context( Asset::CONTEXT_ADMIN_POSTS ) ) { $this->enqueue_asset( $asset->get_handle() ); } } ); } ); if ( is_admin() ) { add_action( 'enqueue_block_assets', function () { $assets = $this->get_assets(); array_walk( $assets, function ( $asset ) { if ( $asset->has_context( Asset::CONTEXT_ADMIN_BLOCK_EDITOR ) ) { $this->enqueue_asset( $asset->get_handle() ); } } ); } ); } add_action( 'enqueue_block_editor_assets', function () { $assets = $this->get_assets(); array_walk( $assets, function ( $asset ) { if ( $asset->has_context( Asset::CONTEXT_ADMIN_POST_EDITOR ) ) { $this->enqueue_asset( $asset->get_handle() ); } } ); } ); $scripts_print_callback = function () { $scripts = wp_scripts(); $this->run_before_print_callbacks( $scripts, $scripts->queue ); }; add_action( 'wp_print_scripts', $scripts_print_callback ); add_action( 'admin_print_scripts', $scripts_print_callback ); $styles_print_callback = function () { $styles = wp_styles(); $this->run_before_print_callbacks( $styles, $styles->queue ); }; add_action( 'wp_print_styles', $styles_print_callback ); add_action( 'admin_print_styles', $styles_print_callback ); } /** * Enqueues the given plugin asset (script or stylesheet). * * The asset must already be registered in order to be enqueued. * * @since 1.0.0 * * @param string $handle Asset handle. */ public function enqueue_asset( $handle ) { // Register assets on-the-fly if necessary (currently the case for admin bar in frontend). if ( ! $this->assets_registered ) { $this->assets_registered = true; $this->register_assets(); } $assets = $this->get_assets(); if ( empty( $assets[ $handle ] ) ) { return; } $assets[ $handle ]->enqueue(); } /** * Enqueues Google fonts. * * @since 1.0.0 * @deprecated 1.41.0 This method is no longer used as fonts are loaded as a normal style dependency now. */ public function enqueue_fonts() { _deprecated_function( __METHOD__, '1.41.0' ); $assets = $this->get_assets(); if ( ! empty( $assets['googlesitekit-fonts'] ) && $assets['googlesitekit-fonts'] instanceof Asset ) { $assets['googlesitekit-fonts']->enqueue(); } } /** * Get Google fonts src for CSS. * * @since 1.41.0 * * @return string String URL src. */ protected function get_fonts_src() { $font_families = array( 'Google+Sans+Text:400,500', 'Google+Sans+Display:400,500,700', ); if ( Feature_Flags::enabled( 'gm3Components' ) ) { $font_families[] = 'Roboto:300,400,500'; } $filtered_font_families = apply_filters( 'googlesitekit_font_families', $font_families ); if ( empty( $filtered_font_families ) ) { return ''; } return add_query_arg( array( 'family' => implode( '|', $filtered_font_families ), 'subset' => 'latin-ext', 'display' => 'fallback', ), 'https://fonts.googleapis.com/css' ); } /** * Registers all plugin assets. * * @since 1.0.0 */ private function register_assets() { $assets = $this->get_assets(); foreach ( $assets as $asset ) { $asset->register( $this->context ); } } /** * Add data-ampdevmode attributes to assets. * * @todo What about dependencies? * * @param Asset[] $assets Assets. */ private function add_amp_dev_mode_attributes( $assets ) { add_filter( 'script_loader_tag', function ( $tag, $handle ) use ( $assets ) { // TODO: 'hoverintent-js' can be removed from here at some point, see https://github.com/ampproject/amp-wp/pull/3928. if ( $this->context->is_amp() && ( isset( $assets[ $handle ] ) && ( $assets[ $handle ] instanceof Script || 'hoverintent-js' === $handle ) ) ) { $tag = preg_replace( '/(?<=):', " $script_execution", $tag, 1 ); } return $tag; } /** * Executes all extra callbacks before printing a list of dependencies. * * This method ensures that such callbacks that run e.g. `wp_add_inline_script()` are executed just-in-time, * only when the asset is actually loaded in the current request. * * This method works recursively, also looking at dependencies, and supports both scripts and stylesheets. * * @since 1.2.0 * * @param WP_Dependencies $dependencies WordPress dependencies class instance. * @param array $handles List of handles to run before print callbacks for. */ private function run_before_print_callbacks( WP_Dependencies $dependencies, array $handles ) { $is_amp = $this->context->is_amp(); foreach ( $handles as $handle ) { if ( isset( $this->print_callbacks_done[ $handle ] ) ) { continue; } $this->print_callbacks_done[ $handle ] = true; if ( isset( $this->assets[ $handle ] ) ) { $this->assets[ $handle ]->before_print(); // TODO: This can be removed at some point, see https://github.com/ampproject/amp-wp/pull/4001. if ( $is_amp && $this->assets[ $handle ] instanceof Script ) { $this->add_extra_script_amp_dev_mode( $handle ); } } if ( isset( $dependencies->registered[ $handle ] ) && is_array( $dependencies->registered[ $handle ]->deps ) ) { $this->run_before_print_callbacks( $dependencies, $dependencies->registered[ $handle ]->deps ); } } } /** * Adds a comment to all extra scripts so that they are considered compatible with AMP dev mode. * * {@see Assets::add_amp_dev_mode_attributes()} makes all registered scripts and stylesheets compatible, including * their potential inline additions. This method does the same for extra scripts, which are registered under the * 'data' key. * * @since 1.4.0 * * @param string $handle The handle of a registered script. */ private function add_extra_script_amp_dev_mode( $handle ) { $data = wp_scripts()->get_data( $handle, 'data' ) ?: ''; if ( ! empty( $data ) && is_string( $data ) ) { wp_scripts()->add_data( $handle, 'data', '/*googlesitekit*/ ' . $data ); } } /** * Gets the prefix for the client side cache key. * * Cache key is scoped to user session and blog_id to isolate the * cache between users and sites (in multisite). * * @since 1.92.0 * * @return string */ private function get_storage_prefix() { $current_user = wp_get_current_user(); $auth_cookie = wp_parse_auth_cookie(); $blog_id = get_current_blog_id(); $session_token = isset( $auth_cookie['token'] ) ? $auth_cookie['token'] : ''; return wp_hash( $current_user->user_login . '|' . $session_token . '|' . $blog_id ); } /** * Gets the product post type. * * @since 1.116.0 * * @return string|null The product post type name or null if not present on the website. */ protected function get_product_post_type() { /** * Filters the product post type. * * @since 1.116.0 * * @param string $product_post_type The product post type name. */ $product_post_type = apply_filters( 'googlesitekit_product_post_type', 'product' ); $product_type = get_post_type_object( $product_post_type ); if ( $product_type instanceof WP_Post_Type && $product_type->public ) { return $product_post_type; } return null; } }