Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P16237
Adopt Google Font proxy for Wikimedia.it WordPress theme
Active
Public
Actions
Authored by
valerio.bozzolan
on May 29 2021, 10:04 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
WMIT-Infrastructure
Subscribers
None
<?php
/*
* Enable a Google Font proxy
*
* Author: Valerio Bozzolan
* License: GNU General Public License v2 or later
* Date: 2021
*
* See https://phabricator.wikimedia.org/T282613
* See https://gitpull.it/T776
* See https://gitpull.it/R26:f8b39ca15e8ba48a92fb0d58c2772e9b02691059
*/
/**
* Local Google Font cache
*/
define
(
'GOOGLE_FONT_PROXY'
,
'fonts.wikimedia.it'
);
/**
* Convert a Google Font domain to your local proxy cache
*
* See https://phabricator.wikimedia.org/T266998
*/
function
convert_google_font_to_local_proxy
(
$url
)
{
return
str_replace
(
'fonts.googleapis.com'
,
GOOGLE_FONT_PROXY
,
$url
);
}
/**
* Avoid Google Fonts in your stylesheets
*
* https://phabricator.wikimedia.org/T282613
*/
add_filter
(
'style_loader_src'
,
'convert_google_font_to_local_proxy'
);
/**
* Avoid Google Fonts in your DNS prefetch
*
* https://phabricator.wikimedia.org/T282613
*/
add_filter
(
'wp_resource_hints'
,
function
(
$urls
)
{
foreach
(
$urls
as
&
$url
)
{
$url
=
convert_google_font_to_local_proxy
(
$url
);
}
return
$urls
;
}
);
Event Timeline
valerio.bozzolan
created this paste.
May 29 2021, 10:04 PM
2021-05-29 22:04:51 (UTC+0)
valerio.bozzolan
mentioned this in
T282613: Deploy a KISS Google Font proxy for Wikimedia Italia (fonts.wikimedia.it)
.
May 29 2021, 10:16 PM
2021-05-29 22:16:44 (UTC+0)
valerio.bozzolan
mentioned this in
T266998: Avoid third party resources from *.wikimedia.it websites
.
May 29 2021, 10:34 PM
2021-05-29 22:34:16 (UTC+0)
Log In to Comment