OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy. - Version 4.1.0

Version Description

  • Added some on-boarding to ease the use of the new interface.
    • OMGF will now show a notice in the admin area, if the optimization never ran, to increase UX.
    • Added a loader when any of the following actions are triggered:
    • Empty Cache Directory
    • Start Optimization
  • Minor tweaks and optimizations.
Download this release

Release Info

Developer DaanvandenBergh
Plugin Icon 128x128 OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy.
Version 4.1.0
Comparing to
See all releases

Code changes from version 4.0.2 to 4.1.0

assets/css/omgf-admin.css CHANGED
@@ -80,6 +80,24 @@
80
  #omgf-welcome-panel .signature-image {
81
  max-width: 90%;
82
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  /**
84
  * Responsiveness
85
  */
80
  #omgf-welcome-panel .signature-image {
81
  max-width: 90%;
82
  }
83
+ /**
84
+ * Loader
85
+ */
86
+ .omgf-loading {
87
+ position: fixed;
88
+ background-color: rgba(255, 255, 255, 0.6);
89
+ width: 100%;
90
+ height: 100%;
91
+ top: 0;
92
+ text-align: center;
93
+ }
94
+ .omgf-loading .spinner {
95
+ top: 50%;
96
+ left: 50%;
97
+ position: absolute;
98
+ -ms-transform: translate(0, -70%);
99
+ transform: translate(0, -70%);
100
+ }
101
  /**
102
  * Responsiveness
103
  */
assets/css/omgf-admin.css.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["omgf-admin.less"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAkBA,KACE;EACE,WAAA;EACA,qBAAA;EACA,yBAAA;EACA,gBAAA;EACA,eAAA;EACA,kBAAA;EACA,mBAAA;EACA,4BAAA;;AAEA,KAVF,eAUG;EACC,eAAA;EACA,mBAAA;EACA,WAAA;EACA,qBAAA;;;;;AAQN;EACE,oBAAA;;AADF,SAGE;EACE,eAAA;;AAJJ,SAOE,kBAAiB;EACf,oBAAA;EACA,mBAAA;;;;;AAQF,gBAAC;EACC,WAAA;EACA,UAAA;;AAGF,gBAAC;EACC,YAAA;EACA,aAAA;;;;;AAOJ;EACE,sBAAA;;AADF,mBAGE;EACE,cAAA;EACA,eAAA;;AALJ,mBAQE,GAAG;EACD,gBAAA;;AAIA,mBADF,WACG,WAAW;EACV,cAAA;;AAdN,mBAkBE,cAAa;EACX,UAAA;;AAnBJ,mBAsBE;EACE,kBAAA;;AAvBJ,mBA0BE;EACE,cAAA;;;;;AAOJ,wBAA2C;EACzC;IACE,cAAA;IACA,WAAA;;EAEA,gBAAC;EACD,gBAAC;IACC,WAAA","file":"omgf-admin.css"}
1
+ {"version":3,"sources":["omgf-admin.less"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAkBA,KACE;EACE,WAAA;EACA,qBAAA;EACA,yBAAA;EACA,gBAAA;EACA,eAAA;EACA,kBAAA;EACA,mBAAA;EACA,4BAAA;;AAEA,KAVF,eAUG;EACC,eAAA;EACA,mBAAA;EACA,WAAA;EACA,qBAAA;;;;;AAQN;EACE,oBAAA;;AADF,SAGE;EACE,eAAA;;AAJJ,SAOE,kBAAiB;EACf,oBAAA;EACA,mBAAA;;;;;AAQF,gBAAC;EACC,WAAA;EACA,UAAA;;AAGF,gBAAC;EACC,YAAA;EACA,aAAA;;;;;AAOJ;EACE,sBAAA;;AADF,mBAGE;EACE,cAAA;EACA,eAAA;;AALJ,mBAQE,GAAG;EACD,gBAAA;;AAIA,mBADF,WACG,WAAW;EACV,cAAA;;AAdN,mBAkBE,cAAa;EACX,UAAA;;AAnBJ,mBAsBE;EACE,kBAAA;;AAvBJ,mBA0BE;EACE,cAAA;;;;;AAOJ;EACE,eAAA;EACA,0CAAA;EACA,WAAA;EACA,YAAA;EACA,MAAA;EACA,kBAAA;;AANF,aAQE;EACE,QAAA;EACA,SAAA;EACA,kBAAA;EACA,eAAe,kBAAf;EACA,WAAW,kBAAX;;;;;AAOJ,wBAA2C;EACzC;IACE,cAAA;IACA,WAAA;;EAEA,gBAAC;EACD,gBAAC;IACC,WAAA","file":"omgf-admin.css"}
assets/css/omgf-admin.less CHANGED
@@ -101,6 +101,26 @@
101
  }
102
  }
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  /**
105
  * Responsiveness
106
  */
101
  }
102
  }
103
 
104
+ /**
105
+ * Loader
106
+ */
107
+ .omgf-loading {
108
+ position: fixed;
109
+ background-color: rgba(255,255,255,0.6);
110
+ width: 100%;
111
+ height: 100%;
112
+ top: 0;
113
+ text-align: center;
114
+
115
+ .spinner {
116
+ top: 50%;
117
+ left: 50%;
118
+ position: absolute;
119
+ -ms-transform: translate(0, -70%);
120
+ transform: translate(0, -70%);
121
+ }
122
+ }
123
+
124
  /**
125
  * Responsiveness
126
  */
assets/css/omgf-admin.min.css CHANGED
@@ -1 +1 @@
1
- .omgf .button-cancel{color:#a00;text-decoration:none;border-color:transparent;box-shadow:none;background:0 0;border-radius:3px;white-space:nowrap;padding:1px 10px!important}.omgf .button-cancel:hover{cursor:pointer;background:#d54e21;color:#fff;border-color:#d54e21}.omgf-nav{padding:1em 0 1.5em}.omgf-nav a{cursor:pointer}.omgf-nav .dashicons-before:before{margin-right:.25em;line-height:1.15em}.settings-column.left{float:left;width:66%}.settings-column.right{float:right;width:21.75%}#omgf-welcome-panel{padding:20px 10px 5px}#omgf-welcome-panel .welcome-panel-content{margin-left:0;padding:0 15px}#omgf-welcome-panel h3>.dashicons{line-height:1.4}#omgf-welcome-panel .dashicons.ffwp-heart:before{color:#ff4136}#omgf-welcome-panel .welcome-icon:before{padding:0}#omgf-welcome-panel .signature{text-align:center}#omgf-welcome-panel .signature-image{max-width:90%}@media only screen and (max-width:1024px){.settings-column{display:block;float:none}.settings-column.left,.settings-column.right{width:100%}}
1
+ .omgf .button-cancel{color:#a00;text-decoration:none;border-color:transparent;box-shadow:none;background:0 0;border-radius:3px;white-space:nowrap;padding:1px 10px!important}.omgf .button-cancel:hover{cursor:pointer;background:#d54e21;color:#fff;border-color:#d54e21}.omgf-nav{padding:1em 0 1.5em}.omgf-nav a{cursor:pointer}.omgf-nav .dashicons-before:before{margin-right:.25em;line-height:1.15em}.settings-column.left{float:left;width:66%}.settings-column.right{float:right;width:21.75%}#omgf-welcome-panel{padding:20px 10px 5px}#omgf-welcome-panel .welcome-panel-content{margin-left:0;padding:0 15px}#omgf-welcome-panel h3>.dashicons{line-height:1.4}#omgf-welcome-panel .dashicons.ffwp-heart:before{color:#ff4136}#omgf-welcome-panel .welcome-icon:before{padding:0}#omgf-welcome-panel .signature,.omgf-loading{text-align:center}#omgf-welcome-panel .signature-image{max-width:90%}.omgf-loading{position:fixed;background-color:rgba(255,255,255,.6);width:100%;height:100%;top:0}.omgf-loading .spinner{top:50%;left:50%;position:absolute;-ms-transform:translate(0,-70%);transform:translate(0,-70%)}@media only screen and (max-width:1024px){.settings-column{display:block;float:none}.settings-column.left,.settings-column.right{width:100%}}
assets/js/omgf-admin.js CHANGED
@@ -16,6 +16,7 @@
16
  jQuery(document).ready(function ($) {
17
  var omgf_admin = {
18
  empty_cache_directory_xhr: false,
 
19
 
20
  /**
21
  * Initialize all on click events.
@@ -23,6 +24,7 @@ jQuery(document).ready(function ($) {
23
  init: function () {
24
  // Buttons
25
  $('.omgf-empty').on('click', this.empty_cache_directory);
 
26
  },
27
 
28
  /**
@@ -39,11 +41,49 @@ jQuery(document).ready(function ($) {
39
  data: {
40
  action: 'omgf_ajax_empty_dir'
41
  },
 
 
 
42
  complete: function() {
43
  location.reload();
44
  }
45
  });
46
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  };
48
 
49
  omgf_admin.init();
16
  jQuery(document).ready(function ($) {
17
  var omgf_admin = {
18
  empty_cache_directory_xhr: false,
19
+ optimize_xhr: false,
20
 
21
  /**
22
  * Initialize all on click events.
24
  init: function () {
25
  // Buttons
26
  $('.omgf-empty').on('click', this.empty_cache_directory);
27
+ $('#omgf-optimize').on('click', this.optimize);
28
  },
29
 
30
  /**
41
  data: {
42
  action: 'omgf_ajax_empty_dir'
43
  },
44
+ beforeSend: function () {
45
+ omgf_admin.show_loader();
46
+ },
47
  complete: function() {
48
  location.reload();
49
  }
50
  });
51
  },
52
+
53
+ /**
54
+ *
55
+ */
56
+ optimize: function () {
57
+ if (omgf_admin.optimize_xhr) {
58
+ omgf_admin.optimize_xhr.abort();
59
+ }
60
+
61
+ omgf_admin.optimize_xhr = $.ajax({
62
+ type: 'GET',
63
+ url: ajaxurl,
64
+ data: {
65
+ action: 'omgf_ajax_optimize'
66
+ },
67
+ beforeSend: function() {
68
+ omgf_admin.show_loader();
69
+ },
70
+ complete: function() {
71
+ $('.omgf-loading').html('<span>All done!</span>');
72
+
73
+ setTimeout(
74
+ location.reload(),
75
+ 3000
76
+ )
77
+ }
78
+ });
79
+ },
80
+
81
+ /**
82
+ *
83
+ */
84
+ show_loader: function () {
85
+ $('#wpcontent').append('<div class="omgf-loading"><span class="spinner is-active"></span></div>');
86
+ }
87
  };
88
 
89
  omgf_admin.init();
host-webfonts-local.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: OMGF
5
  * Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
6
  * Description: Minimize DNS requests and leverage browser cache by automatically saving Google Fonts to your server and removing the external Google Fonts.
7
- * Version: 4.0.2
8
  * Author: Daan (from Fast FW Press)
9
  * Author URI: https://ffwp.dev
10
  * License: GPL2v2 or later
4
  * Plugin Name: OMGF
5
  * Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
6
  * Description: Minimize DNS requests and leverage browser cache by automatically saving Google Fonts to your server and removing the external Google Fonts.
7
+ * Version: 4.1.0
8
  * Author: Daan (from Fast FW Press)
9
  * Author URI: https://ffwp.dev
10
  * License: GPL2v2 or later
includes/admin/class-notice.php CHANGED
@@ -31,9 +31,9 @@ class OMGF_Admin_Notice
31
  * @param bool $json
32
  * @param int $code
33
  */
34
- public static function set_notice ( $message, $die = true, $type = 'success', $code = 200, $screen_id = 'all' ) {
35
  self::$notices = get_transient( self::OMGF_ADMIN_NOTICE_TRANSIENT );
36
- self::$notices[ $screen_id ][ $type ][] = $message;
37
 
38
  set_transient( self::OMGF_ADMIN_NOTICE_TRANSIENT, self::$notices, self::OMGF_ADMIN_NOTICE_EXPIRATION );
39
 
31
  * @param bool $json
32
  * @param int $code
33
  */
34
+ public static function set_notice ( $message, $message_id = '', $die = true, $type = 'success', $code = 200, $screen_id = 'all' ) {
35
  self::$notices = get_transient( self::OMGF_ADMIN_NOTICE_TRANSIENT );
36
+ self::$notices[ $screen_id ][ $type ][ $message_id ] = $message;
37
 
38
  set_transient( self::OMGF_ADMIN_NOTICE_TRANSIENT, self::$notices, self::OMGF_ADMIN_NOTICE_EXPIRATION );
39
 
includes/admin/class-settings.php CHANGED
@@ -18,11 +18,13 @@ defined( 'ABSPATH' ) || exit;
18
 
19
  class OMGF_Admin_Settings extends OMGF_Admin
20
  {
 
 
21
  /**
22
  * Settings Fields
23
  */
24
- const OMGF_SETTINGS_FIELD_BASIC = 'omgf-basic-settings';
25
- const OMGF_SETTINGS_FIELD_ADVANCED = 'omgf-advanced-settings';
26
 
27
  /**
28
  * Option Values
@@ -69,6 +71,11 @@ class OMGF_Admin_Settings extends OMGF_Admin
69
  'vietnamese' => 'Vietnamese'
70
  ];
71
 
 
 
 
 
 
72
  /**
73
  * Basic Settings
74
  */
@@ -80,10 +87,10 @@ class OMGF_Admin_Settings extends OMGF_Admin
80
  /**
81
  * Advanced Settings
82
  */
83
- const OMGF_ADV_SETTING_CACHE_URI = 'omgf_cache_uri';
84
- const OMGF_ADV_SETTING_CDN_URL = 'omgf_cdn_url';
85
- const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
86
- const OMGF_ADV_SETTING_RELATIVE_URL = 'omgf_relative_url';
87
 
88
  /** @var string $active_tab */
89
  private $active_tab;
@@ -273,7 +280,7 @@ class OMGF_Admin_Settings extends OMGF_Admin
273
  return;
274
  }
275
  ?>
276
- <form id="<?= $field; ?>-form" name="omgf-settings-form" method="post" action="<?= admin_url('options.php?tab=' . $this->active_tab); ?>">
277
  <?php
278
  settings_fields( $field );
279
  do_settings_sections( $field );
@@ -284,9 +291,9 @@ class OMGF_Admin_Settings extends OMGF_Admin
284
 
285
  do_action( 'omgf_after_settings_form_settings' );
286
 
287
- submit_button(__('Save Changes', $this->plugin_text_domain), 'primary', 'submit', false);
288
  ?>
289
- <a id="omgf-empty" class="omgf-empty button-cancel"><?php _e('Empty Cache Directory', $this->plugin_text_domain); ?></a>
290
  </form>
291
  <?php
292
  }
18
 
19
  class OMGF_Admin_Settings extends OMGF_Admin
20
  {
21
+ const FFWP_WORDPRESS_PLUGINS_OMGF_PRO = 'https://ffwp.dev/wordpress/omgf-pro/';
22
+
23
  /**
24
  * Settings Fields
25
  */
26
+ const OMGF_SETTINGS_FIELD_BASIC = 'omgf-basic-settings';
27
+ const OMGF_SETTINGS_FIELD_ADVANCED = 'omgf-advanced-settings';
28
 
29
  /**
30
  * Option Values
71
  'vietnamese' => 'Vietnamese'
72
  ];
73
 
74
+ /**
75
+ *
76
+ */
77
+ const OMGF_OPTIMIZATION_COMPLETE = 'omgf_optimization_complete';
78
+
79
  /**
80
  * Basic Settings
81
  */
87
  /**
88
  * Advanced Settings
89
  */
90
+ const OMGF_ADV_SETTING_CACHE_URI = 'omgf_cache_uri';
91
+ const OMGF_ADV_SETTING_CDN_URL = 'omgf_cdn_url';
92
+ const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
93
+ const OMGF_ADV_SETTING_RELATIVE_URL = 'omgf_relative_url';
94
 
95
  /** @var string $active_tab */
96
  private $active_tab;
280
  return;
281
  }
282
  ?>
283
+ <form id="<?= $field; ?>-form" name="omgf-settings-form" method="post" action="<?= admin_url( 'options.php?tab=' . $this->active_tab ); ?>">
284
  <?php
285
  settings_fields( $field );
286
  do_settings_sections( $field );
291
 
292
  do_action( 'omgf_after_settings_form_settings' );
293
 
294
+ submit_button( __( 'Save Changes', $this->plugin_text_domain ), 'primary', 'submit', false );
295
  ?>
296
+ <a id="omgf-empty" class="omgf-empty button-cancel"><?php _e( 'Empty Cache Directory', $this->plugin_text_domain ); ?></a>
297
  </form>
298
  <?php
299
  }
includes/admin/settings/class-basic.php CHANGED
@@ -63,7 +63,7 @@ class OMGF_Admin_Settings_Basic extends OMGF_Admin_Settings_Builder
63
  OMGF_Admin_Settings::OMGF_BASIC_SETTING_FONT_PROCESSING,
64
  OMGF_Admin_Settings::OMGF_FONT_PROCESSING_OPTIONS,
65
  OMGF_FONT_PROCESSING,
66
- 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 or install your own.", $this->plugin_text_domain ), self::FFWP_WORDPRESS_PLUGINS_OMGF_PRO )
67
  );
68
  }
69
 
63
  OMGF_Admin_Settings::OMGF_BASIC_SETTING_FONT_PROCESSING,
64
  OMGF_Admin_Settings::OMGF_FONT_PROCESSING_OPTIONS,
65
  OMGF_FONT_PROCESSING,
66
+ 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 or install your own.", $this->plugin_text_domain ), OMGF_Admin_Settings::FFWP_WORDPRESS_PLUGINS_OMGF_PRO )
67
  );
68
  }
69
 
includes/admin/settings/class-builder.php CHANGED
@@ -18,8 +18,6 @@ defined( 'ABSPATH' ) || exit;
18
 
19
  class OMGF_Admin_Settings_Builder
20
  {
21
- const FFWP_WORDPRESS_PLUGINS_OMGF_PRO = 'https://ffwp.dev/wordpress/omgf-pro/';
22
-
23
  /** @var string $plugin_text_domain */
24
  protected $plugin_text_domain = 'host-webfonts-local';
25
 
@@ -44,7 +42,7 @@ class OMGF_Admin_Settings_Builder
44
  */
45
  public function do_promo () {
46
  if (apply_filters('apply_omgf_pro_promo', true)) {
47
- $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), self::FFWP_WORDPRESS_PLUGINS_OMGF_PRO));
48
  }
49
  }
50
 
18
 
19
  class OMGF_Admin_Settings_Builder
20
  {
 
 
21
  /** @var string $plugin_text_domain */
22
  protected $plugin_text_domain = 'host-webfonts-local';
23
 
42
  */
43
  public function do_promo () {
44
  if (apply_filters('apply_omgf_pro_promo', true)) {
45
+ $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 ));
46
  }
47
  }
48
 
includes/class-admin.php CHANGED
@@ -46,6 +46,7 @@ class OMGF_Admin
46
 
47
  $this->do_basic_settings();
48
  $this->do_advanced_settings();
 
49
 
50
  add_filter( 'pre_update_option', [ $this, 'settings_changed' ], 10, 3 );
51
  }
@@ -56,10 +57,8 @@ class OMGF_Admin
56
  * @param $hook
57
  */
58
  public function enqueue_admin_scripts ( $hook ) {
59
- if ( $hook == 'settings_page_optimize-webfonts' ) {
60
- wp_enqueue_script( self::OMGF_ADMIN_JS_HANDLE, plugin_dir_url( OMGF_PLUGIN_FILE ) . 'assets/js/omgf-admin.js', [ 'jquery' ], OMGF_STATIC_VERSION, true );
61
- wp_enqueue_style( self::OMGF_ADMIN_CSS_HANDLE, plugin_dir_url( OMGF_PLUGIN_FILE ) . 'assets/css/omgf-admin.css', [], OMGF_STATIC_VERSION );
62
- }
63
  }
64
 
65
  /**
@@ -105,11 +104,27 @@ class OMGF_Admin
105
 
106
  if ( $value != $old_value ) {
107
  OMGF_Admin_Notice::set_notice(
108
- __('Settings changed. <a href="#" class="omgf-empty">Click here</a> to flush OMGF\'s cache.', $this->plugin_text_domain),
 
109
  false
110
  );
111
  }
112
 
113
  return $value;
114
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
46
 
47
  $this->do_basic_settings();
48
  $this->do_advanced_settings();
49
+ $this->show_optimize_notice();
50
 
51
  add_filter( 'pre_update_option', [ $this, 'settings_changed' ], 10, 3 );
52
  }
57
  * @param $hook
58
  */
59
  public function enqueue_admin_scripts ( $hook ) {
60
+ wp_enqueue_script( self::OMGF_ADMIN_JS_HANDLE, plugin_dir_url( OMGF_PLUGIN_FILE ) . 'assets/js/omgf-admin.js', [ 'jquery' ], OMGF_STATIC_VERSION, true );
61
+ wp_enqueue_style( self::OMGF_ADMIN_CSS_HANDLE, plugin_dir_url( OMGF_PLUGIN_FILE ) . 'assets/css/omgf-admin.css', [], OMGF_STATIC_VERSION );
 
 
62
  }
63
 
64
  /**
104
 
105
  if ( $value != $old_value ) {
106
  OMGF_Admin_Notice::set_notice(
107
+ __('Settings changed. <a href="#" class="omgf-empty">Click here</a> to empty OMGF\'s cache.', $this->plugin_text_domain),
108
+ 'omgf-settings-changed',
109
  false
110
  );
111
  }
112
 
113
  return $value;
114
  }
115
+
116
+ /**
117
+ *
118
+ */
119
+ private function show_optimize_notice () {
120
+ if (get_option(OMGF_Admin_Settings::OMGF_OPTIMIZATION_COMPLETE)) {
121
+ return;
122
+ }
123
+
124
+ OMGF_Admin_Notice::set_notice(
125
+ __('OMGF is ready to optimize your Google Fonts. <a href="#" id="omgf-optimize">Start optimization</a>.', $this->plugin_text_domain),
126
+ 'omgf-optimize',
127
+ false
128
+ );
129
+ }
130
  }
includes/class-ajax.php CHANGED
@@ -26,6 +26,7 @@ class OMGF_AJAX
26
  */
27
  public function __construct () {
28
  add_action( 'wp_ajax_omgf_ajax_empty_dir', [ $this, 'empty_directory' ] );
 
29
  }
30
 
31
  /**
@@ -39,10 +40,13 @@ class OMGF_AJAX
39
  $this->delete( $entry );
40
  }
41
 
 
 
42
  OMGF_Admin_Notice::set_notice( __( 'Cache directory successfully emptied.', $this->plugin_text_domain ) );
43
  } catch ( \Exception $e ) {
44
  OMGF_Admin_Notice::set_notice(
45
  __( 'Something went wrong while emptying the cache directory: ', $this->plugin_text_domain ) . $e->getMessage(),
 
46
  true,
47
  'error',
48
  $e->getCode()
@@ -68,4 +72,92 @@ class OMGF_AJAX
68
  unlink( $entry );
69
  }
70
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
26
  */
27
  public function __construct () {
28
  add_action( 'wp_ajax_omgf_ajax_empty_dir', [ $this, 'empty_directory' ] );
29
+ add_action( 'wp_ajax_omgf_ajax_optimize', [ $this, 'optimize' ] );
30
  }
31
 
32
  /**
40
  $this->delete( $entry );
41
  }
42
 
43
+ update_option( OMGF_Admin_Settings::OMGF_OPTIMIZATION_COMPLETE, false );
44
+
45
  OMGF_Admin_Notice::set_notice( __( 'Cache directory successfully emptied.', $this->plugin_text_domain ) );
46
  } catch ( \Exception $e ) {
47
  OMGF_Admin_Notice::set_notice(
48
  __( 'Something went wrong while emptying the cache directory: ', $this->plugin_text_domain ) . $e->getMessage(),
49
+ 'omgf-cache-error',
50
  true,
51
  'error',
52
  $e->getCode()
72
  unlink( $entry );
73
  }
74
  }
75
+
76
+ /**
77
+ * Fetch Download API URLs from Frontend and go through them one by one, to trigger an uncached call to the Download API.
78
+ */
79
+ public function optimize () {
80
+ $front_html = wp_remote_get(
81
+ site_url(),
82
+ [
83
+ 'sslverify' => false,
84
+ 'timeout' => 10
85
+ ]
86
+ );
87
+
88
+ if ( is_wp_error( $front_html ) ) {
89
+ return;
90
+ }
91
+
92
+ $urls = [];
93
+ $document = new DOMDocument();
94
+ $document->loadHtml( wp_remote_retrieve_body( $front_html ) );
95
+
96
+ foreach ( $document->getElementsByTagName( 'link' ) as $link ) {
97
+ /** @var $link DOMElement */
98
+ if ( $link->hasAttribute( 'href' ) && strpos( $link->getAttribute( 'href' ), '/omgf/v1/download/css' ) ) {
99
+ $urls[] = $link->getAttribute( 'href' );
100
+ }
101
+ }
102
+
103
+ if ( empty( $urls ) ) {
104
+ $message = __( 'No Google Fonts found to optimize. <a href="#" class="omgf-empty">Empty the Cache Directory</a> to start over.', $this->plugin_text_domain );
105
+
106
+ if ( apply_filters( 'apply_omgf_pro_promo', true ) ) {
107
+ $message .= ' ' . sprintf( __( 'Or <a target="_blank" href="%s">Upgrade to OMGF Pro</a> to capture requests throughout the entire HTML document.', $this->plugin_text_domain ), OMGF_Admin_Settings::FFWP_WORDPRESS_PLUGINS_OMGF_PRO );
108
+ }
109
+
110
+ OMGF_Admin_Notice::set_notice(
111
+ $message,
112
+ 'omgf-fonts-not-found',
113
+ true,
114
+ 'error',
115
+ 404
116
+ );
117
+ }
118
+
119
+ foreach ( $urls as $url ) {
120
+ $download = wp_remote_get(
121
+ add_query_arg( [ 'nocache' => substr( md5( microtime() ), rand( 0, 26 ), 5 ) ], $url ),
122
+ [
123
+ 'sslverify' => false,
124
+ 'timeout' => 10
125
+ ]
126
+ );
127
+
128
+ if ( is_wp_error( $download ) ) {
129
+ update_option( 'omgf_optimization_complete', false );
130
+
131
+ OMGF_Admin_Notice::set_notice(
132
+ __( 'Something went wrong while downloading Google Fonts', $this->plugin_text_domain ) . ': ' . $download->get_error_message(),
133
+ 'omgf-download-failed',
134
+ true,
135
+ 'error',
136
+ $download->get_error_code()
137
+ );
138
+ }
139
+ }
140
+
141
+ update_option( OMGF_Admin_Settings::OMGF_OPTIMIZATION_COMPLETE, true );
142
+
143
+ OMGF_Admin_Notice::set_notice(
144
+ __( 'OMGF has finished optimizing your Google Fonts. Enjoy! :-)', $this->plugin_text_domain ),
145
+ 'omgf-optimize',
146
+ false,
147
+ );
148
+
149
+ OMGF_Admin_Notice::set_notice(
150
+ '<em>' . __( 'If you\'re using any CSS minify/combine and/or Full Page Caching plugins, don\'t forget to flush their caches.', $this->plugin_text_domain ) . '</em>',
151
+ 'omgf-optimize-plugin-notice',
152
+ false,
153
+ 'info'
154
+ );
155
+
156
+ OMGF_Admin_Notice::set_notice(
157
+ __( 'OMGF will keep running silently in the background and will generate additional stylesheets when other Google Fonts are found on any of your pages.', $this->plugin_text_domain ),
158
+ 'omgf-optimize-background',
159
+ true,
160
+ 'info'
161
+ );
162
+ }
163
  }
includes/class-omgf.php CHANGED
@@ -14,85 +14,80 @@
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
- defined('ABSPATH') || exit;
18
 
19
  class OMGF
20
  {
21
- /**
22
- * OMGF constructor.
23
- */
24
- public function __construct()
25
- {
26
- $this->define_constants();
27
-
28
- if (is_admin()) {
29
- $this->do_settings();
30
- $this->add_ajax_hooks();
31
- }
32
-
33
- if (!is_admin()) {
34
- $this->do_frontend();
35
- }
36
 
37
- add_action('rest_api_init', [$this, 'register_routes']);
38
- }
39
-
40
- /**
41
- * Define constants.
42
- */
43
- public function define_constants()
44
- {
45
- define('OMGF_SITE_URL', 'https://daan.dev');
46
- define('OMGF_FONT_PROCESSING', esc_attr(get_option(OMGF_Admin_Settings::OMGF_BASIC_SETTING_FONT_PROCESSING, 'replace')));
47
- define('OMGF_DISPLAY_OPTION', esc_attr(get_option( OMGF_Admin_Settings::OMGF_BASIC_SETTING_DISPLAY_OPTION, 'swap')) ?: 'swap');
48
- define('OMGF_OPTIMIZE_EDIT_ROLES', esc_attr(get_option( OMGF_Admin_Settings::OMGF_BASIC_SETTING_OPTIMIZE_EDIT_ROLES, 'on')));
49
- define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_BASIC_SETTING_CACHE_PATH)) ?: '/uploads/omgf');
50
- define('OMGF_CACHE_URI', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI)) ?: '');
51
- define('OMGF_RELATIVE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL)));
52
- define('OMGF_CDN_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL)));
53
- define('OMGF_FONTS_DIR', WP_CONTENT_DIR . OMGF_CACHE_PATH);
54
- define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL)));
55
- }
56
-
57
- /**
58
- * @return OMGF_Admin_Settings
59
- */
60
- private function do_settings()
61
- {
62
- return new OMGF_Admin_Settings();
63
- }
64
-
65
- /**
66
- * @return OMGF_AJAX
67
- */
68
- private function add_ajax_hooks()
69
- {
70
- return new OMGF_AJAX();
71
- }
72
-
73
- /**
74
- * @return OMGF_Frontend_Functions
75
- */
76
- public function do_frontend()
77
- {
78
- return new OMGF_Frontend_Functions();
79
- }
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  /**
82
  *
83
  */
84
- public function register_routes()
85
- {
86
  $proxy = new OMGF_API_Download();
87
  $proxy->register_routes();
88
  }
89
-
90
- /**
91
- * @return OMGF_Uninstall
92
- * @throws ReflectionException
93
- */
94
- public static function do_uninstall()
95
- {
96
- return new OMGF_Uninstall();
97
- }
98
  }
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
+ defined( 'ABSPATH' ) || exit;
18
 
19
  class OMGF
20
  {
21
+ private $plugin_text_domain = 'host-webfonts-local';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ /**
24
+ * OMGF constructor.
25
+ */
26
+ public function __construct () {
27
+ $this->define_constants();
28
+
29
+ if ( is_admin() ) {
30
+ $this->do_settings();
31
+ $this->add_ajax_hooks();
32
+ }
33
+
34
+ if ( ! is_admin() ) {
35
+ $this->do_frontend();
36
+ }
37
+
38
+ add_action( 'rest_api_init', [ $this, 'register_routes' ] );
39
+ }
40
+
41
+ /**
42
+ * Define constants.
43
+ */
44
+ public function define_constants () {
45
+ define( 'OMGF_SITE_URL', 'https://daan.dev' );
46
+ define( 'OMGF_FONT_PROCESSING', esc_attr( get_option( OMGF_Admin_Settings::OMGF_BASIC_SETTING_FONT_PROCESSING, 'replace' ) ) );
47
+ define( 'OMGF_DISPLAY_OPTION', esc_attr( get_option( OMGF_Admin_Settings::OMGF_BASIC_SETTING_DISPLAY_OPTION, 'swap' ) ) ?: 'swap' );
48
+ define( 'OMGF_OPTIMIZE_EDIT_ROLES', esc_attr( get_option( OMGF_Admin_Settings::OMGF_BASIC_SETTING_OPTIMIZE_EDIT_ROLES, 'on' ) ) );
49
+ define( 'OMGF_CACHE_PATH', esc_attr( get_option( OMGF_Admin_Settings::OMGF_BASIC_SETTING_CACHE_PATH ) ) ?: '/uploads/omgf' );
50
+ define( 'OMGF_CACHE_URI', esc_attr( get_option( OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI ) ) ?: '' );
51
+ define( 'OMGF_RELATIVE_URL', esc_attr( get_option( OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL ) ) );
52
+ define( 'OMGF_CDN_URL', esc_attr( get_option( OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL ) ) );
53
+ define( 'OMGF_FONTS_DIR', WP_CONTENT_DIR . OMGF_CACHE_PATH );
54
+ define( 'OMGF_UNINSTALL', esc_attr( get_option( OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL ) ) );
55
+ }
56
+
57
+ /**
58
+ * @return OMGF_Admin_Settings
59
+ */
60
+ private function do_settings () {
61
+ return new OMGF_Admin_Settings();
62
+ }
63
+
64
+ /**
65
+ * @return OMGF_AJAX
66
+ */
67
+ private function add_ajax_hooks () {
68
+ return new OMGF_AJAX();
69
+ }
70
+
71
+ /**
72
+ * @return OMGF_Frontend_Functions
73
+ */
74
+ public function do_frontend () {
75
+ return new OMGF_Frontend_Functions();
76
+ }
77
 
78
  /**
79
  *
80
  */
81
+ public function register_routes () {
 
82
  $proxy = new OMGF_API_Download();
83
  $proxy->register_routes();
84
  }
85
+
86
+ /**
87
+ * @return OMGF_Uninstall
88
+ * @throws ReflectionException
89
+ */
90
+ public static function do_uninstall () {
91
+ return new OMGF_Uninstall();
92
+ }
 
93
  }
includes/frontend/class-functions.php CHANGED
@@ -120,11 +120,4 @@ class OMGF_Frontend_Functions
120
  }
121
  );
122
  }
123
-
124
- /**
125
- * @param $name
126
- */
127
- public function get_template ( $name ) {
128
- include OMGF_PLUGIN_DIR . 'templates/frontend-' . $name . '.phtml';
129
- }
130
  }
120
  }
121
  );
122
  }
 
 
 
 
 
 
 
123
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: DaanvandenBergh
3
  Tags: google, fonts, gdpr, cache, speed, preload, font-display, webfonts, subsets, remove, minimize, external, requests
4
  Requires at least: 4.6
5
  Tested up to: 5.5
6
- Stable tag: 4.0.2
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -112,6 +112,14 @@ N/A
112
 
113
  == Changelog ==
114
 
 
 
 
 
 
 
 
 
115
  = 4.0.2 =
116
  * Fixed bug where OMGF would trigger too late for the requests to fonts.googleapis.com to be captured.
117
 
3
  Tags: google, fonts, gdpr, cache, speed, preload, font-display, webfonts, subsets, remove, minimize, external, requests
4
  Requires at least: 4.6
5
  Tested up to: 5.5
6
+ Stable tag: 4.1.0
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
112
 
113
  == Changelog ==
114
 
115
+ = 4.1.0 =
116
+ * Added some on-boarding to ease the use of the new interface.
117
+ * OMGF will now show a notice in the admin area, if the optimization never ran, to increase UX.
118
+ * Added a loader when any of the following actions are triggered:
119
+ * Empty Cache Directory
120
+ * Start Optimization
121
+ * Minor tweaks and optimizations.
122
+
123
  = 4.0.2 =
124
  * Fixed bug where OMGF would trigger too late for the requests to fonts.googleapis.com to be captured.
125
 
templates/admin/block-welcome.phtml CHANGED
@@ -72,7 +72,7 @@ $tweetUrl = 'https://twitter.com/intent/tweet?text=I+just+optimized+my
72
  <?= __('Click the button below and receive a unique discount code for 10% off your next purchase!'); ?>
73
  </p>
74
  <p>
75
- <a target="_blank" class="button button-primary button-hero" href="<?= OMGF_Admin_Settings_Builder::FFWP_WORDPRESS_PLUGINS_OMGF_PRO . '#edd-reviews-title'; ?>"><span class="dashicons-before dashicons-star-filled"> <?php _e('Review', $plugin_text_domain); ?></span></a>
76
  <span><?= __('(login required)', $plugin_text_domain); ?></span>
77
  </p>
78
  <?php endif; ?>
72
  <?= __('Click the button below and receive a unique discount code for 10% off your next purchase!'); ?>
73
  </p>
74
  <p>
75
+ <a target="_blank" class="button button-primary button-hero" href="<?= OMGF_Admin_Settings::FFWP_WORDPRESS_PLUGINS_OMGF_PRO . '#edd-reviews-title'; ?>"><span class="dashicons-before dashicons-star-filled"> <?php _e( 'Review', $plugin_text_domain); ?></span></a>
76
  <span><?= __('(login required)', $plugin_text_domain); ?></span>
77
  </p>
78
  <?php endif; ?>