Speed Booster Pack - Version 4.5.2

Version Description

Release Date: 14 May 2022

  • NEW: New option called "Dequeue global styles".
  • Improved: Lots of refactoring to the class-sbp-tweaks.php file.
  • Improved: Removed unused helper functions.
  • Fixed: Full site editing related bug squashed.
  • Fixed: HTML minifier did a lot more damage than it did good, so we replaced it with an external class from github.com/mrclay/minify.
  • Fixed: Hooked our public-faced features to init instead of template_redirect so it's more compatible with other plugins.
  • Fixed: Reverted the shutdown hook as it did more damage than good.
  • Fixed: The PHP version warning (shown to PHP 5.x users) is now dismissible.
Download this release

Release Info

Developer optimocha
Plugin Icon 128x128 Speed Booster Pack
Version 4.5.2
Comparing to
See all releases

Code changes from version 4.5.1.1 to 4.5.2

README.txt CHANGED
@@ -3,9 +3,9 @@ Plugin Name: Speed Booster Pack ⚡ PageSpeed Optimization Suite
3
  Contributors: optimocha, speedboosterpack
4
  Tags: speed, pagespeed, optimization, core web vitals, cache
5
  Requires at least: 4.6
6
- Tested up to: 5.9
7
  Requires PHP: 5.6
8
- Stable tag: 4.5.1.1
9
  License: GPLv3 or later
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
11
 
@@ -103,15 +103,28 @@ All the time! We're always looking for new ways to get this plugin to a better s
103
 
104
  == Changelog ==
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  = 4.5.1.1 =
107
 
108
- *Release Date: 24 April 2021*
109
 
110
  * **Fixed**: One more (tiny) fix to the deactivation survey.
111
 
112
  = 4.5.1 =
113
 
114
- *Release Date: 18 April 2021*
115
 
116
  * **NEW**: Simple warning notice about PHP version (when it's below 7.0).
117
  * **Fixed**: Deactivation survey didn't show the details textarea.
@@ -119,7 +132,7 @@ All the time! We're always looking for new ways to get this plugin to a better s
119
 
120
  = 4.5.0 =
121
 
122
- *Release Date: 14 April 2021*
123
 
124
  * **NEW - WooCommerce optimizations**: The "Special" tab is replaced with the "WooCommerce" tab with SEVEN WC-related optimizations, four of them brand new!
125
  * **NEW - Deactivation survey**: An optional survey added to the "Deactivate" button to get feedback from users leaving us, so we can improve SBP even further.
@@ -134,7 +147,7 @@ All the time! We're always looking for new ways to get this plugin to a better s
134
 
135
  = 4.4.1.1 =
136
 
137
- *Release Date: 12 March 2021*
138
 
139
  * **Improved**: Speed Booster Pack's wp-admin CSS file got a bit smaller.
140
  * **Improved**: Better onboarding with titles.
@@ -148,7 +161,7 @@ All the time! We're always looking for new ways to get this plugin to a better s
148
 
149
  = 4.4.0 =
150
 
151
- *Release Date: 05 February 2021*
152
 
153
  * **NEW - LiteSpeed Caching**: This experimental new feature connects to your LiteSpeed server and use LiteSpeed's caching structure. Since it's really new, be sure to test thoroughly and [kindly report any bugs to our GitHub page](https://github.com/optimocha/speed-booster-pack/issues/).
154
  * **Improved**: Better page caching by refactoring some of the code.
3
  Contributors: optimocha, speedboosterpack
4
  Tags: speed, pagespeed, optimization, core web vitals, cache
5
  Requires at least: 4.6
6
+ Tested up to: 6.0
7
  Requires PHP: 5.6
8
+ Stable tag: 4.5.2
9
  License: GPLv3 or later
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
11
 
103
 
104
  == Changelog ==
105
 
106
+ = 4.5.2 =
107
+
108
+ *Release Date: 14 May 2022*
109
+
110
+ * **NEW**: New option called "Dequeue global styles".
111
+ * **Improved**: Lots of refactoring to the `class-sbp-tweaks.php` file.
112
+ * **Improved**: Removed unused helper functions.
113
+ * **Fixed**: Full site editing related bug squashed.
114
+ * **Fixed**: HTML minifier did a lot more damage than it did good, so we replaced it with an external class from github.com/mrclay/minify.
115
+ * **Fixed**: Hooked our public-faced features to `init` instead of `template_redirect` so it's more compatible with other plugins.
116
+ * **Fixed**: Reverted the `shutdown` hook as it did more damage than good.
117
+ * **Fixed**: The PHP version warning (shown to PHP 5.x users) is now dismissible.
118
+
119
  = 4.5.1.1 =
120
 
121
+ *Release Date: 24 April 2022*
122
 
123
  * **Fixed**: One more (tiny) fix to the deactivation survey.
124
 
125
  = 4.5.1 =
126
 
127
+ *Release Date: 18 April 2022*
128
 
129
  * **NEW**: Simple warning notice about PHP version (when it's below 7.0).
130
  * **Fixed**: Deactivation survey didn't show the details textarea.
132
 
133
  = 4.5.0 =
134
 
135
+ *Release Date: 14 April 2022*
136
 
137
  * **NEW - WooCommerce optimizations**: The "Special" tab is replaced with the "WooCommerce" tab with SEVEN WC-related optimizations, four of them brand new!
138
  * **NEW - Deactivation survey**: An optional survey added to the "Deactivate" button to get feedback from users leaving us, so we can improve SBP even further.
147
 
148
  = 4.4.1.1 =
149
 
150
+ *Release Date: 12 March 2022*
151
 
152
  * **Improved**: Speed Booster Pack's wp-admin CSS file got a bit smaller.
153
  * **Improved**: Better onboarding with titles.
161
 
162
  = 4.4.0 =
163
 
164
+ *Release Date: 05 February 2022*
165
 
166
  * **NEW - LiteSpeed Caching**: This experimental new feature connects to your LiteSpeed server and use LiteSpeed's caching structure. Since it's really new, be sure to test thoroughly and [kindly report any bugs to our GitHub page](https://github.com/optimocha/speed-booster-pack/issues/).
167
  * **Improved**: Better page caching by refactoring some of the code.
admin/class-speed-booster-pack-admin.php CHANGED
@@ -13,6 +13,10 @@
13
  // If this file is called directly, abort.
14
  use SpeedBooster\SBP_Notice_Manager;
15
  use SpeedBooster\SBP_Utils;
 
 
 
 
16
 
17
  if ( ! defined( 'WPINC' ) ) {
18
  die;
@@ -113,6 +117,46 @@ class Speed_Booster_Pack_Admin {
113
  add_action( 'csf_loaded', [ $this, 'create_metaboxes' ] );
114
  }
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  /**
117
  * Register the stylesheets for the admin area.
118
  *
@@ -413,6 +457,14 @@ class Speed_Booster_Pack_Admin {
413
  'dependency' => [ 'module_tweaks', '==', '1', '', 'visible' ],
414
  'sanitize' => 'sbp_sanitize_boolean',
415
  ],
 
 
 
 
 
 
 
 
416
  [
417
  'title' => __( 'Heartbeat settings', 'speed-booster-pack' ),
418
  'id' => 'heartbeat_settings',
@@ -611,6 +663,7 @@ class Speed_Booster_Pack_Admin {
611
  'title' => __( 'Enable/Disable', 'speed-booster-pack' ) . ' ' . __( 'Caching', 'speed-booster-pack' ),
612
  'label' => __( 'Enables or disables the whole module without resetting its settings.', 'speed-booster-pack' ),
613
  'sanitize' => 'sbp_sanitize_boolean',
 
614
  ],
615
  [
616
  'title' => __( 'Cache expiry time', 'speed-booster-pack' ),
@@ -1462,7 +1515,7 @@ class Speed_Booster_Pack_Admin {
1462
  'title' => __( 'WooCommerce Marketing', 'speed-booster-pack' ),
1463
  'id' => 'woocommerce_marketing',
1464
  'type' => 'switcher',
1465
- 'desc' => __( 'Enable or disable WooCommerce marketing. Note that this will also disable coupons.', 'speed-booster-pack' ),
1466
  'dependency' => [ 'module_woocommerce', '==', '1', '', 'visible' ],
1467
  'sanitize' => 'sbp_sanitize_boolean',
1468
  'text_on' => 'Enabled',
13
  // If this file is called directly, abort.
14
  use SpeedBooster\SBP_Notice_Manager;
15
  use SpeedBooster\SBP_Utils;
16
+ use SpeedBooster\SBP_Advanced_Cache_Generator;
17
+ use SpeedBooster\SBP_Cache;
18
+ use SpeedBooster\SBP_LiteSpeed_Cache;
19
+
20
 
21
  if ( ! defined( 'WPINC' ) ) {
22
  die;
117
  add_action( 'csf_loaded', [ $this, 'create_metaboxes' ] );
118
  }
119
 
120
+ public static function set_up_defaults() {
121
+
122
+ if( ! get_option( 'sbp_activation_defaults' ) ) { return; }
123
+
124
+ if ( sbp_get_option( 'module_caching' ) && ! sbp_should_disable_feature( 'caching' ) ) {
125
+
126
+ SBP_Cache::clear_total_cache();
127
+
128
+ SBP_Cache::set_wp_cache_constant( true );
129
+
130
+ SBP_Cache::generate_htaccess();
131
+
132
+ $advanced_cache_file_content = SBP_Advanced_Cache_Generator::generate_advanced_cache_file();
133
+ $advanced_cache_path = WP_CONTENT_DIR . '/advanced-cache.php';
134
+ if ( $advanced_cache_file_content ) {
135
+ file_put_contents( $advanced_cache_path, $advanced_cache_file_content );
136
+ }
137
+
138
+ }
139
+
140
+ if ( sbp_get_option( 'module_caching_ls' ) && ! sbp_should_disable_feature( 'caching' ) ) {
141
+ SBP_LiteSpeed_Cache::insert_htaccess_rules();
142
+ }
143
+
144
+ delete_option( 'sbp_activation_defaults' );
145
+
146
+ }
147
+
148
+ public static function redirect() {
149
+
150
+ // Make sure it's the correct user
151
+ if ( intval( get_option( 'sbp_activation_redirect', false ) ) === wp_get_current_user()->ID ) {
152
+ // Make sure we don't redirect again after this one
153
+ delete_option( 'sbp_activation_redirect' );
154
+ wp_safe_redirect( admin_url( '/admin.php?page=sbp-settings' ) );
155
+ exit;
156
+ }
157
+
158
+ }
159
+
160
  /**
161
  * Register the stylesheets for the admin area.
162
  *
457
  'dependency' => [ 'module_tweaks', '==', '1', '', 'visible' ],
458
  'sanitize' => 'sbp_sanitize_boolean',
459
  ],
460
+ [
461
+ 'title' => __( 'Dequeue "global styles"', 'speed-booster-pack' ),
462
+ 'id' => 'dequeue_global_styles',
463
+ 'type' => 'switcher',
464
+ 'desc' => __( 'With version 5.9, full site editing capabilities has been added to WordPress. However, the new structure has some "global styles" that isn\'t really needed for most themes and/or WordPress users. Enabling this will remove a big chunk of inline CSS that WordPress adds, plus some SVG definitions. If you don\'t know what this is, you can try enabling it and see if it affects your front-end.', 'speed-booster-pack' ),
465
+ 'dependency' => [ 'module_tweaks', '==', '1', '', 'visible' ],
466
+ 'sanitize' => 'sbp_sanitize_boolean',
467
+ ],
468
  [
469
  'title' => __( 'Heartbeat settings', 'speed-booster-pack' ),
470
  'id' => 'heartbeat_settings',
663
  'title' => __( 'Enable/Disable', 'speed-booster-pack' ) . ' ' . __( 'Caching', 'speed-booster-pack' ),
664
  'label' => __( 'Enables or disables the whole module without resetting its settings.', 'speed-booster-pack' ),
665
  'sanitize' => 'sbp_sanitize_boolean',
666
+ // 'default' => true,
667
  ],
668
  [
669
  'title' => __( 'Cache expiry time', 'speed-booster-pack' ),
1515
  'title' => __( 'WooCommerce Marketing', 'speed-booster-pack' ),
1516
  'id' => 'woocommerce_marketing',
1517
  'type' => 'switcher',
1518
+ 'desc' => __( 'Enable or disable WooCommerce marketing.', 'speed-booster-pack' ),
1519
  'dependency' => [ 'module_woocommerce', '==', '1', '', 'visible' ],
1520
  'sanitize' => 'sbp_sanitize_boolean',
1521
  'text_on' => 'Enabled',
includes/class-speed-booster-pack-activator.php CHANGED
@@ -39,21 +39,17 @@ class Speed_Booster_Pack_Activator {
39
  * @since 4.0.0
40
  */
41
  public static function activate() {
42
- if ( sbp_get_option( 'module_caching' ) && ! sbp_should_disable_feature( 'caching' ) ) {
43
- SBP_Cache::clear_total_cache();
44
- SBP_Cache::set_wp_cache_constant( true );
45
- SBP_Cache::generate_htaccess();
46
-
47
- $advanced_cache_file_content = SBP_Advanced_Cache_Generator::generate_advanced_cache_file();
48
- $advanced_cache_path = WP_CONTENT_DIR . '/advanced-cache.php';
49
- if ( $advanced_cache_file_content ) {
50
- file_put_contents( $advanced_cache_path, $advanced_cache_file_content );
51
- }
52
  }
 
53
 
54
- if ( sbp_get_option( 'module_caching_ls' ) && ! sbp_should_disable_feature( 'caching' ) ) {
55
- SBP_LiteSpeed_Cache::insert_htaccess_rules();
56
- }
57
  }
58
 
59
  }
39
  * @since 4.0.0
40
  */
41
  public static function activate() {
42
+
43
+ add_option( 'sbp_activation_defaults', true );
44
+
45
+ // Don't do redirects when multiple plugins are bulk activated
46
+ if (
47
+ ( isset( $_REQUEST['action'] ) && 'activate-selected' === $_REQUEST['action'] ) &&
48
+ ( isset( $_POST['checked'] ) && count( $_POST['checked'] ) > 1 ) ) {
49
+ return;
 
 
50
  }
51
+ add_option( 'sbp_activation_redirect', wp_get_current_user()->ID );
52
 
 
 
 
53
  }
54
 
55
  }
includes/class-speed-booster-pack.php CHANGED
@@ -273,6 +273,8 @@ class Speed_Booster_Pack {
273
 
274
  $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
275
  $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
 
 
276
  }
277
 
278
  /**
@@ -288,9 +290,9 @@ class Speed_Booster_Pack {
288
 
289
  $plugin_public = new Speed_Booster_Pack_Public( $this->get_plugin_name(), $this->get_version() );
290
 
291
- $this->loader->add_action( 'template_redirect', $plugin_public, 'template_redirect', 0 );
292
 
293
- $this->loader->add_action( 'shutdown', $plugin_public, 'shutdown', PHP_INT_MAX );
294
 
295
  $this->loader->add_filter( 'wp_headers', $plugin_public, 'sbp_headers' );
296
  }
@@ -300,6 +302,7 @@ class Speed_Booster_Pack {
300
  */
301
  private function define_public_filters() {
302
  add_filter( 'aioseo_flush_output_buffer', '__return_false' );
 
303
  }
304
 
305
  private function save_post_types() {
273
 
274
  $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
275
  $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
276
+ $this->loader->add_action( 'admin_init', $plugin_admin, 'set_up_defaults' );
277
+ $this->loader->add_action( 'admin_init', $plugin_admin, 'redirect' );
278
  }
279
 
280
  /**
290
 
291
  $plugin_public = new Speed_Booster_Pack_Public( $this->get_plugin_name(), $this->get_version() );
292
 
293
+ $this->loader->add_action( 'init', $plugin_public, 'template_redirect', 1 );
294
 
295
+ // $this->loader->add_action( 'shutdown', $plugin_public, 'shutdown', PHP_INT_MAX );
296
 
297
  $this->loader->add_filter( 'wp_headers', $plugin_public, 'sbp_headers' );
298
  }
302
  */
303
  private function define_public_filters() {
304
  add_filter( 'aioseo_flush_output_buffer', '__return_false' );
305
+ add_filter( 'rocket_plugins_to_deactivate', '__return_empty_array' );
306
  }
307
 
308
  private function save_post_types() {
includes/classes/class-sbp-html-minifier.php CHANGED
@@ -2,6 +2,8 @@
2
 
3
  namespace SpeedBooster;
4
 
 
 
5
  // If this file is called directly, abort.
6
  if ( ! defined( 'WPINC' ) ) {
7
  die;
@@ -32,79 +34,271 @@ class SBP_HTML_Minifier extends SBP_Abstract_Module {
32
 
33
  public function handle_html_minify( $html ) {
34
  $this->html = $html;
35
- $this->minifyHTML();
36
 
37
- return $this->html;
38
  }
39
 
40
- private function minifyHTML() {
41
- $pattern = '/<(?<script>script).*?<\/script\s*>|<(?<style>style).*?<\/style\s*>|<!(?<comment>--).*?-->|<(?<tag>[\/\w.:-]*)(?:".*?"|\'.*?\'|[^\'">]+)*>|(?<text>((<[^!\/\w.:-])?[^<]*)+)|/si';
42
- preg_match_all( $pattern, $this->html, $matches, PREG_SET_ORDER );
43
- $overriding = false;
44
- $raw_tag = false;
45
- // Variable reused for output
46
- $html = '';
47
- foreach ( $matches as $token ) {
48
- $tag = ( isset( $token['tag'] ) ) ? strtolower( $token['tag'] ) : null;
49
-
50
- $content = $token[0];
51
-
52
- if ( is_null( $tag ) ) {
53
- if ( ! empty( $token['script'] ) ) {
54
- $strip = $this->minify_js;
55
- } elseif ( ! empty( $token['style'] ) ) {
56
- $strip = $this->minify_css;
57
- } elseif ( $content == '<!--sbp-html-minifier no minifier-->' ) {
58
- $overriding = ! $overriding;
59
-
60
- // Don't print the comments
61
- continue;
62
- } elseif ( $this->remove_comments ) {
63
- if ( ! $overriding && $raw_tag != 'textarea' ) {
64
- // Remove any HTML comments, except MSIE conditional comments
65
- $content = preg_replace( '/<!--(?!\s*(?:\[if [^\]]+]|<!|>))(?:(?!-->).)*-->/s', '', $content );
66
- }
67
- }
68
- } else {
69
- if ( $tag == 'pre' || $tag == 'textarea' ) {
70
- $raw_tag = $tag;
71
- } elseif ( $tag == '/pre' || $tag == '/textarea' ) {
72
- $raw_tag = false;
73
- } else {
74
- if ( $raw_tag || $overriding ) {
75
- $strip = false;
76
- } else {
77
- $strip = true;
78
- // Remove all empty attributes, except action, alt, content, src
79
- $content = preg_replace( '/(\s+)(\w++(?<!\baction|\balt|\bcontent|\bsrc)="")/',
80
- '$1',
81
- $content );
82
- // Remove all space before the end of self-closing XHTML tags
83
- // JavaScript excluded
84
- $content = str_replace( ' />', '/>', $content );
85
- }
86
- }
87
- }
88
-
89
- if ( $strip ) {
90
- $content = $this->removeWhiteSpace( $content );
91
- }
92
-
93
- $html .= $content;
94
- }
95
 
96
- $this->html = $html;
97
- }
 
 
98
 
99
- private function removeWhiteSpace( $str ) {
100
- $str = str_replace( "\t", ' ', $str );
101
- $str = str_replace( "\n", '', $str );
102
- $str = str_replace( "\r", '', $str );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
- while ( stristr( $str, ' ' ) ) {
105
- $str = str_replace( ' ', ' ', $str );
106
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
- return $str;
109
- }
110
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  namespace SpeedBooster;
4
 
5
+ use SpeedBooster\SBP_HTML_Minify;
6
+
7
  // If this file is called directly, abort.
8
  if ( ! defined( 'WPINC' ) ) {
9
  die;
34
 
35
  public function handle_html_minify( $html ) {
36
  $this->html = $html;
37
+ return SBP_HTML_Minify::minify($html);
38
 
 
39
  }
40
 
41
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
+ /**
44
+ * Class Minify_HTML
45
+ * @package Minify
46
+ */
47
 
48
+ /**
49
+ * Compress HTML
50
+ *
51
+ * This is a heavy regex-based removal of whitespace, unnecessary comments and
52
+ * tokens. IE conditional comments are preserved. There are also options to have
53
+ * STYLE and SCRIPT blocks compressed by callback functions.
54
+ *
55
+ * A test suite is available.
56
+ *
57
+ * @package Minify
58
+ * @author Stephen Clay <steve@mrclay.org>
59
+ */
60
+ class SBP_HTML_Minify
61
+ {
62
+ /**
63
+ * @var boolean
64
+ */
65
+ protected $_jsCleanComments = true;
66
 
67
+ /**
68
+ * "Minify" an HTML page
69
+ *
70
+ * @param string $html
71
+ *
72
+ * @param array $options
73
+ *
74
+ * 'cssMinifier' : (optional) callback function to process content of STYLE
75
+ * elements.
76
+ *
77
+ * 'jsMinifier' : (optional) callback function to process content of SCRIPT
78
+ * elements. Note: the type attribute is ignored.
79
+ *
80
+ * 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
81
+ * unset, minify will sniff for an XHTML doctype.
82
+ *
83
+ * @return string
84
+ */
85
+ public static function minify($html, $options = array())
86
+ {
87
+ $min = new self($html, $options);
88
 
89
+ return $min->process();
90
+ }
91
+
92
+ /**
93
+ * Create a minifier object
94
+ *
95
+ * @param string $html
96
+ *
97
+ * @param array $options
98
+ *
99
+ * 'cssMinifier' : (optional) callback function to process content of STYLE
100
+ * elements.
101
+ *
102
+ * 'jsMinifier' : (optional) callback function to process content of SCRIPT
103
+ * elements. Note: the type attribute is ignored.
104
+ *
105
+ * 'jsCleanComments' : (optional) whether to remove HTML comments beginning and end of script block
106
+ *
107
+ * 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
108
+ * unset, minify will sniff for an XHTML doctype.
109
+ */
110
+ public function __construct($html, $options = array())
111
+ {
112
+ $this->_html = str_replace("\r\n", "\n", trim($html));
113
+ if (isset($options['xhtml'])) {
114
+ $this->_isXhtml = (bool)$options['xhtml'];
115
+ }
116
+ if (isset($options['cssMinifier'])) {
117
+ $this->_cssMinifier = $options['cssMinifier'];
118
+ }
119
+ if (isset($options['jsMinifier'])) {
120
+ $this->_jsMinifier = $options['jsMinifier'];
121
+ }
122
+ if (isset($options['jsCleanComments'])) {
123
+ $this->_jsCleanComments = (bool)$options['jsCleanComments'];
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Minify the markeup given in the constructor
129
+ *
130
+ * @return string
131
+ */
132
+ public function process()
133
+ {
134
+ if ($this->_isXhtml === null) {
135
+ $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
136
+ }
137
+
138
+ $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
139
+ $this->_placeholders = array();
140
+
141
+ // replace SCRIPTs (and minify) with placeholders
142
+ $this->_html = preg_replace_callback(
143
+ '/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/iu',
144
+ array($this, '_removeScriptCB'),
145
+ $this->_html
146
+ );
147
+
148
+ // replace STYLEs (and minify) with placeholders
149
+ $this->_html = preg_replace_callback(
150
+ '/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/iu',
151
+ array($this, '_removeStyleCB'),
152
+ $this->_html
153
+ );
154
+
155
+ // remove HTML comments (not containing IE conditional comments).
156
+ $this->_html = preg_replace_callback(
157
+ '/<!--([\\s\\S]*?)-->/u',
158
+ array($this, '_commentCB'),
159
+ $this->_html
160
+ );
161
+
162
+ // replace PREs with placeholders
163
+ $this->_html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/iu', array($this, '_removePreCB'), $this->_html);
164
+
165
+ // replace TEXTAREAs with placeholders
166
+ $this->_html = preg_replace_callback(
167
+ '/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/iu',
168
+ array($this, '_removeTextareaCB'),
169
+ $this->_html
170
+ );
171
+
172
+ // trim each line.
173
+ // @todo take into account attribute values that span multiple lines.
174
+ $this->_html = preg_replace('/^\\s+|\\s+$/mu', '', $this->_html);
175
+
176
+ // remove ws around block/undisplayed elements
177
+ $this->_html = preg_replace('/\\s+(<\\/?(?:area|article|aside|base(?:font)?|blockquote|body'
178
+ .'|canvas|caption|center|col(?:group)?|dd|dir|div|dl|dt|fieldset|figcaption|figure|footer|form'
179
+ .'|frame(?:set)?|h[1-6]|head|header|hgroup|hr|html|legend|li|link|main|map|menu|meta|nav'
180
+ .'|ol|opt(?:group|ion)|output|p|param|section|t(?:able|body|head|d|h||r|foot|itle)'
181
+ .'|ul|video)\\b[^>]*>)/iu', '$1', $this->_html);
182
+
183
+ // remove ws outside of all elements
184
+ $this->_html = preg_replace(
185
+ '/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?</u',
186
+ '>$1$2$3<',
187
+ $this->_html
188
+ );
189
+
190
+ // use newlines before 1st attribute in open tags (to limit line lengths)
191
+ $this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/iu', "$1\n$2", $this->_html);
192
+
193
+ // fill placeholders
194
+ $this->_html = str_replace(
195
+ array_keys($this->_placeholders),
196
+ array_values($this->_placeholders),
197
+ $this->_html
198
+ );
199
+ // issue 229: multi-pass to catch scripts that didn't get replaced in textareas
200
+ $this->_html = str_replace(
201
+ array_keys($this->_placeholders),
202
+ array_values($this->_placeholders),
203
+ $this->_html
204
+ );
205
+
206
+ return $this->_html;
207
+ }
208
+
209
+ protected function _commentCB($m)
210
+ {
211
+ return (0 === strpos($m[1], '[') || false !== strpos($m[1], '<![') || 0 === strpos($m[1], '#'))
212
+ ? $m[0]
213
+ : '';
214
+ }
215
+
216
+ protected function _reservePlace($content)
217
+ {
218
+ $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
219
+ $this->_placeholders[$placeholder] = $content;
220
+
221
+ return $placeholder;
222
+ }
223
+
224
+ protected $_isXhtml;
225
+ protected $_replacementHash;
226
+ protected $_placeholders = array();
227
+ protected $_cssMinifier;
228
+ protected $_jsMinifier;
229
+
230
+ protected function _removePreCB($m)
231
+ {
232
+ return $this->_reservePlace("<pre{$m[1]}");
233
+ }
234
+
235
+ protected function _removeTextareaCB($m)
236
+ {
237
+ return $this->_reservePlace("<textarea{$m[1]}");
238
+ }
239
+
240
+ protected function _removeStyleCB($m)
241
+ {
242
+ $openStyle = "<style{$m[1]}";
243
+ $css = $m[2];
244
+ // remove HTML comments
245
+ $css = preg_replace('/(?:^\\s*<!--|-->\\s*$)/u', '', $css);
246
+
247
+ // remove CDATA section markers
248
+ $css = $this->_removeCdata($css);
249
+
250
+ // minify
251
+ $minifier = $this->_cssMinifier
252
+ ? $this->_cssMinifier
253
+ : 'trim';
254
+ $css = call_user_func($minifier, $css);
255
+
256
+ return $this->_reservePlace(
257
+ $this->_needsCdata($css)
258
+ ? "{$openStyle}/*<![CDATA[*/{$css}/*]]>*/</style>"
259
+ : "{$openStyle}{$css}</style>"
260
+ );
261
+ }
262
+
263
+ protected function _removeScriptCB($m)
264
+ {
265
+ $openScript = "<script{$m[2]}";
266
+ $js = $m[3];
267
+
268
+ // whitespace surrounding? preserve at least one space
269
+ $ws1 = ($m[1] === '') ? '' : ' ';
270
+ $ws2 = ($m[4] === '') ? '' : ' ';
271
+
272
+ // remove HTML comments (and ending "//" if present)
273
+ if ($this->_jsCleanComments) {
274
+ $js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/u', '', $js);
275
+ }
276
+
277
+ // remove CDATA section markers
278
+ $js = $this->_removeCdata($js);
279
+
280
+ // minify
281
+ $minifier = $this->_jsMinifier
282
+ ? $this->_jsMinifier
283
+ : 'trim';
284
+ $js = call_user_func($minifier, $js);
285
+
286
+ return $this->_reservePlace(
287
+ $this->_needsCdata($js)
288
+ ? "{$ws1}{$openScript}/*<![CDATA[*/{$js}/*]]>*/</script>{$ws2}"
289
+ : "{$ws1}{$openScript}{$js}</script>{$ws2}"
290
+ );
291
+ }
292
+
293
+ protected function _removeCdata($str)
294
+ {
295
+ return (false !== strpos($str, '<![CDATA['))
296
+ ? str_replace(array('<![CDATA[', ']]>'), '', $str)
297
+ : $str;
298
+ }
299
+
300
+ protected function _needsCdata($str)
301
+ {
302
+ return ($this->_isXhtml && preg_match('/(?:[<&]|\\-\\-|\\]\\]>)/u', $str));
303
+ }
304
+ }
includes/classes/class-sbp-preboost.php CHANGED
@@ -50,11 +50,11 @@ class SBP_Preboost extends SBP_Abstract_Module {
50
  $preboost = sbp_get_option( 'preboost' );
51
 
52
  if ( isset( $preboost['preboost_enable'] ) && $preboost['preboost_enable'] ) {
53
- add_action( 'wp_head', [ $this, 'add_preload_tags' ] );
54
  }
55
 
56
  if ( isset( $preboost['preboost_featured_image'] ) && $preboost['preboost_featured_image'] ) {
57
- add_action( 'wp_head', [ $this, 'add_featured_image_preload_tag' ] );
58
  }
59
  }
60
  }
50
  $preboost = sbp_get_option( 'preboost' );
51
 
52
  if ( isset( $preboost['preboost_enable'] ) && $preboost['preboost_enable'] ) {
53
+ add_action( 'wp_head', [ $this, 'add_preload_tags' ], 1 );
54
  }
55
 
56
  if ( isset( $preboost['preboost_featured_image'] ) && $preboost['preboost_featured_image'] ) {
57
+ add_action( 'wp_head', [ $this, 'add_featured_image_preload_tag' ], 1 );
58
  }
59
  }
60
  }
includes/classes/class-sbp-tweaks.php CHANGED
@@ -8,28 +8,6 @@ if ( ! defined( 'WPINC' ) ) {
8
  }
9
 
10
  class SBP_Tweaks extends SBP_Abstract_Module {
11
- private $tweak_settings = [
12
- 'trim_query_strings' => 'trim_query_strings',
13
- 'dequeue_emoji_scripts' => 'dequeue_emoji_scripts',
14
- 'disable_self_pingbacks' => 'disable_self_pingbacks',
15
- 'dequeue_dashicons' => 'dequeue_dashicons',
16
- 'post_revisions' => 'post_revisions',
17
- 'autosave_interval' => 'autosave_interval',
18
- 'dequeue_block_library' => 'dequeue_block_library',
19
- 'disable_post_embeds' => 'disable_post_embeds',
20
- 'instant_page' => 'instant_page',
21
- 'heartbeat_settings' => 'heartbeat_settings',
22
- 'declutter_head' => [
23
- 'declutter_shortlinks' => 'declutter_shortlinks',
24
- 'declutter_adjacent_posts_links' => 'declutter_adjacent_posts_links',
25
- 'declutter_wlw' => 'declutter_wlw',
26
- 'declutter_rsd' => 'declutter_rsd',
27
- 'declutter_rest_api_links' => 'declutter_rest_api_links',
28
- 'declutter_feed_links' => 'declutter_feed_links',
29
- 'declutter_wp_version' => 'declutter_wp_version',
30
- ],
31
- 'dequeue_comment_reply_script' => 'dequeue_comment_reply_script',
32
- ];
33
 
34
  public function __construct() {
35
  parent::__construct();
@@ -42,45 +20,42 @@ class SBP_Tweaks extends SBP_Abstract_Module {
42
  }
43
 
44
  public function run_class() {
45
- if ( $this->should_sbp_run ) {
46
- $this->call_option_methods( $this->tweak_settings );
47
- }
48
- }
49
 
50
- private function call_option_methods( $settings, $parent = null ) {
51
- foreach ( $settings as $option_name => $function ) {
52
- if ( is_array( $settings[ $option_name ] ) ) {
53
- $this->call_option_methods( $settings[ $option_name ], $option_name );
54
- } else {
55
- if ( null !== $parent ) {
56
- if ( is_array( sbp_get_option( $parent ) ) && isset( sbp_get_option( $parent )[ $option_name ] ) ) {
57
- $this->$function();
58
- }
59
- } else {
60
- if ( sbp_get_option( $option_name ) ) {
61
- $this->$function();
62
- }
63
- }
64
- }
65
- }
 
 
 
 
 
 
66
  }
67
 
68
  /**
69
  * Hook trim_query_string_process to proper actions
70
  */
71
  private function trim_query_strings() {
72
- if ( ! is_admin() ) {
73
- if ( sbp_get_option( 'trim_query_strings' ) ) {
74
- add_action( 'script_loader_src', [ $this, 'trim_query_strings_handle' ], 15 );
75
- }
76
 
77
- if ( sbp_get_option( 'trim_query_strings' ) ) {
78
- add_action( 'style_loader_src', [ $this, 'trim_query_strings_handle' ], 15 );
79
- }
80
- }
81
- }
82
 
83
- // Remove Query Strings
84
 
85
  /**
86
  * Removes query string parameters (rev and ver) from styles and scripts
@@ -90,12 +65,17 @@ class SBP_Tweaks extends SBP_Abstract_Module {
90
  * @return mixed|string
91
  */
92
  public function trim_query_strings_handle( $src ) {
 
93
  return preg_split( "/(\?rev|&ver|\?ver)/", $src )[0];
 
94
  }
95
 
96
  // Remove Emoji Scripts
97
 
98
  private function dequeue_emoji_scripts() {
 
 
 
99
  add_action( 'init', [ $this, 'dequeue_emoji_scripts_handle' ] );
100
  }
101
 
@@ -103,124 +83,139 @@ class SBP_Tweaks extends SBP_Abstract_Module {
103
  * Removes WordPress emoji script
104
  */
105
  public function dequeue_emoji_scripts_handle() {
106
- if ( ! is_admin() ) {
107
- remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
108
- remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
109
- remove_filter( 'embed_head', 'print_emoji_detection_script' );
110
- remove_action( 'wp_print_styles', 'print_emoji_styles' );
111
- remove_action( 'admin_print_styles', 'print_emoji_styles' );
112
- remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
113
- remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
114
- remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
115
-
116
- add_filter( 'tiny_mce_plugins', [ $this, 'disable_emojis_tinymce' ] );
117
- add_filter( 'wp_resource_hints', [ $this, 'disable_emojis_dns_prefetch' ], 10, 2 );
118
- }
119
  }
120
 
121
- /**
122
- * Disables emojis in Tinymce
123
- *
124
- * @param $plugins
125
- *
126
- * @return array
127
- */
128
  public function disable_emojis_tinymce( $plugins ) {
 
129
  if ( is_array( $plugins ) ) {
130
  return array_diff( $plugins, [ 'wpemoji' ] );
131
  } else {
132
  return [];
133
  }
 
134
  }
135
 
136
- /**
137
- * @param $urls
138
- * @param $relation_type
139
- *
140
- * @return array
141
- */
142
  public function disable_emojis_dns_prefetch( $urls, $relation_type ) {
 
143
  if ( 'dns-prefetch' == $relation_type ) {
144
  $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2.2.1/svg/' );
145
  $urls = array_diff( $urls, [ $emoji_svg_url ] );
146
  }
147
 
148
  return $urls;
149
- }
150
 
151
- // Disable Self Pingback
152
 
153
  private function disable_self_pingbacks() {
 
 
 
154
  add_action( 'pre_ping', [ $this, 'disable_self_pingbacks_handle' ] );
155
  }
156
 
157
- /**
158
- * @param $links
159
- */
160
  public function disable_self_pingbacks_handle( &$links ) {
 
161
  $home = get_option( 'home' );
 
162
  foreach ( $links as $l => $link ) {
163
  if ( 0 === strpos( $link, $home ) ) {
164
  unset( $links[ $l ] );
165
  }
166
  }
167
- }
168
 
169
- /**
170
- * @param $scripts
171
- */
172
- public function dequeue_jquery_migrate_handle( $scripts ) {
173
- if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) {
174
- $jquery_script = $scripts->registered['jquery'];
175
-
176
- if ( $jquery_script->deps ) { // Check whether the script has any dependencies
177
- $jquery_script->deps = array_diff( $jquery_script->deps, [ 'jquery-migrate' ] );
178
- }
179
- }
180
  }
181
 
182
- // Remove Dash Icons
183
  private function dequeue_dashicons() {
 
 
 
184
  add_action( 'wp_enqueue_scripts', [ $this, 'dequeue_dashicons_handle' ] );
 
185
  }
186
 
187
  public function dequeue_dashicons_handle() {
188
- if ( ! is_user_logged_in() ) {
189
- wp_dequeue_style( 'dashicons' );
190
- wp_deregister_style( 'dashicons' );
191
- }
 
192
  }
193
 
194
  private function post_revisions() {
 
195
  $post_revisions = sbp_get_option( 'post_revisions' );
196
- if ( ! empty( $post_revisions ) && (int) $post_revisions ) {
197
- add_filter( 'wp_revisions_to_keep', function( $num, $post ) use ( $post_revisions ) {
198
- return $post_revisions;
199
- }, 2, 2 );
200
- }
 
 
201
  }
202
 
203
  private function autosave_interval() {
204
- if ( ! empty( sbp_get_option( 'autosave_interval' ) ) && ! defined( 'AUTOSAVE_INTERVAL' ) ) {
205
- define( 'AUTOSAVE_INTERVAL', sbp_get_option( 'autosave_interval' ) * 60 );
206
- }
 
 
 
 
207
  }
208
 
209
  private function dequeue_block_library() {
 
 
 
210
  add_action( 'wp_enqueue_scripts', [ $this, 'dequeue_block_library_handle' ] );
 
211
  }
212
 
213
  public function dequeue_block_library_handle() {
 
214
  wp_dequeue_style( 'wp-block-library' );
215
  wp_dequeue_style( 'wp-block-library-theme' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  }
217
 
218
  private function disable_post_embeds() {
 
 
 
219
  add_action( 'init', [ $this, 'remove_embeds_from_init' ], 9999 );
220
 
221
  }
222
 
223
  public function remove_embeds_from_init() {
 
224
  // Remove the REST API endpoint.
225
  remove_action( 'rest_api_init', 'wp_oembed_register_route' );
226
 
@@ -241,9 +236,11 @@ class SBP_Tweaks extends SBP_Abstract_Module {
241
 
242
  // Remove filter of the oEmbed result before any HTTP requests are made.
243
  remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
 
244
  }
245
 
246
  public function disable_embeds_rewrites( $rules ) {
 
247
  foreach ( $rules as $rule => $rewrite ) {
248
  if ( false !== strpos( $rewrite, 'embed=true' ) ) {
249
  unset( $rules[ $rule ] );
@@ -251,77 +248,123 @@ class SBP_Tweaks extends SBP_Abstract_Module {
251
  }
252
 
253
  return $rules;
254
- }
255
 
256
- public function disable_post_embeds_handle() {
257
- wp_dequeue_script( 'wp-embed' );
258
  }
259
 
260
  private function heartbeat_settings() {
 
261
  switch ( sbp_get_option( 'heartbeat_settings' ) ) {
 
262
  case "optimized":
263
  add_filter( 'heartbeat_settings', [ $this, 'heartbeat_settings_handle' ] );
264
  break;
 
265
  case "disabled":
266
  add_action( 'wp_enqueue_scripts', [ $this, 'disable_heartbeat' ] );
267
  add_action( 'admin_enqueue_scripts', [ $this, 'disable_heartbeat' ] );
268
  break;
 
269
  }
270
- }
271
 
272
- public function disable_heartbeat() {
273
- wp_deregister_script( 'heartbeat' );
274
  }
275
 
276
  public function heartbeat_settings_handle( $settings ) {
277
- $settings['interval'] = sbp_get_option( 'heartbeat_frequency' );
 
278
 
279
  return $settings;
 
 
 
 
 
 
 
280
  }
281
 
282
  // Instant Page
283
  private function instant_page() {
 
 
 
284
  add_action( 'wp_enqueue_scripts', [ $this, 'instant_page_handle' ] );
 
285
  }
286
 
287
  public function instant_page_handle() {
 
288
  wp_enqueue_script( 'sbp-ins-page', SBP_URL . 'public/js/inspage.js', false, '5.1.0', true );
 
289
  }
290
 
291
  private function dequeue_comment_reply_script() {
 
 
 
292
  add_action( 'init', [ $this, 'comment_reply_script_handle' ] );
 
293
  }
294
 
295
  public function comment_reply_script_handle() {
 
296
  wp_deregister_script( 'comment-reply' );
 
297
  }
298
 
299
  private function declutter_shortlinks() {
 
 
 
300
  remove_action( 'wp_head', 'wp_shortlink_wp_head' );
 
301
  }
302
 
303
  private function declutter_adjacent_posts_links() {
 
 
 
304
  remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
 
305
  }
306
 
307
  private function declutter_wlw() {
 
 
 
308
  remove_action( 'wp_head', 'wlwmanifest_link' );
 
309
  }
310
 
311
  private function declutter_rsd() {
 
 
 
312
  remove_action( 'wp_head', 'rsd_link' );
 
313
  }
314
 
315
  private function declutter_rest_api_links() {
 
 
 
316
  remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
 
317
  }
318
 
319
  private function declutter_feed_links() {
 
 
 
320
  remove_action( 'wp_head', 'feed_links_extra', 3 );
321
  remove_action( 'wp_head', 'feed_links', 2 );
 
322
  }
323
 
324
  private function declutter_wp_version() {
 
 
 
325
  remove_action( 'wp_head', 'wp_generator' );
 
326
  }
327
  }
8
  }
9
 
10
  class SBP_Tweaks extends SBP_Abstract_Module {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  public function __construct() {
13
  parent::__construct();
20
  }
21
 
22
  public function run_class() {
 
 
 
 
23
 
24
+ if ( ! $this->should_sbp_run ) { return; }
25
+
26
+ $this->trim_query_strings();
27
+ $this->dequeue_emoji_scripts();
28
+ $this->disable_self_pingbacks();
29
+ $this->dequeue_dashicons();
30
+ $this->post_revisions();
31
+ $this->autosave_interval();
32
+ $this->dequeue_block_library();
33
+ $this->dequeue_global_styles();
34
+ $this->disable_post_embeds();
35
+ $this->instant_page();
36
+ $this->heartbeat_settings();
37
+ $this->declutter_shortlinks();
38
+ $this->declutter_adjacent_posts_links();
39
+ $this->declutter_wlw();
40
+ $this->declutter_rsd();
41
+ $this->declutter_rest_api_links();
42
+ $this->declutter_feed_links();
43
+ $this->declutter_wp_version();
44
+ $this->dequeue_comment_reply_script();
45
+
46
  }
47
 
48
  /**
49
  * Hook trim_query_string_process to proper actions
50
  */
51
  private function trim_query_strings() {
 
 
 
 
52
 
53
+ if ( is_admin() || ! sbp_get_option( 'trim_query_strings' ) ) { return; }
54
+
55
+ add_action( 'script_loader_src', [ $this, 'trim_query_strings_handle' ], 15 );
56
+ add_action( 'style_loader_src', [ $this, 'trim_query_strings_handle' ], 15 );
 
57
 
58
+ }
59
 
60
  /**
61
  * Removes query string parameters (rev and ver) from styles and scripts
65
  * @return mixed|string
66
  */
67
  public function trim_query_strings_handle( $src ) {
68
+
69
  return preg_split( "/(\?rev|&ver|\?ver)/", $src )[0];
70
+
71
  }
72
 
73
  // Remove Emoji Scripts
74
 
75
  private function dequeue_emoji_scripts() {
76
+
77
+ if ( ! sbp_get_option( 'dequeue_emoji_scripts' ) || is_admin() ) { return; }
78
+
79
  add_action( 'init', [ $this, 'dequeue_emoji_scripts_handle' ] );
80
  }
81
 
83
  * Removes WordPress emoji script
84
  */
85
  public function dequeue_emoji_scripts_handle() {
86
+
87
+ remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
88
+ remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
89
+ remove_filter( 'embed_head', 'print_emoji_detection_script' );
90
+ remove_action( 'wp_print_styles', 'print_emoji_styles' );
91
+ remove_action( 'admin_print_styles', 'print_emoji_styles' );
92
+ remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
93
+ remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
94
+ remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
95
+
96
+ add_filter( 'tiny_mce_plugins', [ $this, 'disable_emojis_tinymce' ] );
97
+ add_filter( 'wp_resource_hints', [ $this, 'disable_emojis_dns_prefetch' ], 10, 2 );
98
+
99
  }
100
 
 
 
 
 
 
 
 
101
  public function disable_emojis_tinymce( $plugins ) {
102
+
103
  if ( is_array( $plugins ) ) {
104
  return array_diff( $plugins, [ 'wpemoji' ] );
105
  } else {
106
  return [];
107
  }
108
+
109
  }
110
 
 
 
 
 
 
 
111
  public function disable_emojis_dns_prefetch( $urls, $relation_type ) {
112
+
113
  if ( 'dns-prefetch' == $relation_type ) {
114
  $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2.2.1/svg/' );
115
  $urls = array_diff( $urls, [ $emoji_svg_url ] );
116
  }
117
 
118
  return $urls;
 
119
 
120
+ }
121
 
122
  private function disable_self_pingbacks() {
123
+
124
+ if ( ! sbp_get_option( 'disable_self_pingbacks' ) ) { return; }
125
+
126
  add_action( 'pre_ping', [ $this, 'disable_self_pingbacks_handle' ] );
127
  }
128
 
 
 
 
129
  public function disable_self_pingbacks_handle( &$links ) {
130
+
131
  $home = get_option( 'home' );
132
+
133
  foreach ( $links as $l => $link ) {
134
  if ( 0 === strpos( $link, $home ) ) {
135
  unset( $links[ $l ] );
136
  }
137
  }
 
138
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
 
 
141
  private function dequeue_dashicons() {
142
+
143
+ if ( ! sbp_get_option( 'dequeue_dashicons' ) ) { return; }
144
+
145
  add_action( 'wp_enqueue_scripts', [ $this, 'dequeue_dashicons_handle' ] );
146
+
147
  }
148
 
149
  public function dequeue_dashicons_handle() {
150
+
151
+ if ( is_user_logged_in() ) { return; }
152
+
153
+ wp_deregister_style( 'dashicons' );
154
+
155
  }
156
 
157
  private function post_revisions() {
158
+
159
  $post_revisions = sbp_get_option( 'post_revisions' );
160
+
161
+ if ( empty( $post_revisions ) || ! (int) $post_revisions ) { return; }
162
+
163
+ add_filter( 'wp_revisions_to_keep', function( $num, $post ) use ( $post_revisions ) {
164
+ return $post_revisions;
165
+ }, 50, 2 );
166
+
167
  }
168
 
169
  private function autosave_interval() {
170
+
171
+ $autosave_interval = sbp_get_option( 'autosave_interval' );
172
+
173
+ if ( empty( $autosave_interval ) || ! (int) $autosave_interval || defined( 'AUTOSAVE_INTERVAL' ) ) { return; }
174
+
175
+ define( 'AUTOSAVE_INTERVAL', sbp_get_option( 'autosave_interval' ) * 60 );
176
+
177
  }
178
 
179
  private function dequeue_block_library() {
180
+
181
+ if ( ! sbp_get_option( 'dequeue_block_library' ) ) { return; }
182
+
183
  add_action( 'wp_enqueue_scripts', [ $this, 'dequeue_block_library_handle' ] );
184
+
185
  }
186
 
187
  public function dequeue_block_library_handle() {
188
+
189
  wp_dequeue_style( 'wp-block-library' );
190
  wp_dequeue_style( 'wp-block-library-theme' );
191
+
192
+ }
193
+
194
+ private function dequeue_global_styles() {
195
+
196
+ if ( ! sbp_get_option( 'dequeue_global_styles' ) ) { return; }
197
+
198
+ add_action( 'init', [ $this, 'dequeue_global_styles_handle' ], 9999 );
199
+
200
+ }
201
+
202
+ public function dequeue_global_styles_handle() {
203
+
204
+ remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
205
+ remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
206
+
207
  }
208
 
209
  private function disable_post_embeds() {
210
+
211
+ if ( ! sbp_get_option( 'disable_post_embeds' ) ) { return; }
212
+
213
  add_action( 'init', [ $this, 'remove_embeds_from_init' ], 9999 );
214
 
215
  }
216
 
217
  public function remove_embeds_from_init() {
218
+
219
  // Remove the REST API endpoint.
220
  remove_action( 'rest_api_init', 'wp_oembed_register_route' );
221
 
236
 
237
  // Remove filter of the oEmbed result before any HTTP requests are made.
238
  remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
239
+
240
  }
241
 
242
  public function disable_embeds_rewrites( $rules ) {
243
+
244
  foreach ( $rules as $rule => $rewrite ) {
245
  if ( false !== strpos( $rewrite, 'embed=true' ) ) {
246
  unset( $rules[ $rule ] );
248
  }
249
 
250
  return $rules;
 
251
 
 
 
252
  }
253
 
254
  private function heartbeat_settings() {
255
+
256
  switch ( sbp_get_option( 'heartbeat_settings' ) ) {
257
+
258
  case "optimized":
259
  add_filter( 'heartbeat_settings', [ $this, 'heartbeat_settings_handle' ] );
260
  break;
261
+
262
  case "disabled":
263
  add_action( 'wp_enqueue_scripts', [ $this, 'disable_heartbeat' ] );
264
  add_action( 'admin_enqueue_scripts', [ $this, 'disable_heartbeat' ] );
265
  break;
266
+
267
  }
 
268
 
 
 
269
  }
270
 
271
  public function heartbeat_settings_handle( $settings ) {
272
+
273
+ $settings['interval'] = 120;
274
 
275
  return $settings;
276
+
277
+ }
278
+
279
+ public function disable_heartbeat() {
280
+
281
+ wp_deregister_script( 'heartbeat' );
282
+
283
  }
284
 
285
  // Instant Page
286
  private function instant_page() {
287
+
288
+ if ( ! sbp_get_option( 'instant_page' ) ) { return; }
289
+
290
  add_action( 'wp_enqueue_scripts', [ $this, 'instant_page_handle' ] );
291
+
292
  }
293
 
294
  public function instant_page_handle() {
295
+
296
  wp_enqueue_script( 'sbp-ins-page', SBP_URL . 'public/js/inspage.js', false, '5.1.0', true );
297
+
298
  }
299
 
300
  private function dequeue_comment_reply_script() {
301
+
302
+ if ( ! sbp_get_option( 'dequeue_comment_reply_script' ) ) { return; }
303
+
304
  add_action( 'init', [ $this, 'comment_reply_script_handle' ] );
305
+
306
  }
307
 
308
  public function comment_reply_script_handle() {
309
+
310
  wp_deregister_script( 'comment-reply' );
311
+
312
  }
313
 
314
  private function declutter_shortlinks() {
315
+
316
+ if ( ! is_array( sbp_get_option( 'declutter_head' ) ) || ! sbp_get_option( 'declutter_head' )[ 'declutter_shortlinks' ] ) { return; }
317
+
318
  remove_action( 'wp_head', 'wp_shortlink_wp_head' );
319
+
320
  }
321
 
322
  private function declutter_adjacent_posts_links() {
323
+
324
+ if ( ! is_array( sbp_get_option( 'declutter_head' ) ) || ! sbp_get_option( 'declutter_head' )[ 'declutter_adjacent_posts_links' ] ) { return; }
325
+
326
  remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
327
+
328
  }
329
 
330
  private function declutter_wlw() {
331
+
332
+ if ( ! is_array( sbp_get_option( 'declutter_head' ) ) || ! sbp_get_option( 'declutter_head' )[ 'declutter_wlw' ] ) { return; }
333
+
334
  remove_action( 'wp_head', 'wlwmanifest_link' );
335
+
336
  }
337
 
338
  private function declutter_rsd() {
339
+
340
+ if ( ! is_array( sbp_get_option( 'declutter_head' ) ) || ! sbp_get_option( 'declutter_head' )[ 'declutter_rsd' ] ) { return; }
341
+
342
  remove_action( 'wp_head', 'rsd_link' );
343
+
344
  }
345
 
346
  private function declutter_rest_api_links() {
347
+
348
+ if ( ! is_array( sbp_get_option( 'declutter_head' ) ) || ! sbp_get_option( 'declutter_head' )[ 'declutter_rest_api_links' ] ) { return; }
349
+
350
  remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
351
+
352
  }
353
 
354
  private function declutter_feed_links() {
355
+
356
+ if ( ! is_array( sbp_get_option( 'declutter_head' ) ) || ! sbp_get_option( 'declutter_head' )[ 'declutter_feed_links' ] ) { return; }
357
+
358
  remove_action( 'wp_head', 'feed_links_extra', 3 );
359
  remove_action( 'wp_head', 'feed_links', 2 );
360
+
361
  }
362
 
363
  private function declutter_wp_version() {
364
+
365
+ if ( ! is_array( sbp_get_option( 'declutter_head' ) ) || ! sbp_get_option( 'declutter_head' )[ 'declutter_wp_version' ] ) { return; }
366
+
367
  remove_action( 'wp_head', 'wp_generator' );
368
+
369
  }
370
  }
includes/classes/class-sbp-wp-admin.php CHANGED
@@ -308,7 +308,7 @@ class SBP_WP_Admin {
308
 
309
  if ( version_compare( phpversion(), '7.0', '>=' ) ) { return; }
310
 
311
- SBP_Notice_Manager::display_notice( 'upgrade_php_notice', '<p><strong>' . SBP_PLUGIN_NAME . '</strong>: ' . __( 'You are using a really old PHP version! In a few months, Speed Booster Pack will stop working with PHP versions below 7.0, so we highly recommend you update PHP to the latest version (or ask your hosting company to do it).', 'speed-booster-pack' ) . '</p>', 'warning', false );
312
 
313
  }
314
 
@@ -360,6 +360,7 @@ class SBP_WP_Admin {
360
  ' . __( 'Other (please specify below)', 'speed-booster-pack' ) . '
361
  </label>
362
  <label>
 
363
  <textarea name="sbp_deactivation_description" class="widefat" placeholder="' . __( 'Details (optional)', 'speed-booster-pack' ) . '"></textarea>
364
  </label>
365
  <input type="hidden" name="sbp_site_url" value="' . site_url() . '" />
308
 
309
  if ( version_compare( phpversion(), '7.0', '>=' ) ) { return; }
310
 
311
+ SBP_Notice_Manager::display_notice( 'upgrade_php_notice', '<p><strong>' . SBP_PLUGIN_NAME . '</strong>: ' . __( 'You are using a really old PHP version! In a few months, Speed Booster Pack will stop working with PHP versions below 7.0, so we highly recommend you update PHP to the latest version (or ask your hosting company to do it).', 'speed-booster-pack' ) . '</p>', 'warning', true );
312
 
313
  }
314
 
360
  ' . __( 'Other (please specify below)', 'speed-booster-pack' ) . '
361
  </label>
362
  <label>
363
+ <p><strong>' . __( 'Useful, detailed feedback will be rewarded with up to €200 discounts in Optimocha services!', 'speed-booster-pack' ) . '</strong><br><a href="https://optimocha.com/feedback/?utm_source=speed-booster-pack-plugin&utm_medium=deactivation-survey&utm_campaign=rewards-for-feedback" rel="external noopener" target="_blank">' . __( 'Click here for more details.', 'speed-booster-pack' ) . '</a></p>
364
  <textarea name="sbp_deactivation_description" class="widefat" placeholder="' . __( 'Details (optional)', 'speed-booster-pack' ) . '"></textarea>
365
  </label>
366
  <input type="hidden" name="sbp_site_url" value="' . site_url() . '" />
includes/sbp-helpers.php CHANGED
@@ -392,12 +392,6 @@ if ( ! function_exists( 'sbp_sanitize_query_strings' ) ) {
392
  }
393
  }
394
 
395
- if ( ! function_exists( 'sbp_sanitize_special_characters' ) ) {
396
- function sbp_sanitize_special_characters( $param ) {
397
- return filter_var( $param, FILTER_SANITIZE_SPECIAL_CHARS );
398
- }
399
- }
400
-
401
  if ( ! function_exists( 'sbp_sanitize_boolean' ) ) {
402
  function sbp_sanitize_boolean( $value ) {
403
  return $value == '1' ? '1' : '0';
@@ -431,16 +425,6 @@ if ( ! function_exists( 'sbp_check_file_permissions' ) ) {
431
  }
432
  }
433
 
434
- if ( ! function_exists( 'sbp_sanitize_titles_in_array' ) ) {
435
- function sbp_sanitize_titles_in_array( $array ) {
436
- if ( is_array( $array ) ) {
437
- return array_map( 'sanitize_title', $array );
438
- }
439
-
440
- return $array;
441
- }
442
- }
443
-
444
  if ( ! function_exists( 'sbp_proper_parse_str' ) ) {
445
  function sbp_proper_parse_str( $str ) {
446
  # result array
@@ -473,14 +457,6 @@ if ( ! function_exists( 'sbp_proper_parse_str' ) ) {
473
  }
474
  }
475
 
476
- if ( ! function_exists( 'sbp_get_public_post_types' ) ) {
477
- function sbp_get_public_post_types() {
478
- $post_types = get_option( 'sbp_public_post_types' );
479
-
480
- return is_array( $post_types ) ? $post_types : [];
481
- }
482
- }
483
-
484
  if ( ! function_exists( 'sbp_get_wp_config_path' ) ) {
485
  function sbp_get_wp_config_path() {
486
  if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
@@ -500,15 +476,3 @@ if ( ! function_exists( 'sbp_is_wp_config_writable' ) ) {
500
  return file_exists( $wp_config_file ) && sbp_check_file_permissions( $wp_config_file );
501
  }
502
  }
503
-
504
- if ( ! function_exists( 'sbp_log' ) ) {
505
-
506
- function sbp_log( $message ) {
507
-
508
- if ( WP_DEBUG !== true ) { return; }
509
-
510
- error_log( print_r( $message, true ) );
511
-
512
- }
513
-
514
- }
392
  }
393
  }
394
 
 
 
 
 
 
 
395
  if ( ! function_exists( 'sbp_sanitize_boolean' ) ) {
396
  function sbp_sanitize_boolean( $value ) {
397
  return $value == '1' ? '1' : '0';
425
  }
426
  }
427
 
 
 
 
 
 
 
 
 
 
 
428
  if ( ! function_exists( 'sbp_proper_parse_str' ) ) {
429
  function sbp_proper_parse_str( $str ) {
430
  # result array
457
  }
458
  }
459
 
 
 
 
 
 
 
 
 
460
  if ( ! function_exists( 'sbp_get_wp_config_path' ) ) {
461
  function sbp_get_wp_config_path() {
462
  if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
476
  return file_exists( $wp_config_file ) && sbp_check_file_permissions( $wp_config_file );
477
  }
478
  }
 
 
 
 
 
 
 
 
 
 
 
 
public/class-speed-booster-pack-public.php CHANGED
@@ -57,7 +57,7 @@ class Speed_Booster_Pack_Public {
57
  * Basically a hook for functions which use output buffer
58
  */
59
  public function template_redirect() {
60
- if ( is_admin() || wp_doing_cron() || wp_doing_ajax() ) { return; }
61
  ob_start( [ $this, 'output_buffer' ] );
62
  }
63
 
57
  * Basically a hook for functions which use output buffer
58
  */
59
  public function template_redirect() {
60
+ // if ( is_admin() || wp_doing_cron() || wp_doing_ajax() ) { return; }
61
  ob_start( [ $this, 'output_buffer' ] );
62
  }
63
 
public/partials/speed-booster-pack-public-display.php DELETED
@@ -1,16 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Provide a public-facing view for the plugin
5
- *
6
- * This file is used to markup the public-facing aspects of the plugin.
7
- *
8
- * @link https://optimocha.com
9
- * @since 4.0.0
10
- *
11
- * @package Speed_Booster_Pack
12
- * @subpackage Speed_Booster_Pack/public/views
13
- */
14
- ?>
15
-
16
- <!-- This file should primarily consist of HTML with a little bit of PHP. -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
speed-booster-pack.php CHANGED
@@ -6,7 +6,7 @@
6
  * Plugin Name: Speed Booster Pack
7
  * Plugin URI: https://speedboosterpack.com
8
  * Description: PageSpeed optimization is vital for SEO: A faster website equals better conversions. Optimize & cache your site with this smart plugin!
9
- * Version: 4.5.1.1
10
  * Author: Optimocha
11
  * Author URI: https://optimocha.com
12
  * License: GPLv3 or later
@@ -32,7 +32,7 @@ define( 'SBP_PLUGIN_NAME', 'Speed Booster Pack' );
32
  /**
33
  * Current plugin version.
34
  */
35
- define( 'SBP_VERSION', '4.5.1.1' );
36
 
37
  /**
38
  * Plugin website URL.
@@ -175,7 +175,7 @@ function sbp_autoloader( $class_name ) {
175
  * @since 4.0.0
176
  */
177
  function run_speed_booster_pack() {
178
- if ( preg_match( '/(\.txt|\.pdf|\.xml|\.svg|\.ico|wp-json|\.gz|\/feed\/?)/', $_SERVER['REQUEST_URI'] ) ) {
179
  return;
180
  }
181
 
6
  * Plugin Name: Speed Booster Pack
7
  * Plugin URI: https://speedboosterpack.com
8
  * Description: PageSpeed optimization is vital for SEO: A faster website equals better conversions. Optimize & cache your site with this smart plugin!
9
+ * Version: 4.5.2
10
  * Author: Optimocha
11
  * Author URI: https://optimocha.com
12
  * License: GPLv3 or later
32
  /**
33
  * Current plugin version.
34
  */
35
+ define( 'SBP_VERSION', '4.5.2' );
36
 
37
  /**
38
  * Plugin website URL.
175
  * @since 4.0.0
176
  */
177
  function run_speed_booster_pack() {
178
+ if ( preg_match( '/(_wp-|\.txt|\.pdf|\.xml|\.svg|\.ico|wp-json|\.gz|\/feed\/?)/', $_SERVER['REQUEST_URI'] ) ) {
179
  return;
180
  }
181