| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Flying Fonts |
| 4 |
* Plugin URI: https://wordpress.org/plugins/flying-fonts/ |
| 5 |
* Description: Eliminate Google Fonts to reduce network requests and prevent FOUT or CLS, using system fonts for faster performance and a smoother experience. |
| 6 |
* Author: WP Speed Matters |
| 7 |
* Author URI: https://wpspeedmatters.com/ |
| 8 |
* Version: 1.0.2 |
| 9 |
* Text Domain: flying-fonts |
| 10 |
*/ |
| 11 |
|
| 12 |
defined('ABSPATH') or die('Bye!'); |
| 13 |
define('FLYING_FONTS_VERSION', '1.0.2'); |
| 14 |
|
| 15 |
function flying_fonts_rewrite_html($html) |
| 16 |
{ |
| 17 |
$html = preg_replace('/<link.*fonts.googleapis.com.*>/i', '', $html); |
| 18 |
$html = preg_replace('/<link.*fonts.gstatic.com.*>/i', '', $html); |
| 19 |
$style = |
| 20 |
"<style>body{font-family:-apple-system,system-ui,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,'Fira Sans','Droid Sans','Helvetica Neue',sans-serif !important}code{font-family:Menlo,Consolas,Monaco,Liberation Mono,Lucida Console,monospace !important}</style>"; |
| 21 |
$html = str_replace('</head>', $style . '</head>', $html); |
| 22 |
return $html; |
| 23 |
} |
| 24 |
|
| 25 |
if (!is_admin()) { |
| 26 |
ob_start('flying_fonts_rewrite_html'); |
| 27 |
} |
| 28 |
|
| 29 |
if (!defined('FLYING_PRESS_VERSION')) { |
| 30 |
add_filter('plugin_action_links_' . plugin_basename(__FILE__), function ($links) { |
| 31 |
$plugin_shortcuts[] = |
| 32 |
'<a href="https://flyingpress.com?ref=swap_google_fonts_display" target="_blank" style="color:#3db634;">Get FlyingPress</a>'; |
| 33 |
return array_merge($links, $plugin_shortcuts); |
| 34 |
}); |
| 35 |
} |