• I’ve been having issues with certain fonts not wanting to enqueue, such as WP’s dashicons.

    I’ve managed to narrow it down to a single test in the combinator logic to see if a file should be combined.

    See inside the loop in Combinator::combine_styles. The following line:
    @strpos( Helper::get_home_url(), parse_url( $wp_styles->registered[ $handle ]->src, PHP_URL_HOST ) ) === false || // Skip all external sources.

    Upon further investigation, I have noticed that all files that I expect to be included all specify ONLY a file path in the source, instead of a full URL.

    dashicons: skip "https://staging4.aeontech.com.au/" !== "" ("/wp-includes/css/dashicons.min.css")
    admin-bar: skip "https://staging4.aeontech.com.au/" !== "" ("/wp-includes/css/admin-bar.min.css")
    wp-block-library: skip "https://staging4.aeontech.com.au/" !== "" ("/wp-includes/css/dist/block-library/style.min.css")

    The above output was generated as follows:
    printf( "reason \"%s\" !== \"%s\" (\"%s\")\n", Helper::get_home_url(), parse_url( $wp_styles->registered[ $handle ]->src, PHP_URL_HOST ), $wp_styles->registered[ $handle ]->src );

    In order to resolve this, I added a check at the start of the foreach loop to prepend the site URL to any sources that include a path only. This has resulted in the new $src variable, which I have gone to the liberty of putting through the function.

    
    // Get groups of handles.
    foreach ( $styles->to_do as $handle ) {
    	$src = $wp_styles->registered[ $handle ]->src;
    
    	// Ensure the src has a host. If not, it is relative to the WordPress domain.
    	if ( $src{0} === '/' ) {
    		$src = Helper::get_home_url() . $src;
    	}
    
    	// Get the src host.
    	$host = parse_url( $src, PHP_URL_HOST );
    
    	if (
    		( true === $in_header && $styles->groups[ $handle ] > 0 ) || // Bail if the style is not in the header/footer.
    		in_array( $handle, $excluded_styles ) || // If the style is excluded from combination.
    		false === $src || // If the source is empty.
    		@strpos( Helper::get_home_url(), $host ) === false  || // Skip all external sources.
    		pathinfo( $src, PATHINFO_EXTENSION ) === 'php' || // If it's dynamically generated css.
    		is_int( strpos( $handle, 'elementor-post-' ) ) // Exclude all elementor styles.
    	) {
    		continue;
    	}
    
    	// Check for inline styles.
    	$item_inline_style = $styles->get_data( $handle, 'after' );
    
    	if ( ! empty( $item_inline_style ) ) {
    		// Check for inline styles.
    		$inline_styles .= implode( $item_inline_style, "\n" );
    	}
    
    	$content[ $src ] = $this->get_style_content( $src );
    
    	// Remove the style from registered styles.
    	unset( $wp_styles->registered[ $handle ] );
    }
    

    Kind Regards
    Shane Thompson

    • This topic was modified 5 years, 2 months ago by shanept.
    • This topic was modified 5 years, 2 months ago by shanept.
    • This topic was modified 5 years, 2 months ago by shanept.
  • The topic ‘CSS Combinator Dashicons’ is closed to new replies.