Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
wpcomsh_google_fonts_proxy
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Customizations to the Google Fonts module available in Jetpack.
4 *
5 * @package wpcomsh
6 */
7
8/*
9 * The old versions of Gutenberg that don't support the Font Library very well use this constant
10 * to disable the Font Library. Leave it as it is to keep disabling the Font Library.
11 */
12if ( ! defined( 'FONT_LIBRARY_DISABLED' ) ) {
13    define( 'FONT_LIBRARY_DISABLED', true );
14}
15
16/**
17 * Replaces Google Fonts API references in enqueued styles with our caching reverse proxy.
18 *
19 * @see pMz3w-g6E-p2#comment-103418
20 *
21 * @param string|array $src The source URL of the enqueued style.
22 * @return string|array
23 */
24function wpcomsh_google_fonts_proxy( $src ) {
25    // If an array, run the function on each item.
26    if ( is_array( $src ) ) {
27        return array_map( 'wpcomsh_google_fonts_proxy', $src );
28    }
29    $src = str_replace( 'fonts.googleapis.com', 'fonts-api.wp.com', $src );
30    $src = str_replace( 'fonts.gstatic.com', 'fonts.wp.com', $src );
31    return $src;
32}
33add_filter( 'style_loader_src', 'wpcomsh_google_fonts_proxy' );
34add_filter( 'wp_resource_hints', 'wpcomsh_google_fonts_proxy' );
35add_filter( 'jetpack_google_fonts_api_url', 'wpcomsh_google_fonts_proxy' );
36add_filter( 'custom_fonts_google_fonts_api_url', 'wpcomsh_google_fonts_proxy' );
37add_filter( 'jetpack_global_styles_google_fonts_api_url', 'wpcomsh_google_fonts_proxy' );