first commit

This commit is contained in:
Roman Pyrih
2023-07-24 08:30:51 +02:00
commit c2e100a763
7128 changed files with 1622619 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
<?php
/* * * * * * * * * * * * * * * * * * * * *
*
* ██████╗ ███╗ ███╗ ██████╗ ███████╗
* ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
* ██║ ██║██╔████╔██║██║ ███╗█████╗
* ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
* ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
* ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
*
* @package : OMGF
* @author : Daan van den Bergh
* @copyright: (c) 2021 Daan van den Bergh
* @url : https://daan.dev
* * * * * * * * * * * * * * * * * * * */
defined('ABSPATH') || exit;
class OMGF_Admin_Notice
{
const OMGF_ADMIN_NOTICE_TRANSIENT = 'omgf_admin_notice';
const OMGF_ADMIN_NOTICE_EXPIRATION = 60;
/** @var array $notices */
public static $notices = [];
/**
* @param $message
* @param string $type (info|warning|error|success)
* @param string $screen_id
* @param bool $json
* @param int $code
*/
public static function set_notice($message, $message_id = '', $die = true, $type = 'success', $code = 200, $screen_id = 'all')
{
self::$notices = get_transient(self::OMGF_ADMIN_NOTICE_TRANSIENT);
if (!self::$notices) {
self::$notices = [];
}
self::$notices[$screen_id][$type][$message_id] = $message;
set_transient(self::OMGF_ADMIN_NOTICE_TRANSIENT, self::$notices, self::OMGF_ADMIN_NOTICE_EXPIRATION);
if ($die) {
switch ($type) {
case 'error':
wp_send_json_error($message, $code);
break;
default:
wp_send_json_success($message, $code);
}
}
}
/**
* @param string $message_id
* @param string $type
* @param string $screen_id
*/
public static function unset_notice($message_id = '', $type = 'info', $screen_id = 'all')
{
self::$notices = get_transient(self::OMGF_ADMIN_NOTICE_TRANSIENT);
if (isset(self::$notices[$screen_id][$type][$message_id])) {
unset(self::$notices[$screen_id][$type][$message_id]);
}
if (is_array(self::$notices) && empty(self::$notices[$screen_id][$type])) {
unset(self::$notices[$screen_id][$type]);
}
set_transient(self::OMGF_ADMIN_NOTICE_TRANSIENT, self::$notices, self::OMGF_ADMIN_NOTICE_EXPIRATION);
}
/**
* Prints notice (if any) grouped by type.
*/
public static function print_notices()
{
$admin_notices = get_transient(self::OMGF_ADMIN_NOTICE_TRANSIENT);
if (is_array($admin_notices)) {
$current_screen = get_current_screen();
foreach ($admin_notices as $screen => $notice) {
if ($current_screen->id != $screen && $screen != 'all') {
continue;
}
foreach ($notice as $type => $message) {
?>
<div id="message" class="notice notice-<?php echo $type; ?> is-dismissible">
<?php foreach ($message as $line) : ?>
<p><strong><?= $line; ?></strong></p>
<?php endforeach; ?>
</div>
<?php
}
}
}
delete_transient(self::OMGF_ADMIN_NOTICE_TRANSIENT);
}
}

View File

@@ -0,0 +1,526 @@
<?php
/* * * * * * * * * * * * * * * * * * * * *
*
* ██████╗ ███╗ ███╗ ██████╗ ███████╗
* ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
* ██║ ██║██╔████╔██║██║ ███╗█████╗
* ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
* ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
* ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
*
* @package : OMGF
* @author : Daan van den Bergh
* @copyright: (c) 2021 Daan van den Bergh
* @url : https://daan.dev
* * * * * * * * * * * * * * * * * * * */
defined('ABSPATH') || exit;
class OMGF_Admin_Settings extends OMGF_Admin
{
const OMGF_ADMIN_PAGE = 'optimize-webfonts';
/**
* Transients
*/
const OMGF_NEWS_REEL = 'omgf_news_reel';
const OMGF_CURRENT_DB_VERSION = 'omgf_current_db_version';
/**
* Settings Fields
*/
const OMGF_SETTINGS_FIELD_OPTIMIZE = 'omgf-optimize-settings';
const OMGF_SETTINGS_FIELD_DETECTION = 'omgf-detection-settings';
const OMGF_SETTINGS_FIELD_ADVANCED = 'omgf-advanced-settings';
const OMGF_SETTINGS_FIELD_HELP = 'omgf-help';
/**
* Option Values
*/
const OMGF_OPTIMIZATION_MODE = [
'manual' => 'Manual (default)',
'auto' => 'Automatic (Pro)'
];
const OMGF_FONT_PROCESSING_OPTIONS = [
'replace' => 'Replace (default)',
'remove' => 'Remove only'
];
const OMGF_FONT_DISPLAY_OPTIONS = [
'swap' => 'Swap (recommended)',
'auto' => 'Auto',
'block' => 'Block',
'fallback' => 'Fallback',
'optional' => 'Optional'
];
const OMGF_FILE_TYPES_OPTIONS = [
'woff2' => 'Web Open Font Format 2.0 (WOFF2)',
'woff' => 'Web Open Font Format (WOFF)',
'eot' => 'Embedded OpenType (EOT)',
'ttf' => 'TrueType Font (TTF)',
'svg' => 'Scalable Vector Graphics (SVG)'
];
const OMGF_FORCE_SUBSETS_OPTIONS = [
'arabic' => 'Arabic',
'bengali' => 'Bengali',
'chinese-hongkong' => 'Chinese (Hong Kong)',
'chinese-simplified' => 'Chinese (Simplified)',
'chinese-traditional' => 'Chinese (Traditional)',
'cyrillic' => 'Cyrillic',
'cyrillic-ext' => 'Cyrillic Extended',
'devanagari' => 'Devanagari',
'greek' => 'Greek',
'greek-ext' => 'Greek Extended',
'gujarati' => 'Gujarati',
'gurmukhi' => 'Gurmukhi',
'hebrew' => 'Hebrew',
'japanese' => 'Japanese',
'kannada' => 'Kannada',
'khmer' => 'Khmer',
'korean' => 'Korean',
'latin' => 'Latin',
'latin-ext' => 'Latin Extended',
'malayalam' => 'Malayalam',
'myanmar' => 'Myanmar',
'oriya' => 'Oriya',
'sinhala' => 'Sinhala',
'tamil' => 'Tamil',
'telugu' => 'Telugu',
'thai' => 'Thai',
'tibetan' => 'Tibetan',
'vietnamese' => 'Vietnamese'
];
const OMGF_FALLBACK_FONT_STACKS_OPTIONS = [
'arial' => 'Arial',
'baskerville' => 'Baskerville',
'bodoni-mt' => 'Bodoni MT',
'calibri' => 'Calibri',
'calisto-mt' => 'Calisto MT',
'cambria' => 'Cambria',
'candara' => 'Candara',
'century-gothic' => 'Century Gothic',
'consolas' => 'Consolas',
'copperplate-gothic' => 'Copperplate Gothic',
'courier-new' => 'Courier New',
'dejavu-sans' => 'Dejavu Sans',
'didot' => 'Didot',
'franklin-gothic' => 'Franklin Gothic',
'garamond' => 'Garamond',
'georgia' => 'Georgia',
'gill-sans' => 'Gill Sans',
'goudy-old-style' => 'Goudy Old Style',
'helvetica' => 'Helvetica',
'impact' => 'Impact',
'lucida-bright' => 'Lucida Bright',
'lucida-sans' => 'Lucida Sans',
'ms-sans-serif' => 'Microsoft Sans Serif',
'optima' => 'Optima',
'palatino' => 'Palatino',
'perpetua' => 'Perpetua',
'rockwell' => 'Rockwell',
'segoe-ui' => 'Segoe UI',
'tahoma' => 'Tahoma',
'trebuchet-ms' => 'Trebuchet MS',
'verdana' => 'Verdana'
];
const OMGF_AMP_HANDLING_OPTIONS = [
'fallback' => 'Fallback (default)',
'disable' => 'Disable'
];
/**
* Optimize Fonts
*/
const OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION = 'omgf_display_option';
const OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL = 'omgf_manual_optimize_url';
const OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE = 'omgf_optimization_mode';
const OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS = 'omgf_optimized_fonts';
const OMGF_OPTIMIZE_SETTING_OPTIMIZE_EDIT_ROLES = 'omgf_optimize_edit_roles';
const OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS = 'omgf_preload_fonts';
const OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS = 'omgf_unload_fonts';
const OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS = 'omgf_unload_stylesheets';
const OMGF_OPTIMIZE_SETTING_CACHE_KEYS = 'omgf_cache_keys';
/**
* Detection Settings
*/
const OMGF_DETECTION_SETTING_FONT_PROCESSING = 'omgf_font_processing';
/**
* Advanced Settings
*/
const OMGF_ADV_SETTING_AMP_HANDLING = 'omgf_amp_handling';
const OMGF_ADV_SETTING_CACHE_PATH = 'omgf_cache_dir';
const OMGF_ADV_SETTING_SOURCE_URL = 'omgf_fonts_url';
const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
/**
* Miscellaneous
*/
const OMGF_OPTIONS_GENERAL_PAGE_OPTIMIZE_WEBFONTS = 'options-general.php?page=optimize-webfonts';
const OMGF_PLUGINS_INSTALL_CHANGELOG_SECTION = 'plugin-install.php?tab=plugin-information&plugin=host-webfonts-local&TB_iframe=true&width=772&height=1015&section=changelog';
const FFWP_WORDPRESS_PLUGINS_OMGF_PRO = 'https://ffw.press/wordpress/omgf-pro/';
/** @var string $active_tab */
private $active_tab;
/** @var string $page */
private $page;
/** @var string $plugin_text_domain */
private $plugin_text_domain = 'host-webfonts-local';
/** @var string|null */
private $submit_button_text = null;
/**
* OMGF_Admin_Settings constructor.
*/
public function __construct()
{
parent::__construct();
$this->active_tab = isset($_GET['tab']) ? $_GET['tab'] : self::OMGF_SETTINGS_FIELD_OPTIMIZE;
$this->page = isset($_GET['page']) ? $_GET['page'] : '';
add_action('admin_menu', [$this, 'create_menu']);
add_filter('plugin_action_links_' . plugin_basename(OMGF_PLUGIN_FILE), [$this, 'create_settings_link']);
if ($this->page !== self::OMGF_ADMIN_PAGE) {
return;
}
if ($this->active_tab == self::OMGF_SETTINGS_FIELD_OPTIMIZE) {
$this->submit_button_text = __('Save & Optimize', $this->plugin_text_domain);
}
// Footer Text
add_filter('admin_footer_text', [$this, 'footer_text_left'], 99);
add_filter('update_footer', [$this, 'footer_text_right'], 11);
// Tabs
add_action('omgf_settings_tab', [$this, 'optimize_fonts_tab'], 0);
add_action('omgf_settings_tab', [$this, 'detection_settings_tab'], 1);
add_action('omgf_settings_tab', [$this, 'advanced_settings_tab'], 2);
add_action('omgf_settings_tab', [$this, 'help_tab'], 3);
// Content
add_action('omgf_settings_content', [$this, 'optimize_fonts_content'], 0);
add_action('omgf_settings_content', [$this, 'detection_settings_content'], 1);
add_action('omgf_settings_content', [$this, 'advanced_settings_content'], 2);
add_action('omgf_settings_content', [$this, 'help_content'], 3);
}
/**
* Creates the menu item.
*/
public function create_menu()
{
add_options_page(
'OMGF',
'Optimize Google Fonts',
'manage_options',
self::OMGF_ADMIN_PAGE,
[$this, 'create_settings_page']
);
add_action('admin_init', [$this, 'register_settings']);
}
/**
* Display the settings page.
*/
public function create_settings_page()
{
if (!current_user_can('manage_options')) {
wp_die(__("You're not cool enough to access this page.", $this->plugin_text_domain));
}
?>
<div class="wrap omgf">
<h1><?= apply_filters('omgf_settings_page_title', __('OMGF | Optimize My Google Fonts', $this->plugin_text_domain)); ?></h1>
<p>
<?= get_plugin_data(OMGF_PLUGIN_FILE)['Description']; ?>
</p>
<div class="settings-column">
<h2 class="omgf-nav nav-tab-wrapper">
<?php do_action('omgf_settings_tab'); ?>
</h2>
<?php do_action('omgf_settings_content'); ?>
</div>
</div>
<?php
}
/**
* Register all settings.
*
* @throws ReflectionException
*/
public function register_settings()
{
if (
$this->active_tab !== self::OMGF_SETTINGS_FIELD_OPTIMIZE
&& $this->active_tab !== self::OMGF_SETTINGS_FIELD_DETECTION
&& $this->active_tab !== self::OMGF_SETTINGS_FIELD_ADVANCED
&& $this->active_tab !== self::OMGF_SETTINGS_FIELD_HELP
) {
$this->active_tab = apply_filters('omgf_admin_settings_active_tab', self::OMGF_SETTINGS_FIELD_OPTIMIZE);
}
foreach ($this->get_settings() as $constant => $value) {
register_setting(
$this->active_tab,
$value
);
}
}
/**
* Get all settings using the constants in this class.
*
* @return array
* @throws ReflectionException
*/
public function get_settings()
{
$reflection = new ReflectionClass($this);
$constants = apply_filters('omgf_settings_constants', $reflection->getConstants());
switch ($this->active_tab) {
case (self::OMGF_SETTINGS_FIELD_DETECTION):
$needle = 'OMGF_DETECTION_SETTING_';
break;
case (self::OMGF_SETTINGS_FIELD_ADVANCED):
$needle = 'OMGF_ADV_SETTING_';
break;
case (self::OMGF_SETTINGS_FIELD_HELP):
$needle = 'OMGF_HELP_SETTING_';
default:
$needle = apply_filters('omgf_settings_needle', 'OMGF_OPTIMIZE_SETTING_');
}
return array_filter(
$constants,
function ($key) use ($needle) {
return strpos($key, $needle) !== false;
},
ARRAY_FILTER_USE_KEY
);
}
public function optimize_fonts_tab()
{
$this->generate_tab(self::OMGF_SETTINGS_FIELD_OPTIMIZE, 'dashicons-performance', __('Optimize Fonts', $this->plugin_text_domain));
}
/**
* Add Basic Settings Tab to Settings Screen.
*/
public function detection_settings_tab()
{
$this->generate_tab(self::OMGF_SETTINGS_FIELD_DETECTION, 'dashicons-search', __('Detection Settings', $this->plugin_text_domain));
}
/**
* Add Advanced Settings Tab to Settings Screen.
*/
public function advanced_settings_tab()
{
$this->generate_tab(self::OMGF_SETTINGS_FIELD_ADVANCED, 'dashicons-admin-settings', __('Advanced Settings', $this->plugin_text_domain));
}
/**
* Add Help Tab to Settings Screen.
*
* @return void
*/
public function help_tab()
{
$this->generate_tab(self::OMGF_SETTINGS_FIELD_HELP, 'dashicons-editor-help', __('Help', $this->plugin_text_domain));
}
/**
* @param $id
* @param null $icon
* @param null $label
*/
private function generate_tab($id, $icon = null, $label = null)
{
?>
<a class="nav-tab dashicons-before <?= $icon; ?> <?= $this->active_tab == $id ? 'nav-tab-active' : ''; ?>" href="<?= $this->generate_tab_link($id); ?>">
<?= $label; ?>
</a>
<?php
}
/**
* @param $tab
*
* @return string
*/
private function generate_tab_link($tab)
{
return admin_url(self::OMGF_OPTIONS_GENERAL_PAGE_OPTIMIZE_WEBFONTS . "&tab=$tab");
}
/**
*
*/
public function optimize_fonts_content()
{
$this->do_settings_content(self::OMGF_SETTINGS_FIELD_OPTIMIZE);
}
/**
* Render Basic Settings content
*/
public function detection_settings_content()
{
$this->do_settings_content(self::OMGF_SETTINGS_FIELD_DETECTION);
}
/**
* Render Advanced Settings content
*/
public function advanced_settings_content()
{
$this->do_settings_content(self::OMGF_SETTINGS_FIELD_ADVANCED);
}
/**
* Render Help content
*
* @return void
*/
public function help_content()
{
$this->do_settings_content(self::OMGF_SETTINGS_FIELD_HELP);
}
/**
* @param $field
*/
private function do_settings_content($field)
{
if ($this->active_tab != $field) {
return;
}
?>
<form id="<?= $field; ?>-form" name="omgf-settings-form" method="post" action="<?= admin_url('options.php?tab=' . $this->active_tab); ?>" autocomplete="off">
<?php
settings_fields($field);
do_settings_sections($field);
do_action('omgf_before_settings_form_settings');
echo apply_filters(str_replace('-', '_', $field) . '_content', '');
do_action('omgf_after_settings_form_settings');
?>
<?php if ($this->active_tab !== self::OMGF_SETTINGS_FIELD_HELP) : ?>
<?php submit_button($this->submit_button_text, 'primary', 'submit', false); ?>
<a id="omgf-empty" data-cache-section="/*" data-nonce="<?= wp_create_nonce(self::OMGF_ADMIN_PAGE); ?>" class="omgf-empty button-cancel"><?php _e('Empty Cache Directory', $this->plugin_text_domain); ?></a>
<?php endif; ?>
</form>
<?php
}
/**
* @param $links
*
* @return mixed
*/
public function create_settings_link($links)
{
$adminUrl = admin_url() . self::OMGF_OPTIONS_GENERAL_PAGE_OPTIMIZE_WEBFONTS;
$settingsLink = "<a href='$adminUrl'>" . __('Settings') . "</a>";
array_push($links, $settingsLink);
return $links;
}
/**
* Changes footer text.
*
* @return string
*/
public function footer_text_left()
{
$text = sprintf(__('Coded with %s in The Netherlands @ <strong>FFW.Press</strong>.', $this->plugin_text_domain), '<span class="dashicons dashicons-heart ffwp-heart"></span>');
return '<span id="footer-thankyou">' . $text . '</span>';
}
/**
* All logic to generate the news reel in the bottom right of the footer on all of OMGF's settings pages.
*
* Includes multiple checks to make sure the reel is only shown if a recent post is available.
*
* @param mixed $text
* @return mixed
*/
public function footer_text_right($text)
{
if (!extension_loaded('simplexml')) {
return $text;
}
/**
* If a WordPress update is available, show the original text.
*/
if (strpos($text, 'Get Version') !== false) {
return $text;
}
// Prevents bashing the API.
$xml = get_transient(self::OMGF_NEWS_REEL);
if (!$xml) {
$response = wp_remote_get('https://ffw.press/blog/tag/omgf/feed');
if (!is_wp_error($response)) {
$xml = wp_remote_retrieve_body($response);
// Refresh the feed once a day to prevent bashing of the API.
set_transient(self::OMGF_NEWS_REEL, $xml, DAY_IN_SECONDS);
}
}
if (!$xml) {
return $text;
}
/**
* Make sure the XML is properly encoded.
*/
$xml = utf8_encode(html_entity_decode($xml));
$xml = simplexml_load_string($xml);
if (!$xml) {
return $text;
}
$items = $xml->channel->item ?? [];
if (empty($items)) {
return $text;
}
$text = sprintf(__('Recently tagged <a target="_blank" href="%s"><strong>#OMGF</strong></a> on my blog:', $this->plugin_text_domain), 'https://daan.dev/tag/omgf') . ' ';
$text .= '<span id="omgf-ticker-wrap">';
$i = 0;
foreach ($items as $item) {
$hide = $i > 0 ? 'style="display: none;"' : '';
$text .= "<span class='ticker-item' $hide>" . sprintf('<a target="_blank" href="%s"><em>%s</em></a>', $item->link, $item->title) . '</span>';
$i++;
}
$text .= "</span>";
return $text;
}
}

View File

@@ -0,0 +1,133 @@
<?php
/* * * * * * * * * * * * * * * * * * * * *
*
* ██████╗ ███╗ ███╗ ██████╗ ███████╗
* ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
* ██║ ██║██╔████╔██║██║ ███╗█████╗
* ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
* ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
* ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
*
* @package : OMGF
* @author : Daan van den Bergh
* @copyright: (c) 2021 Daan van den Bergh
* @url : https://daan.dev
* * * * * * * * * * * * * * * * * * * */
defined('ABSPATH') || exit;
class OMGF_Admin_Settings_Advanced extends OMGF_Admin_Settings_Builder
{
/**
* OMGF_Admin_Settings_Advanced constructor.
*/
public function __construct()
{
parent::__construct();
$this->title = __('Advanced Settings', $this->plugin_text_domain);
// Open
add_filter('omgf_advanced_settings_content', [$this, 'do_title'], 10);
add_filter('omgf_advanced_settings_content', [$this, 'do_description'], 15);
add_filter('omgf_advanced_settings_content', [$this, 'do_before'], 20);
// Settings
add_filter('omgf_advanced_settings_content', [$this, 'do_promo_amp_handling'], 40);
add_filter('omgf_advanced_settings_content', [$this, 'do_promo_exclude_posts'], 50);
add_filter('omgf_advanced_settings_content', [$this, 'do_cache_dir'], 70);
add_filter('omgf_advanced_settings_content', [$this, 'do_promo_fonts_source_url'], 80);
add_filter('omgf_advanced_settings_content', [$this, 'do_uninstall'], 110);
// Close
add_filter('omgf_advanced_settings_content', [$this, 'do_after'], 200);
}
/**
* Description
*/
public function do_description()
{
?>
<p>
<?= __('If you require the downloaded/generated files to be saved in a different location or served from a different resource (e.g. a CDN) or path, use these settings to make OMGF work with your configuration.', $this->plugin_text_domain); ?>
</p>
<?php
}
public function do_promo_amp_handling()
{
$this->do_select(
__('AMP handling (Pro)', $this->plugin_text_domain),
'omgf_pro_amp_handling',
OMGF_Admin_Settings::OMGF_AMP_HANDLING_OPTIONS,
defined('OMGF_PRO_AMP_HANDLING') ? OMGF_PRO_AMP_HANDLING : '',
sprintf(__("Decide how OMGF Pro should behave on AMP pages. Only select <strong>enable</strong> if the custom CSS limit of 75kb is not already reached by your theme and/or other plugins and no other <code>amp-custom</code> tag is present on your pages.", $this->plugin_text_domain), OMGF_Admin_Settings::FFWP_WORDPRESS_PLUGINS_OMGF_PRO) . ' ' . $this->promo,
false,
true
);
}
/**
* Excluded Post/Page IDs (Pro)
*
* @return void
*/
public function do_promo_exclude_posts()
{
$this->do_text(
__('Excluded Post/Page IDs (Pro)', $this->plugin_text_domain),
'omgf_pro_excluded_ids',
__('e.g. 1,2,5,21,443'),
defined('OMGF_PRO_EXCLUDED_IDS') ? OMGF_PRO_EXCLUDED_IDS : '',
__('A comma separated list of post/page IDs where OMGF Pro shouldn\'t run. Only works when Advanced Proccessing is enabled under Detection Settings.', $this->plugin_text_domain) . ' ' . $this->promo,
true
);
}
/**
*
*/
public function do_cache_dir()
{
$this->do_text(
__('Fonts Cache Directory', $this->plugin_text_domain),
OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH,
__('e.g. /uploads/omgf', $this->plugin_text_domain),
OMGF_CACHE_PATH,
__("The directory (inside <code>wp-content</code>) where font files should be stored. Give each site a unique value if you're using Multisite. Defaults to <code>/uploads/omgf</code>. After changing this setting, the directory will be created if it doesn't exist and existing files will be moved automatically.", $this->plugin_text_domain)
);
}
/**
*
*/
public function do_promo_fonts_source_url()
{
$this->do_text(
__('Fonts Source URL (Pro)', $this->plugin_text_domain),
'omgf_pro_source_url',
__('e.g. https://cdn.mydomain.com/alternate/relative-path', $this->plugin_text_domain),
defined('OMGF_PRO_SOURCE_URL') ? OMGF_PRO_SOURCE_URL : '',
sprintf(
__("Modify the <code>src</code> URL for each font file in the stylesheet. This can be anything, like an absolute URL (e.g. <code>%s</code>) to an alternate relative URL (e.g. <code>/renamed-wp-content-dir/alternate/path/to/font-files</code>). Make sure you include the full path to where OMGF's files are stored and/or served from. Defaults to <code>%s</code>.", $this->plugin_text_domain),
str_replace(home_url(), 'https://your-cdn.com', WP_CONTENT_URL . OMGF_CACHE_PATH),
WP_CONTENT_URL . OMGF_CACHE_PATH
) . ' ' . $this->promo,
true
);
}
/**
*
*/
public function do_uninstall()
{
$this->do_checkbox(
__('Remove Settings/Files At Uninstall', $this->plugin_text_domain),
OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL,
OMGF_UNINSTALL,
__('Warning! This will remove all settings and cached fonts upon plugin deletion.', $this->plugin_text_domain)
);
}
}

View File

@@ -0,0 +1,223 @@
<?php
/* * * * * * * * * * * * * * * * * * * * *
*
* ██████╗ ███╗ ███╗ ██████╗ ███████╗
* ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
* ██║ ██║██╔████╔██║██║ ███╗█████╗
* ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
* ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
* ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
*
* @package : OMGF
* @author : Daan van den Bergh
* @copyright: (c) 2021 Daan van den Bergh
* @url : https://daan.dev
* * * * * * * * * * * * * * * * * * * */
defined('ABSPATH') || exit;
class OMGF_Admin_Settings_Builder
{
/** @var string $plugin_text_domain */
protected $plugin_text_domain = 'host-webfonts-local';
/** @var $title */
protected $title;
/** @var $promo string */
protected $promo;
/**
* Only sets the promo string on settings load.
*
* OMGF_Admin_Settings_Builder constructor.
*/
public function __construct()
{
add_filter('omgf_optimize_settings_content', [$this, 'do_promo']);
add_filter('omgf_detection_settings_content', [$this, 'do_promo']);
add_filter('omgf_advanced_settings_content', [$this, 'do_promo']);
}
/**
*
*/
public function do_promo()
{
if (apply_filters('apply_omgf_pro_promo', true)) {
$this->promo = apply_filters('omgf_pro_promo', sprintf(__('<a href="%s" target="_blank">Upgrade to Pro</a> to enable this option.', $this->plugin_text_domain), OMGF_Admin_Settings::FFWP_WORDPRESS_PLUGINS_OMGF_PRO));
}
}
/**
*
*/
public function do_before()
{
?>
<table class="form-table">
<?php
}
/**
*
*/
public function do_after()
{
?>
</table>
<?php
}
/**
*
*/
public function do_title()
{
?>
<h3><?= $this->title ?></h3>
<?php
}
/**
* Generate radio setting
*
* @param $label
* @param $inputs
* @param $name
* @param $checked
* @param $description
*/
public function do_radio($label, $inputs, $name, $checked, $description)
{
?>
<tr>
<th scope="row"><?= $label; ?></th>
<td>
<?php foreach ($inputs as $option => $option_label) : ?>
<label>
<input type="radio" <?= strpos($option_label, '(Pro)') !== false ? apply_filters($name . '_' . $option . '_setting_disabled', 'disabled') : ''; ?> class="<?= str_replace('_', '-', $name . '_' . $option); ?>" name="<?= $name; ?>" value="<?= $option; ?>" <?= $option == $checked ? 'checked="checked"' : ''; ?> />
<?= $option_label; ?>
</label>
<br />
<?php endforeach; ?>
<p class="description">
<?= $description . ' ' . $this->promo; ?>
</p>
</td>
</tr>
<?php
}
/**
* Generate select setting
*
* @param $label
* @param $name
* @param $options
* @param $selected
* @param $description
* @param bool $update_required
*/
public function do_select($label, $name, $options, $selected, $description, $is_multiselect = false, $disabled = false)
{
?>
<tr>
<th scope="row">
<?= apply_filters($name . '_setting_label', $label); ?>
</th>
<td>
<select name="<?= $name; ?><?= $is_multiselect ? '[]' : ''; ?>" class="<?= str_replace('_', '-', $name); ?>" <?= $is_multiselect ? 'size="8" multiple="multiple"' : ''; ?> <?= apply_filters($name . '_setting_disabled', $disabled) ? 'disabled' : ''; ?>>
<?php
$options = apply_filters($name . '_setting_options', $options);
?>
<?php foreach ($options as $option => $option_label) : ?>
<?php
if (is_array($selected)) {
$is_selected = in_array($option, $selected);
} else {
$is_selected = $selected == $option;
}
?>
<option value="<?= $option; ?>" <?= $is_selected ? 'selected="selected"' : ''; ?>><?= $option_label; ?></option>
<?php endforeach; ?>
</select>
<p class="description">
<?= apply_filters($name . '_setting_description', $description); ?>
</p>
</td>
</tr>
<?php
}
/**
* Generate number setting.
*
* @param $label
* @param $name
* @param $value
* @param $description
*/
public function do_number($label, $name, $value, $description, $min = 0, $visible = true)
{
?>
<tr valign="top" <?= $visible ? '' : 'style="display: none;"'; ?>>
<th scope="row"><?= apply_filters($name . '_setting_label', $label); ?></th>
<td>
<input class="<?= str_replace('_', '-', $name); ?>" type="number" name="<?= $name; ?>" min="<?= $min; ?>" value="<?= $value; ?>" />
<p class="description">
<?= apply_filters($name . '_setting_description', $description); ?>
</p>
</td>
</tr>
<?php
}
/**
* Generate text setting.
*
* @param $label
* @param $name
* @param $placeholder
* @param $value
* @param string $description
* @param bool $update_required
*/
public function do_text($label, $name, $placeholder, $value, $description = '', $disabled = false)
{
?>
<tr class="<?= str_replace('_', '-', $name); ?>-row">
<th scope="row"><?= apply_filters($name . '_setting_label', $label); ?></th>
<td>
<input <?= apply_filters($name . '_setting_disabled', $disabled) ? 'disabled' : ''; ?> class="<?= str_replace('_', '-', $name); ?>" type="text" name="<?= $name; ?>" placeholder="<?= $placeholder; ?>" value="<?= $value; ?>" />
<p class="description">
<?= apply_filters($name . 'setting_description', $description); ?>
</p>
</td>
</tr>
<?php
}
/**
* Generate checkbox setting.
*
* @param $label
* @param $name
* @param $checked
* @param $description
*/
public function do_checkbox($label, $name, $checked, $description, $disabled = false)
{
?>
<tr>
<th scope="row"><?= apply_filters($name . '_setting_label', $label); ?></th>
<td>
<label for="<?= $name; ?>">
<input id="<?= $name; ?>" type="checkbox" <?= apply_filters($name . '_setting_disabled', $disabled) ? 'disabled' : ''; ?> class="<?= str_replace('_', '-', $name); ?>" name="<?= $name; ?>" <?= $checked == "on" ? 'checked = "checked"' : ''; ?> />
<?= apply_filters($name . '_setting_description', $description); ?>
</label>
</td>
</tr>
<?php
}
}

View File

@@ -0,0 +1,179 @@
<?php
/* * * * * * * * * * * * * * * * * * * * *
*
* ██████╗ ███╗ ███╗ ██████╗ ███████╗
* ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
* ██║ ██║██╔████╔██║██║ ███╗█████╗
* ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
* ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
* ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
*
* @package : OMGF
* @author : Daan van den Bergh
* @copyright: (c) 2021 Daan van den Bergh
* @url : https://daan.dev
* * * * * * * * * * * * * * * * * * * */
defined('ABSPATH') || exit;
class OMGF_Admin_Settings_Detection extends OMGF_Admin_Settings_Builder
{
public function __construct()
{
parent::__construct();
$this->title = __('Google Fonts Detection Settings', $this->plugin_text_domain);
// Open
add_filter('omgf_detection_settings_content', [$this, 'do_title'], 10);
add_filter('omgf_detection_settings_content', [$this, 'do_description'], 15);
add_filter('omgf_detection_settings_content', [$this, 'do_before'], 20);
// Settings
add_filter('omgf_detection_settings_content', [$this, 'do_process_google_fonts'], 30);
add_filter('omgf_detection_settings_content', [$this, 'do_promo_advanced_processing'], 40);
add_filter('omgf_detection_settings_content', [$this, 'do_promo_safe_mode'], 50);
add_filter('omgf_detection_settings_content', [$this, 'do_promo_fonts_processing'], 60);
add_filter('omgf_detection_settings_content', [$this, 'do_promo_process_resource_hints'], 70);
// Close
add_filter('omgf_detection_settings_content', [$this, 'do_after'], 100);
}
/**
* Description
*/
public function do_description()
{
?>
<p>
<?= __('These settings affect OMGF\'s automatic detection mechanism and how it treats the Google Fonts your theme and plugins use. If you want to use OMGF to remove the Google Fonts your WordPress configuration currently uses, set <strong>Google Fonts Processing</strong> to Remove.', $this->plugin_text_domain); ?>
</p>
<?php
}
/**
*
*/
public function do_promo_fonts_processing()
{
?>
<tr>
<th scope="row"><?= __('Google Fonts Processing (Pro)', $this->plugin_text_domain); ?></th>
<td>
<fieldset id="" class="scheme-list">
<?php foreach ($this->fonts_processing_pro_options() as $name => $data) : ?>
<?php
$checked = defined(strtoupper($name)) ? constant(strtoupper($name)) : false;
$disabled = apply_filters($name . '_setting_disabled', true) ? 'disabled' : '';
?>
<label for="<?= $name; ?>">
<input type="checkbox" name="<?= $name; ?>" id="<?= $name; ?>" <?= $checked ? 'checked="checked"' : ''; ?> <?= $disabled; ?> /><?= $data['label']; ?>
&nbsp;
</label>
<?php endforeach; ?>
</fieldset>
<p class="description">
<?= $this->promo; ?>
</p>
<ul>
<?php foreach ($this->fonts_processing_pro_options() as $name => $data) : ?>
<li><strong><?= $data['label']; ?></strong>: <?= $data['description']; ?></li>
<?php endforeach; ?>
</ul>
</td>
</tr>
<?php
}
/**
* @return array
*/
private function fonts_processing_pro_options()
{
return [
'omgf_pro_process_stylesheets' => [
'label' => __('Process External Stylesheets', $this->plugin_text_domain),
'description' => __('Process stylesheets loaded from <code>fonts.googleapis.com</code> or <code>fonts.gstatic.com</code>.', $this->plugin_text_domain)
],
'omgf_pro_process_stylesheet_imports' => [
'label' => __('Process Stylesheet Imports', $this->plugin_text_domain),
'description' => __('Scan stylesheets loaded by your theme and plugins for <code>@import</code> statements loading Google Fonts and process them.', $this->plugin_text_domain)
],
'omgf_pro_process_stylesheet_font_faces' => [
'label' => __('Process Stylesheet Font Faces', $this->plugin_text_domain),
'description' => __('Scan stylesheets loaded by your theme and plugins for <code>@font-face</code> statements loading Google Fonts and process them.', $this->plugin_text_domain)
],
'omgf_pro_process_inline_styles' => [
'label' => __('Process Inline Styles', $this->plugin_text_domain),
'description' => __('Process all inline <code>@font-face</code> and <code>@import</code> rules loading Google Fonts.', $this->plugin_text_domain)
],
'omgf_pro_process_webfont_loader' => [
'label' => __('Process Webfont Loader', $this->plugin_text_domain),
'description' => __('Process <code>webfont.js</code> libraries and the corresponding configuration defining which Google Fonts to load.', $this->plugin_text_domain)
],
'omgf_pro_process_early_access' => [
'label' => __('Process Early Access', $this->plugin_text_domain),
'description' => __('Process stylesheets loaded from <code>fonts.googleapis.com/earlyaccess</code> or <code>fonts.gstatic.com/ea</code>.', $this->plugin_text_domain)
]
];
}
/**
*
*/
public function do_promo_advanced_processing()
{
$this->do_checkbox(
__('Advanced Processing (Pro)', $this->plugin_text_domain),
'omgf_pro_advanced_processing',
defined('OMGF_PRO_ADVANCED_PROCESSING') ? OMGF_PRO_ADVANCED_PROCESSING : false,
__('By default, OMGF scans for Google Fonts which are registered/enqueued using the <code>wp_enqueue_scripts()</code> action in WordPress\' header (<code>wp_head()</code>). Enabling this option will process all Google Fonts throughout the entire document. This setting can be fine-tuned using the settings below.', $this->plugin_text_domain) . ' ' . $this->promo,
true
);
}
/**
* Add option for Safe Mode (Pro)
*
* @return void
*/
public function do_promo_safe_mode()
{
$this->do_checkbox(
__('Safe Mode (Pro)', $this->plugin_text_domain),
'omgf_pro_safe_mode',
defined('OMGF_PRO_SAFE_MODE') ? OMGF_PRO_SAFE_MODE : false,
__('Enable Safe Mode if Advanced Processing (Pro) breaks styling of certain pages.', $this->plugin_text_domain) . ' ' . $this->promo,
true
);
}
/**
* Add promo options for Process Resource Hints
*/
public function do_promo_process_resource_hints()
{
$this->do_checkbox(
__('Remove Resource Hints (Pro)', $this->plugin_text_domain),
'omgf_pro_process_resource_hints',
defined('OMGF_PRO_PROCESS_RESOURCE_HINTS') ? OMGF_PRO_PROCESS_RESOURCE_HINTS : false,
__('Remove all <code>link</code> elements with a <code>rel</code> attribute value of <code>dns-prefetch</code>, <code>preload</code> or <code>preconnect</code> pointing to <code>fonts.googleapis.com</code> or <code>fonts.gstatic.com</code>.', $this->plugin_text_domain) . ' ' . $this->promo,
true
);
}
/**
*
*/
public function do_process_google_fonts()
{
$this->do_select(
__('Google Fonts Processing', $this->plugin_text_domain),
OMGF_Admin_Settings::OMGF_DETECTION_SETTING_FONT_PROCESSING,
OMGF_Admin_Settings::OMGF_FONT_PROCESSING_OPTIONS,
OMGF_FONT_PROCESSING,
sprintf(__("Choose whether OMGF should (find, download and) <strong>replace</strong> all Google Fonts, or just <strong>remove</strong> them. Choosing Remove will force WordPress to fallback to system fonts.", $this->plugin_text_domain), OMGF_Admin_Settings::FFWP_WORDPRESS_PLUGINS_OMGF_PRO)
);
}
}

View File

@@ -0,0 +1,79 @@
<?php
/* * * * * * * * * * * * * * * * * * * * *
*
* ██████╗ ███╗ ███╗ ██████╗ ███████╗
* ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
* ██║ ██║██╔████╔██║██║ ███╗█████╗
* ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
* ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
* ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
*
* @package : OMGF
* @author : Daan van den Bergh
* @copyright: (c) 2021 Daan van den Bergh
* @url : https://daan.dev
* * * * * * * * * * * * * * * * * * * */
defined('ABSPATH') || exit;
class OMGF_Admin_Settings_Help extends OMGF_Admin_Settings_Builder
{
/**
*
* @return void
*/
public function __construct()
{
$this->title = __('Help & Documentation', $this->plugin_text_domain);
// Title
add_filter('omgf_help_content', [$this, 'do_title'], 10);
// Content
add_filter('omgf_help_content', [$this, 'do_content'], 20);
}
public function do_content()
{
$utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=support_tab';
$tweetUrl = sprintf("https://twitter.com/intent/tweet?text=I+am+using+%s+to+speed+up+Google+Fonts+for+@WordPress!+Try+it+for+yourself:&via=Dan0sz&hashtags=GoogleFonts,WordPress,Pagespeed,Insights&url=%s", str_replace(' ', '+', apply_filters('omgf_settings_page_title', 'OMGF')), apply_filters('omgf_help_tab_plugin_url', 'https://wordpress.org/plugins/host-webfonts-local/'));
?>
<div class="welcome-panel">
<div class="welcome-panel-content">
<h2><?= sprintf(__('Thank you for using %s!', $this->plugin_text_domain), apply_filters('omgf_settings_page_title', 'OMGF')); ?></h2>
<p class="about-description">
<?= sprintf(__('Need help configuring %s? Please refer to the links below to get you started.', $this->plugin_text_domain), apply_filters('omgf_settings_page_title', 'OMGF')); ?>
</p>
<div class="welcome-panel-column-container">
<div class="welcome-panel-column">
<h3>
<?php _e('Need Help?', $this->plugin_text_domain); ?>
</h3>
<ul>
<li><a class="welcome-icon dashicons-controls-forward" target="_blank" href="<?= apply_filters('omgf_settings_help_quick_start', 'https://docs.ffw.press/article/7-quick-start'); ?>"><?= __('Quick Start Guide', $this->plugin_text_domain); ?></a></li>
<li><a class="welcome-icon dashicons-text-page" target="_blank" href="<?= apply_filters('omgf_settings_help_user_manual', 'https://docs.ffw.press/category/4-omgf-pro'); ?>"><?= __('User Manual', $this->plugin_text_domain); ?></a></li>
<li><a class="welcome-icon dashicons-editor-help" target="_blank" href="<?= apply_filters('omgf_settings_help_faq_link', 'https://docs.ffw.press/article/9-frequently-asked-question-faq'); ?>"><?= __('FAQ', $this->plugin_text_domain); ?></a></li>
<li><a class="welcome-icon dashicons-sos" target="_blank" href="<?= apply_filters('omgf_settings_help_troubleshooting_link', 'https://docs.ffw.press/category/37-omgf-pro---troubleshooting'); ?>"><?= __('Troubleshooting Guide', $this->plugin_text_domain); ?></a></li>
<li><a class="welcome-icon dashicons-email" target="_blank" href="<?= apply_filters('omgf_settings_help_support_link', 'https://docs.ffw.press/contact'); ?>"><?= __('Get Support', $this->plugin_text_domain); ?></a></li>
</ul>
</div>
<div class="welcome-panel-column">
<h3><?= sprintf(__('Support %s & Spread the Word!', $this->plugin_text_domain), apply_filters('omgf_settings_page_title', 'OMGF')); ?></h3>
<ul>
<li><a class="welcome-icon dashicons-star-filled" target="_blank" href="<?= apply_filters('omgf_help_tab_review_link', 'https://wordpress.org/support/plugin/host-webfonts-local/reviews/?rate=5#new-post'); ?>"><?= __('Write a 5-star Review or,', $this->plugin_text_domain); ?></a></li>
<li><a class="welcome-icon dashicons-twitter" target="_blank" href="<?= $tweetUrl; ?>"><?= __('Tweet about it!', $this->plugin_text_domain); ?></a></li>
</ul>
</div>
<div class="welcome-panel-column welcome-panel-last">
<h3 class="signature"><?= __('Check out my other plugins', $this->plugin_text_domain); ?> @</h3>
<p class="signature">
<a target="_blank" title="<?= __('Visit FFW Press', $this->plugin_text_domain); ?>" href="https://ffw.press/wordpress-plugins/"><img class="signature-image" alt="<?= __('Visit FFW Press', $this->plugin_text_domain); ?>" src="https://ffw.press/wp-content/uploads/2021/01/logo-color-full@05x.png" /></a>
</p>
</div>
</div>
</div>
</div>
</div>
<?php
}
}

View File

@@ -0,0 +1,387 @@
<?php
/* * * * * * * * * * * * * * * * * * * * *
*
* ██████╗ ███╗ ███╗ ██████╗ ███████╗
* ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
* ██║ ██║██╔████╔██║██║ ███╗█████╗
* ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
* ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
* ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
*
* @package : OMGF
* @author : Daan van den Bergh
* @copyright: (c) 2021 Daan van den Bergh
* @url : https://daan.dev
* * * * * * * * * * * * * * * * * * * */
defined('ABSPATH') || exit;
class OMGF_Admin_Settings_Optimize extends OMGF_Admin_Settings_Builder
{
const FFW_PRESS_OMGF_AF_URL = 'https://ffw.press/wordpress/omgf-additional-fonts/';
/** @var array $optimized_fonts */
private $optimized_fonts;
/**
* OMGF_Admin_Settings_Optimize constructor.
*/
public function __construct()
{
parent::__construct();
$this->title = __('Optimize Google Fonts', $this->plugin_text_domain);
add_filter('omgf_optimize_settings_content', [$this, 'do_title'], 10);
add_filter('omgf_optimize_settings_content', [$this, 'do_description'], 15);
add_filter('omgf_optimize_settings_content', [$this, 'do_before'], 20);
add_filter('omgf_optimize_settings_content', [$this, 'do_optimization_mode'], 30);
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_combine_requests'], 40);
add_filter('omgf_optimize_settings_content', [$this, 'do_display_option'], 50);
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_force_font_display'], 60);
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_include_file_types'], 70);
add_filter('omgf_optimize_settings_content', [$this, 'do_promo_force_subsets'], 80);
add_filter('omgf_optimize_settings_content', [$this, 'do_after'], 100);
add_filter('omgf_optimize_settings_content', [$this, 'do_optimize_fonts_container'], 200);
add_filter('omgf_optimize_settings_content', [$this, 'do_optimize_fonts_contents'], 250);
add_filter('omgf_optimize_settings_content', [$this, 'close_optimize_fonts_container'], 300);
add_filter('omgf_optimize_settings_content', [$this, 'do_before'], 350);
add_filter('omgf_optimize_settings_content', [$this, 'do_optimize_edit_roles'], 375);
add_filter('omgf_optimize_settings_content', [$this, 'do_after'], 400);
}
/**
*
*/
public function do_description()
{
?>
<p>
<?= __('These settings affect the fonts OMGF downloads and the stylesheet it generates. If you\'re simply looking to replace your Google Fonts for locally hosted copies, the default settings should suffice.', $this->plugin_text_domain); ?>
</p>
<p>
<?= sprintf(__('To install additional Google Fonts, an add-on is required, which can be downloaded <a href="%s" target="blank">here</a>.', $this->plugin_text_domain), self::FFW_PRESS_OMGF_AF_URL); ?>
</p>
<?php
}
/**
*
* @return void
*/
public function do_optimization_mode()
{
$this->do_radio(
__('Optimization Mode', $this->plugin_text_domain),
OMGF_Admin_Settings::OMGF_OPTIMIZATION_MODE,
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZATION_MODE,
OMGF_OPTIMIZATION_MODE,
__('<strong>Manual</strong> processing mode is best suited for configurations, which use a fixed number of fonts across the entire site. When in manual mode, the generated stylesheet is forced throughout the entire site. <strong>Automatic</strong> processing mode is best suited for configurations using e.g. page builders, which load different fonts on certain pages.', $this->plugin_text_domain)
);
}
/**
*
*/
public function do_promo_combine_requests()
{
$this->do_checkbox(
__('Combine & Dedupe (Pro)', $this->plugin_text_domain),
'omgf_pro_combine_requests',
defined('OMGF_PRO_COMBINE_REQUESTS') ? true : false,
__('Combine and deduplicate multiple Google Fonts stylesheets into one stylesheet. This feature is always on in OMGF Pro.', $this->plugin_text_domain) . ' ' . $this->promo,
true
);
}
/**
*
*/
public function do_display_option()
{
$this->do_select(
__('Font-Display Option', $this->plugin_text_domain),
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_DISPLAY_OPTION,
OMGF_Admin_Settings::OMGF_FONT_DISPLAY_OPTIONS,
OMGF_DISPLAY_OPTION,
__('Select which value to set the font-display attribute to. Defaults to Swap (recommended).', $this->plugin_text_domain)
);
}
/**
* Force Font-Display Option Site Wide
*/
public function do_promo_force_font_display()
{
$this->do_checkbox(
__('Force Font-Display Option Site Wide (Pro)', $this->plugin_text_domain),
'omgf_pro_force_font_display',
defined('OMGF_PRO_FORCE_FONT_DISPLAY') ? OMGF_PRO_FORCE_FONT_DISPLAY : false,
__('Force the above <code>font-display</code> attribute on all <code>@font-face</code> statements to ensure all text is user-visible while webfonts and icon sets are loading.', $this->plugin_text_domain),
true
);
}
/**
* Display WOFF2 Only
*
* @return void
*/
public function do_promo_include_file_types()
{
$this->do_select(
__('Include File Types (Pro)', $this->plugin_text_domain),
'omgf_pro_file_types',
OMGF_Admin_Settings::OMGF_FILE_TYPES_OPTIONS,
defined('OMGF_PRO_FILE_TYPES') ? OMGF_PRO_FILE_TYPES : [],
__('Select which file types should be included in the stylesheet. Loading <strong>WOFF2</strong> files only will result in a smaller stylesheet, but will make the stylesheet slightly less Cross Browser compatible. Using <strong>WOFF</strong> and <strong>WOFF2</strong> together (default) accounts for +98% of browsers. Add <strong>EOT</strong> for IE 6-10 and <strong>TTF</strong> and <strong>SVG</strong> for legacy Android/iOS browsers. <em>Use CTRL + click to select multiple values</em>.', $this->plugin_text_domain) . ' ' . $this->promo,
true,
true
);
}
/**
*
*/
public function do_promo_force_subsets()
{
$this->do_select(
__('Force Subsets (Pro)', $this->plugin_text_domain),
'omgf_pro_force_subsets',
OMGF_Admin_Settings::OMGF_FORCE_SUBSETS_OPTIONS,
defined('OMGF_PRO_FORCE_SUBSETS') ? OMGF_PRO_FORCE_SUBSETS : [],
__('If a theme or plugin loads subsets you don\'t need, use this option to force all Google Fonts to be loaded in the selected subsets. You can also use this option to force the loading of additional subsets, if a theme/plugin doesn\'t allow you to configure the loaded subsets. <em>Use CTRL + click to select multiple values</em>.', $this->plugin_text_domain) . ' ' . $this->promo,
true,
true
);
}
/**
*
*/
public function do_optimize_fonts_container()
{
?>
<div class="omgf-optimize-fonts-container welcome-panel">
<?php
}
/**
*
*/
public function do_optimize_fonts_contents()
{
$this->optimized_fonts = OMGF::optimized_fonts();
?>
<span class="option-title"><?= __('Manage Optimized Fonts', $this->plugin_text_domain); ?></span>
<?php if ($this->optimized_fonts) : ?>
<?= $this->do_optimized_fonts_manager(); ?>
<?php else : ?>
<div class="omgf-optimize-fonts-description">
<?php
$this->do_manual_template();
$this->do_automatic_template();
?>
</div>
<?php endif;
}
/**
*
*/
private function do_optimized_fonts_manager()
{
?>
<div class="omgf-optimize-fonts-manage">
<p>
</p>
<table>
<thead>
<tr>
<td>&nbsp;</td>
<th><?= __('Style', $this->plugin_text_domain); ?></th>
<th><?= __('Weight', $this->plugin_text_domain); ?></th>
<th><?= __('Preload', $this->plugin_text_domain); ?><span class="dashicons dashicons-info tooltip"><span class="tooltip-text"><span class="inline-text"><?= __('Preload font files (before everything else) so they will be available as soon as they are required for the rendering of the page. Only use preload for font files that are used above the fold.', $this->plugin_text_domain); ?></span><img width="230" class="illustration" src="<?= plugin_dir_url(OMGF_PLUGIN_FILE) . 'assets/images/above-the-fold.png'; ?>" /></span></span></th>
<th><?= __('Do not load', $this->plugin_text_domain); ?></th>
<th><?= __('Fallback Font Stack (Pro)', $this->plugin_text_domain); ?></th>
</tr>
</thead>
<?php
$cache_handles = OMGF::cache_keys();
?>
<?php foreach ($this->optimized_fonts as $handle => $fonts) : ?>
<?php
if (!OMGF::get_cache_key($handle)) {
$cache_handles[] = $handle;
}
?>
<tbody class="stylesheet" id="<?= $handle; ?>">
<tr>
<th colspan="6"><?= sprintf(__('Stylesheet handle: %s', $this->plugin_text_domain), $handle); ?></th>
</tr>
<?php foreach ($fonts as $font) : ?>
<?php if (!is_object($font) || count((array) $font->variants) <= 0) continue; ?>
<?php
$aka = in_array($font->id, OMGF_API_Download::OMGF_RENAMED_GOOGLE_FONTS) ? array_search($font->id, OMGF_API_Download::OMGF_RENAMED_GOOGLE_FONTS) : '';
?>
<tr class="font-family" data-id="<?= $handle . '-' . $font->id; ?>">
<td colspan="5">
<span class="family"><em><?= rawurldecode($font->family); ?><?= $aka ? ' (' . sprintf(__('formerly known as <strong>%s</strong>', $this->plugin_text_domain) . ')', ucfirst($aka)) : ''; ?></em></span> <span class="unload-mass-action">(<a href="#" class="unload-italics"><?= __('Unload italics', $this->plugin_text_domain); ?></a> <span class="dashicons dashicons-info tooltip"><span class="tooltip-text"><?= __('In most situations you can safely unload all Italic font styles. Modern browsers are capable of mimicking Italic font styles.', $this->plugin_text_domain); ?></span></span> | <a href="#" class="unload-all"><?= __('Unload all', $this->plugin_text_domain); ?></a> | <a href="#" class="load-all"><?= __('Load all', $this->plugin_text_domain); ?></a>)</span>
</td>
<td class="fallback-font-stack">
<select data-handle="<?= $handle; ?>" <?= apply_filters('omgf_pro_fallback_font_stack_setting_disabled', true) ? 'disabled' : ''; ?> name="omgf_pro_fallback_font_stack[<?= $handle; ?>][<?= $font->id; ?>]">
<option value=''><?= __('None (default)', $this->plugin_text_domain); ?></option>
<?php foreach (OMGF_Admin_Settings::OMGF_FALLBACK_FONT_STACKS_OPTIONS as $value => $label) : ?>
<option <?= defined('OMGF_PRO_FALLBACK_FONT_STACK') && isset(OMGF_PRO_FALLBACK_FONT_STACK[$handle][$font->id]) && OMGF_PRO_FALLBACK_FONT_STACK[$handle][$font->id] == $value ? 'selected' : ''; ?> value="<?= $value; ?>"><?= $label; ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php foreach ($font->variants as $variant) : ?>
<tr>
<td></td>
<?php
$preload = OMGF::preloaded_fonts()[$handle][$font->id][$variant->id] ?? '';
$unload = OMGF::unloaded_fonts()[$handle][$font->id][$variant->id] ?? '';
$class = $handle . '-' . $font->id . '-' . $variant->id;
?>
<td><?= $variant->fontStyle; ?></td>
<td><?= $variant->fontWeight; ?></td>
<td class="preload-<?= $class; ?>">
<input data-handle="<?= $handle; ?>" data-font-id="<?= $handle . '-' . $font->id; ?>" autocomplete="off" type="checkbox" class="preload" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_PRELOAD_FONTS; ?>[<?= $handle; ?>][<?= $font->id; ?>][<?= $variant->id; ?>]" value="<?= $variant->id; ?>" <?= $preload ? 'checked="checked"' : ''; ?> <?= $unload ? 'disabled' : ''; ?> />
</td>
<td class="unload-<?= $class; ?>">
<input data-handle="<?= $handle; ?>" data-font-id="<?= $handle . '-' . $font->id; ?>" autocomplete="off" type="checkbox" class="unload" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_FONTS; ?>[<?= $handle; ?>][<?= $font->id; ?>][<?= $variant->id; ?>]" value="<?= $variant->id; ?>" <?= $unload ? 'checked="checked"' : ''; ?> <?= $preload ? 'disabled' : ''; ?> />
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
<?php endforeach; ?>
</table>
<div class="omgf-optimize-fonts-tooltip">
<p>
<span class="dashicons-before dashicons-info-outline"></span>
<?php if (OMGF_OPTIMIZATION_MODE == 'manual') : ?>
<em><?= sprintf(__("This list is populated with all Google Fonts captured and downloaded from <strong>%s</strong>. Optimizations will be applied on every page using these fonts. If you want to optimize additional Google Fonts from other pages, switch to <strong>Automatic (Pro)</strong> and visit the pages containing the stylesheets you'd like to optimize. This list will automatically be populated with the captured fonts.", $this->plugin_text_domain), OMGF_MANUAL_OPTIMIZE_URL); ?></em>
<?php else : ?>
<?php $no_cache_param = '?omgf_optimize=' . substr(md5(microtime()), rand(0, 26), 5); ?>
<em><?= sprintf(__("This list is automatically populated with Google Fonts captured throughout your entire site. Optimizations will be applied on every page using these fonts. <strong>Automatic</strong> mode might not work when a Full Page Cache plugin is activated. If this list is not being populated with Google Fonts, you could try to visit your frontend and append the following parameter to the URL: <strong>%s</strong>", $this->plugin_text_domain), $no_cache_param); ?></em>
<?php endif; ?>
</p>
</div>
<input type="hidden" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZED_FONTS; ?>" value='<?= serialize($this->optimized_fonts); ?>' />
<input type="hidden" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL; ?>" value="<?= OMGF_MANUAL_OPTIMIZE_URL; ?>" />
<input id="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS; ?>" type="hidden" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_UNLOAD_STYLESHEETS; ?>" value="<?= OMGF_UNLOAD_STYLESHEETS; ?>" />
<input id="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_CACHE_KEYS; ?>" type="hidden" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_CACHE_KEYS; ?>" value="<?= implode(',', $cache_handles); ?>" />
</div>
<?php
}
/**
*
*/
public function do_manual_template()
{
?>
<div class="omgf-optimize-fonts-manual" <?= OMGF_OPTIMIZATION_MODE == 'manual' ? '' : 'style="display: none;"'; ?>>
<p>
<?= sprintf(__("You've chosen to <strong>optimize your Google Fonts manually</strong>. OMGF will <u>not</u> run automatically and will <strong>%s</strong> the requested Google Fonts throughout your website that were captured on the post/page you defined. A Cross-Browser compatible stylesheet will be generated for all requested Google Fonts.", $this->plugin_text_domain), OMGF_FONT_PROCESSING); ?>
</p>
<div class="omgf-optimize-fonts-pros">
<h3>
<span class="dashicons-before dashicons-yes"></span> <?= __('Pros:', $this->plugin_text_domain); ?>
</h3>
<ul>
<li><?= __('A small initial performance boost, because no calls to OMGF\'s Download API are made in the frontend.', $this->plugin_text_domain); ?></li>
<li><?= __('Force one stylesheet to be used throughout the site.', $this->plugin_text_domain); ?></li>
</ul>
</div>
<div class="omgf-optimize-fonts-cons">
<h3>
<span class="dashicons-before dashicons-no"></span> <?= __('Cons', $this->plugin_text_domain); ?>
</h3>
<ul>
<li><?= __('A font that is only used on a few pages might be lost if one of those URLs isn\'t scanned for fonts.', $this->plugin_text_domain); ?></li>
</ul>
</div>
<p>
<?= __('Enter the URL of the post/page you\'d like to scan for Google Fonts. The detected and optimized stylesheets will be applied on all pages where they\'re used.', $this->plugin_text_domain); ?>
</p>
<label for="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL; ?>">
<?= __('URL to Scan', $this->plugin_text_domain); ?>
<input id="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_MANUAL_OPTIMIZE_URL; ?>" value="<?= OMGF_MANUAL_OPTIMIZE_URL; ?>" />
</label>
<div class="omgf-optimize-fonts-tooltip">
<p>
<span class="dashicons-before dashicons-info-outline"></span>
<em><?= __('This section will be populated with all captured fonts, font styles and available options after saving changes.', $this->plugin_text_domain); ?></em>
</p>
</div>
</div>
<?php
}
/**
*
*/
public function do_automatic_template()
{
?>
<div class="omgf-optimize-fonts-automatic" <?= OMGF_OPTIMIZATION_MODE == 'auto' ? '' : 'style="display: none;"'; ?>>
<p>
<?= sprintf(__("You've chosen to <strong>optimize your Google Fonts automatically</strong>. OMGF will run silently in the background and <strong>%s</strong> all requested Google Fonts. If the captured stylesheet doesn't exist yet, a call is sent to OMGF's Download API to download the font files and generate a Cross-Browser compatible stylesheet.", $this->plugin_text_domain), OMGF_FONT_PROCESSING); ?>
</p>
<div class="omgf-optimize-fonts-pros">
<h3>
<span class="dashicons-before dashicons-yes"></span> <?= __('Pros:', $this->plugin_text_domain); ?>
</h3>
<ul>
<li><?= __('No maintenance.', $this->plugin_text_domain); ?></li>
</ul>
</div>
<div class="omgf-optimize-fonts-cons">
<h3>
<span class="dashicons-before dashicons-no"></span> <?= __('Cons', $this->plugin_text_domain); ?>
</h3>
<ul>
<li><?= __("The first time an unoptimized Google Fonts stylesheet is found, the API will be triggered in the frontend, which might cause the page to load slower than usual. All subsequent pageviews for that page (and all pages using that same stylesheet will load just as fast as when Manual mode is used.", $this->plugin_text_domain); ?></li>
</ul>
</div>
<div class="omgf-optimize-fonts-tooltip">
<p>
<span class="dashicons-before dashicons-info-outline"></span>
<em><?= __("After saving your changes, this section will be populated with all captured fonts, font styles and available options as your site's frontend is visited by you or others. You will be able to manage your fonts at a later point.", $this->plugin_text_domain); ?></em>
</p>
</div>
</div>
<?php
}
/**
*
*/
public function close_optimize_fonts_container()
{
?>
</div>
<?php
}
/**
*
*/
public function do_optimize_edit_roles()
{
$this->do_checkbox(
__('Optimize Fonts For Editors/Administrators?', $this->plugin_text_domain),
OMGF_Admin_Settings::OMGF_OPTIMIZE_SETTING_OPTIMIZE_EDIT_ROLES,
OMGF_OPTIMIZE_EDIT_ROLES,
__('Should only be disabled while debugging/testing, e.g. using a page builder or switching themes.', $this->plugin_text_domain)
);
}
}