Version Description
Download this release
Release Info
Developer | sstoqnov |
Plugin | SG Optimizer |
Version | 5.6.1 |
Comparing to | |
See all releases |
Code changes from version 5.6.0 to 5.6.1
- core/Cli/Cli.php +6 -0
- core/Cli/Cli_DNS_Prefetch.php +127 -0
- core/Cli/Cli_Heartbeat.php +78 -0
- core/Cli/Cli_Optimizer.php +44 -0
- core/Cli/Cli_Status.php +29 -23
- core/Combinator/Css_Combinator.php +3 -3
- core/Combinator/Js_Combinator.php +8 -6
- core/Emojis_Removal/Emojis_Removal.php +1 -1
- core/Front_End_Optimization/Front_End_Optimization.php +12 -12
- core/Heartbeat_Control/Heartbeat_Control.php +3 -3
- core/Helper/Helper.php +2 -2
- core/Lazy_Load/Lazy_Load_Videos.php +1 -1
- core/Memcache/Memcache.php +130 -0
- core/Minifier/Minify_Html.php +3 -3
- core/Rest/Rest_Helper_Environment.php +1 -1
- core/Ssl/Ssl.php +1 -1
- readme.txt +6 -1
- sg-cachepress.php +2 -2
- templates/memcached.tpl +10 -5
- vendor/composer/ClassLoader.php +1 -1
- vendor/sepia/po-parser/src/Sepia/PoParser.php +4 -4
core/Cli/Cli.php
CHANGED
@@ -40,6 +40,12 @@ class Cli {
|
|
40 |
|
41 |
// Status.
|
42 |
\WP_CLI::add_command( 'sg status', 'SiteGround_Optimizer\Cli\Cli_Status' );
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
|
45 |
}
|
40 |
|
41 |
// Status.
|
42 |
\WP_CLI::add_command( 'sg status', 'SiteGround_Optimizer\Cli\Cli_Status' );
|
43 |
+
|
44 |
+
// Heartbeat.
|
45 |
+
\WP_CLI::add_command( 'sg heartbeat', 'SiteGround_Optimizer\Cli\Cli_Heartbeat' );
|
46 |
+
|
47 |
+
// DNS Prefetch
|
48 |
+
\WP_CLI::add_command( 'sg dns-prefetch', 'SiteGround_Optimizer\Cli\Cli_DNS_Prefetch' );
|
49 |
}
|
50 |
|
51 |
}
|
core/Cli/Cli_DNS_Prefetch.php
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace SiteGround_Optimizer\Cli;
|
3 |
+
|
4 |
+
use SiteGround_Optimizer\Options\Options;
|
5 |
+
/**
|
6 |
+
* WP-CLI: wp sg dns-prefetch {setting} value.
|
7 |
+
*
|
8 |
+
* Run the `wp sg dns-prefetch {setting} {option} {value}` command to change the settgins of specific plugin functionality.
|
9 |
+
*
|
10 |
+
* @since 5.6.1
|
11 |
+
* @package Cli
|
12 |
+
* @subpackage Cli/Cli_DNS_Prefetch
|
13 |
+
*/
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Define the {@link Cli_DNS_Prefetch} class.
|
17 |
+
*
|
18 |
+
* @since 5.6.1
|
19 |
+
*/
|
20 |
+
class Cli_DNS_Prefetch {
|
21 |
+
/**
|
22 |
+
* Enable specific setting for SG Optimizer plugin.
|
23 |
+
*
|
24 |
+
* ## OPTIONS
|
25 |
+
*
|
26 |
+
* <setting>
|
27 |
+
* : Setting name.
|
28 |
+
* ---
|
29 |
+
* options:
|
30 |
+
* - urls
|
31 |
+
* - add
|
32 |
+
* - remove
|
33 |
+
* ---
|
34 |
+
* <value>
|
35 |
+
* : The url or urls list.
|
36 |
+
*/
|
37 |
+
public function __invoke( $args ) {
|
38 |
+
// Bail if the DNS Prefetch is disabled..
|
39 |
+
if ( ! Options::is_enabled( 'siteground_optimizer_dns_prefetch' ) ) {
|
40 |
+
return \WP_CLI::warning( 'DNS Prefetch is disabled, to activate it use `wp sg optimize dns-prefetch enable`' );
|
41 |
+
}
|
42 |
+
|
43 |
+
$url = ! empty( $args[1] ) ? preg_replace( '~(?:(?:https?:)?(?:\/\/)(?:www\.|(?!www)))?((?:.*?)\.(?:.*))~', '//$1', $args[1] ) : '';
|
44 |
+
|
45 |
+
switch ( $args[0] ) {
|
46 |
+
case 'urls':
|
47 |
+
return $this->list_prefetch();
|
48 |
+
case 'add':
|
49 |
+
return $this->add_url( $url );
|
50 |
+
case 'remove':
|
51 |
+
return $this->remove_url( $url );
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Get all urls for prefetching.
|
57 |
+
*
|
58 |
+
* @since 5.6.1
|
59 |
+
*/
|
60 |
+
public function list_prefetch() {
|
61 |
+
// Get all urls set for DNS-Prefetch.
|
62 |
+
$urls = get_option( 'siteground_optimizer_dns_prefetch_urls', false );
|
63 |
+
|
64 |
+
$message = 'The following urls are added for DNS Prefetching:';
|
65 |
+
|
66 |
+
if ( empty( $urls ) ) {
|
67 |
+
return \WP_CLI::warning( 'There are no urls added for dns-prefetching' );
|
68 |
+
}
|
69 |
+
|
70 |
+
foreach ( $urls as $url ) {
|
71 |
+
$message .= "\n" . $url;
|
72 |
+
}
|
73 |
+
|
74 |
+
return \WP_CLI::success( $message );
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Add url to DNS-Prefetch list.
|
79 |
+
*
|
80 |
+
* @since 5.6.1
|
81 |
+
*
|
82 |
+
* @param string $url URL to add.
|
83 |
+
*/
|
84 |
+
public function add_url( $url ) {
|
85 |
+
// Remove protocols.
|
86 |
+
$urls = get_option( 'siteground_optimizer_dns_prefetch_urls', array() );
|
87 |
+
|
88 |
+
// Check if the url is in the list.
|
89 |
+
if ( in_array( $url, $urls ) ) {
|
90 |
+
return \WP_CLI::warning( $url . ' is already added for DNS-Prefetching.' );
|
91 |
+
}
|
92 |
+
|
93 |
+
// Add the new url to the other urls.
|
94 |
+
array_push( $urls, $url );
|
95 |
+
|
96 |
+
// Update the option.
|
97 |
+
update_option( 'siteground_optimizer_dns_prefetch_urls', $urls );
|
98 |
+
|
99 |
+
return \WP_CLI::success( $url . ' was added to DNS-Prefetching list.' );
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Remove url from prefetching list.
|
104 |
+
*
|
105 |
+
* @since 5.6.1
|
106 |
+
*
|
107 |
+
* @param string $url URL to remove.
|
108 |
+
*/
|
109 |
+
public function remove_url( $url ) {
|
110 |
+
$urls = get_option( 'siteground_optimizer_dns_prefetch_urls', array() );
|
111 |
+
|
112 |
+
// Check if url is in the list and remove it.
|
113 |
+
if ( ! in_array( $url, $urls ) ) {
|
114 |
+
return \WP_CLI::warning( $url . ' is not added in DNS-Prefetching list.' );
|
115 |
+
}
|
116 |
+
|
117 |
+
// Remove the url from urls.
|
118 |
+
$key = array_search( $url, $urls );
|
119 |
+
unset( $urls[ $key ] );
|
120 |
+
|
121 |
+
// Update the option.
|
122 |
+
update_option( 'siteground_optimizer_dns_prefetch_urls', $urls );
|
123 |
+
|
124 |
+
return \WP_CLI::success( $url . ' was removed from DNN-Prefetching list' );
|
125 |
+
}
|
126 |
+
|
127 |
+
}
|
core/Cli/Cli_Heartbeat.php
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace SiteGround_Optimizer\Cli;
|
3 |
+
|
4 |
+
use SiteGround_Optimizer\Options\Options;
|
5 |
+
/**
|
6 |
+
* WP-CLI: wp sg heartbeat {setting} value.
|
7 |
+
*
|
8 |
+
* Run the `wp sg heartbeat {setting} {option} {frequency}` command to change the settgins of specific plugin functionality.
|
9 |
+
*
|
10 |
+
* @since 5.6.1
|
11 |
+
* @package Cli
|
12 |
+
* @subpackage Cli/Heartbeat
|
13 |
+
*/
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Define the {@link Cli_Heartbeat} class.
|
17 |
+
*
|
18 |
+
* @since 5.6.1
|
19 |
+
*/
|
20 |
+
class Cli_Heartbeat {
|
21 |
+
/**
|
22 |
+
* Enable specific setting for SG Optimizer plugin.
|
23 |
+
*
|
24 |
+
* ## OPTIONS
|
25 |
+
*
|
26 |
+
* <location>
|
27 |
+
* : Settging name.
|
28 |
+
* ---
|
29 |
+
* options:
|
30 |
+
* - frontend
|
31 |
+
* - dashboard
|
32 |
+
* - post
|
33 |
+
* ---
|
34 |
+
* <action>
|
35 |
+
* : Setting name.
|
36 |
+
* [--frequency=<frequency>]
|
37 |
+
* : Frequency for the Heartbeat.
|
38 |
+
*/
|
39 |
+
public function __invoke( $args, $assoc_args ) {
|
40 |
+
// Chek if Heartbeat optimization is enabled.
|
41 |
+
if ( ! Options::is_enabled( 'siteground_optimizer_heartbeat_control' ) ) {
|
42 |
+
return \WP_CLI::warning( 'Heartbeat optimization is disabled, to activate it use `wp sg optimize heartbeat-control enable`' );
|
43 |
+
}
|
44 |
+
|
45 |
+
// Set location based on cli command.
|
46 |
+
$status_option = 'siteground_optimizer_heartbeat_' . $args[0] . '_status';
|
47 |
+
$interval_option = 'siteground_optimizer_heartbeat_' . $args[0] . '_interval';
|
48 |
+
|
49 |
+
if ( 'enable' === $args[1] ) {
|
50 |
+
// Bail if the frequency param is missing.
|
51 |
+
if ( empty( $assoc_args['frequency'] ) ) {
|
52 |
+
\WP_CLI::error( 'Please, use the frequency argument with the command - wp sg heartbeat ' . $args[0] . ' enable --frequency=integer.' );
|
53 |
+
}
|
54 |
+
|
55 |
+
$frequency = intval( $assoc_args['frequency'] );
|
56 |
+
|
57 |
+
// Check if frequency is within the interval.
|
58 |
+
if ( $frequency < 15 || $frequency > 300 ) {
|
59 |
+
\WP_CLI::error( 'Frequency ' . $assoc_args['frequency'] . ' is not supported. Please choose a number between 15 and 300' );
|
60 |
+
}
|
61 |
+
|
62 |
+
// Set the interval frequency.
|
63 |
+
update_option( $interval_option, $frequency );
|
64 |
+
|
65 |
+
// Enable the heartbeat specific optimization.
|
66 |
+
$result = Options::enable_option( $status_option );
|
67 |
+
|
68 |
+
$message = 'Heartbeat optimization for ' . $args[0] . ' was set successfully.';
|
69 |
+
} elseif ( 'disable' === $args[1] ) {
|
70 |
+
// Enable the heartbeat specific optimization.
|
71 |
+
$result = Options::disable_option( $status_option );
|
72 |
+
|
73 |
+
$message = 'Heartbeat optimization for ' . $args[0] . ' was disabled';
|
74 |
+
}
|
75 |
+
|
76 |
+
return true === $result ? \WP_CLI::success( $message ) : \WP_CLI::error( $message );
|
77 |
+
}
|
78 |
+
}
|
core/Cli/Cli_Optimizer.php
CHANGED
@@ -47,6 +47,9 @@ class Cli_Optimizer {
|
|
47 |
* - google-fonts
|
48 |
* - browsercache
|
49 |
* - fix_insecure_content
|
|
|
|
|
|
|
50 |
* ---
|
51 |
* <action>
|
52 |
* : The action: enable\disable.
|
@@ -76,6 +79,8 @@ class Cli_Optimizer {
|
|
76 |
case 'google-fonts':
|
77 |
case 'webp':
|
78 |
case 'images':
|
|
|
|
|
79 |
return $this->optimize( $args[1], $args[0], $blog_id );
|
80 |
case 'lazyload':
|
81 |
return $this->optimize_lazyload( $args[1], $blog_id );
|
@@ -83,6 +88,8 @@ class Cli_Optimizer {
|
|
83 |
return $this->optimize_gzip( $args[1] );
|
84 |
case 'browsercache':
|
85 |
return $this->optimize_browsercache( $args[1] );
|
|
|
|
|
86 |
}
|
87 |
}
|
88 |
|
@@ -129,6 +136,8 @@ class Cli_Optimizer {
|
|
129 |
'images' => 'siteground_optimizer_optimize_images',
|
130 |
'webp' => 'siteground_optimizer_webp_support',
|
131 |
'fix_insecure_content' => 'siteground_optimizer_fix_insecure_content',
|
|
|
|
|
132 |
);
|
133 |
|
134 |
switch ( $action ) {
|
@@ -202,6 +211,41 @@ class Cli_Optimizer {
|
|
202 |
return \WP_CLI::success( 'Lazy Loading Images ' . ucwords( $action ) );
|
203 |
|
204 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
|
206 |
public function optimize_gzip( $action ) {
|
207 |
if ( 'enable' === $action ) {
|
47 |
* - google-fonts
|
48 |
* - browsercache
|
49 |
* - fix_insecure_content
|
50 |
+
* - database-optimization
|
51 |
+
* - dns-prefetch
|
52 |
+
* - heartbeat-control
|
53 |
* ---
|
54 |
* <action>
|
55 |
* : The action: enable\disable.
|
79 |
case 'google-fonts':
|
80 |
case 'webp':
|
81 |
case 'images':
|
82 |
+
case 'dns-prefetch':
|
83 |
+
case 'heartbeat-control':
|
84 |
return $this->optimize( $args[1], $args[0], $blog_id );
|
85 |
case 'lazyload':
|
86 |
return $this->optimize_lazyload( $args[1], $blog_id );
|
88 |
return $this->optimize_gzip( $args[1] );
|
89 |
case 'browsercache':
|
90 |
return $this->optimize_browsercache( $args[1] );
|
91 |
+
case 'database-optimization':
|
92 |
+
return $this->optimize_database( $args[1] );
|
93 |
}
|
94 |
}
|
95 |
|
136 |
'images' => 'siteground_optimizer_optimize_images',
|
137 |
'webp' => 'siteground_optimizer_webp_support',
|
138 |
'fix_insecure_content' => 'siteground_optimizer_fix_insecure_content',
|
139 |
+
'dns-prefetch' => 'siteground_optimizer_dns_prefetch',
|
140 |
+
'heartbeat-control' => 'siteground_optimizer_heartbeat_control',
|
141 |
);
|
142 |
|
143 |
switch ( $action ) {
|
211 |
return \WP_CLI::success( 'Lazy Loading Images ' . ucwords( $action ) );
|
212 |
|
213 |
}
|
214 |
+
|
215 |
+
/**
|
216 |
+
* Enable/disable Datbase Optimization
|
217 |
+
*
|
218 |
+
* @since 5.6.1
|
219 |
+
*
|
220 |
+
* @param string $action Enable/disable the option
|
221 |
+
*
|
222 |
+
*/
|
223 |
+
public function optimize_database ( $action ) {
|
224 |
+
if ( 'enable' === $action ) {
|
225 |
+
// Check if there is a scheduled event.
|
226 |
+
if ( ! wp_next_scheduled( 'siteground_optimizer_database_optimization_cron' ) ) {
|
227 |
+
// Set the event if it is not running.
|
228 |
+
$response = wp_schedule_event( time(), 'weekly', 'siteground_optimizer_database_optimization_cron' );
|
229 |
+
}
|
230 |
+
// Check if the event was scheduled.
|
231 |
+
if ( false === $response ) {
|
232 |
+
return \WP_CLI::error( 'Could not schedule the automatic optimization. Please, try again,' );
|
233 |
+
}
|
234 |
+
// Enable the option.
|
235 |
+
$result = Options::enable_option( 'siteground_optimizer_database_optimization' );
|
236 |
+
$type = true;
|
237 |
+
} else {
|
238 |
+
// Remove the scheduled event.
|
239 |
+
wp_clear_scheduled_hook( 'siteground_optimizer_database_optimization_cron' );
|
240 |
+
// Disable the option.
|
241 |
+
$result = Options::disable_option( 'siteground_optimizer_database_optimization' );
|
242 |
+
$type = false;
|
243 |
+
}
|
244 |
+
// Set the message.
|
245 |
+
$message = $this->option_service->get_response_message( $result, 'siteground_optimizer_database_optimization', $type );
|
246 |
+
|
247 |
+
return true === $result ? \WP_CLI::success( $message ) : \WP_CLI::error( $message );
|
248 |
+
}
|
249 |
|
250 |
public function optimize_gzip( $action ) {
|
251 |
if ( 'enable' === $action ) {
|
core/Cli/Cli_Status.php
CHANGED
@@ -51,6 +51,9 @@ class Cli_Status {
|
|
51 |
* - autoflush
|
52 |
* - dynamic-cache
|
53 |
* - google-fonts
|
|
|
|
|
|
|
54 |
* ---
|
55 |
*
|
56 |
* [--blog_id=<blog_id>]
|
@@ -75,29 +78,32 @@ class Cli_Status {
|
|
75 |
*/
|
76 |
public function get_status( $type, $blog_id = false ) {
|
77 |
$mapping = array(
|
78 |
-
'autoflush'
|
79 |
-
'dynamic-cache'
|
80 |
-
'memcache'
|
81 |
-
'ssl-fix'
|
82 |
-
'html'
|
83 |
-
'js'
|
84 |
-
'js-async'
|
85 |
-
'css'
|
86 |
-
'combine-css'
|
87 |
-
'querystring'
|
88 |
-
'emojis'
|
89 |
-
'images'
|
90 |
-
'lazyload_images'
|
91 |
-
'lazyload_gravatars'
|
92 |
-
'lazyload_thumbnails'
|
93 |
-
'lazyload_responsive'
|
94 |
-
'lazyload_textwidgets'
|
95 |
-
'ssl'
|
96 |
-
'gzip'
|
97 |
-
'browser-caching'
|
98 |
-
'google-fonts'
|
99 |
-
'combine-js'
|
100 |
-
'webp'
|
|
|
|
|
|
|
101 |
);
|
102 |
|
103 |
if ( ! array_key_exists( $type, $mapping ) ) {
|
51 |
* - autoflush
|
52 |
* - dynamic-cache
|
53 |
* - google-fonts
|
54 |
+
* - database-optimization
|
55 |
+
* - dns-prefetch
|
56 |
+
* - heartbeat-control
|
57 |
* ---
|
58 |
*
|
59 |
* [--blog_id=<blog_id>]
|
78 |
*/
|
79 |
public function get_status( $type, $blog_id = false ) {
|
80 |
$mapping = array(
|
81 |
+
'autoflush' => 'siteground_optimizer_autoflush_cache',
|
82 |
+
'dynamic-cache' => 'siteground_optimizer_enable_cache',
|
83 |
+
'memcache' => 'siteground_optimizer_enable_memcached',
|
84 |
+
'ssl-fix' => 'siteground_optimizer_fix_insecure_content',
|
85 |
+
'html' => 'siteground_optimizer_optimize_html',
|
86 |
+
'js' => 'siteground_optimizer_optimize_javascript',
|
87 |
+
'js-async' => 'siteground_optimizer_optimize_javascript_async',
|
88 |
+
'css' => 'siteground_optimizer_optimize_css',
|
89 |
+
'combine-css' => 'siteground_optimizer_combine_css',
|
90 |
+
'querystring' => 'siteground_optimizer_remove_query_strings',
|
91 |
+
'emojis' => 'siteground_optimizer_disable_emojis',
|
92 |
+
'images' => 'siteground_optimizer_optimize_images',
|
93 |
+
'lazyload_images' => 'siteground_optimizer_lazyload_images',
|
94 |
+
'lazyload_gravatars' => 'siteground_optimizer_lazyload_gravatars',
|
95 |
+
'lazyload_thumbnails' => 'siteground_optimizer_lazyload_thumbnails',
|
96 |
+
'lazyload_responsive' => 'siteground_optimizer_lazyload_responsive',
|
97 |
+
'lazyload_textwidgets' => 'siteground_optimizer_lazyload_textwidgets',
|
98 |
+
'ssl' => 'siteground_optimizer_ssl_enabled',
|
99 |
+
'gzip' => 'siteground_optimizer_enable_gzip_compression',
|
100 |
+
'browser-caching' => 'siteground_optimizer_enable_browser_caching',
|
101 |
+
'google-fonts' => 'siteground_optimizer_combine_google_fonts',
|
102 |
+
'combine-js' => 'siteground_optimizer_combine_javascript',
|
103 |
+
'webp' => 'siteground_optimizer_webp_support',
|
104 |
+
'database-optimization' => 'siteground_optimizer_database_optimization',
|
105 |
+
'dns-prefetch' => 'siteground_optimizer_dns_prefetch',
|
106 |
+
'heartbeat-control' => 'siteground_optimizer_heartbeat_control',
|
107 |
);
|
108 |
|
109 |
if ( ! array_key_exists( $type, $mapping ) ) {
|
core/Combinator/Css_Combinator.php
CHANGED
@@ -179,11 +179,11 @@ class Css_Combinator extends Abstract_Combinator {
|
|
179 |
* @return boolean True if the style is excluded, false otherwise.
|
180 |
*/
|
181 |
public function is_excluded( $style ) {
|
182 |
-
if ( false !== strpos( $style[0], 'media=' ) && ! preg_match( '/media=["\'](?:\s*|[^"\']*?\b(all|screen)\b[^"\']*?)["\']/i', $style[0] ) ) {
|
183 |
return true;
|
184 |
}
|
185 |
|
186 |
-
if ( false !== strpos( $style[0], 'only screen and' ) ) {
|
187 |
return true;
|
188 |
}
|
189 |
|
@@ -193,7 +193,7 @@ class Css_Combinator extends Abstract_Combinator {
|
|
193 |
// Bail if it's an external style.
|
194 |
if (
|
195 |
@strpos( Helper::get_home_url(), $host ) === false &&
|
196 |
-
! strpos( $style[2], 'wp-includes' )
|
197 |
) {
|
198 |
return true;
|
199 |
}
|
179 |
* @return boolean True if the style is excluded, false otherwise.
|
180 |
*/
|
181 |
public function is_excluded( $style ) {
|
182 |
+
if ( false !== @strpos( $style[0], 'media=' ) && ! preg_match( '/media=["\'](?:\s*|[^"\']*?\b(all|screen)\b[^"\']*?)["\']/i', $style[0] ) ) {
|
183 |
return true;
|
184 |
}
|
185 |
|
186 |
+
if ( false !== @strpos( $style[0], 'only screen and' ) ) {
|
187 |
return true;
|
188 |
}
|
189 |
|
193 |
// Bail if it's an external style.
|
194 |
if (
|
195 |
@strpos( Helper::get_home_url(), $host ) === false &&
|
196 |
+
! @strpos( $style[2], 'wp-includes' )
|
197 |
) {
|
198 |
return true;
|
199 |
}
|
core/Combinator/Js_Combinator.php
CHANGED
@@ -16,6 +16,8 @@ class Js_Combinator extends Abstract_Combinator {
|
|
16 |
* @var array Array containing all excluded inline content.
|
17 |
*/
|
18 |
private $excluded_inline_content = array(
|
|
|
|
|
19 |
'var DTGS_NONCE_FRONTEND',
|
20 |
'revslider_ajax_call_front',
|
21 |
'#wpb_wcma_menu_',
|
@@ -671,7 +673,7 @@ class Js_Combinator extends Abstract_Combinator {
|
|
671 |
|
672 |
if (
|
673 |
@strpos( Helper::get_home_url(), parse_url( $src, PHP_URL_HOST ) ) === false &&
|
674 |
-
! strpos( $src, 'wp-includes' )
|
675 |
) {
|
676 |
$is_external = true;
|
677 |
}
|
@@ -727,13 +729,13 @@ class Js_Combinator extends Abstract_Combinator {
|
|
727 |
}
|
728 |
|
729 |
// Bail if the script doesn't a src attribute.
|
730 |
-
if ( false !== strpos( $data['attrs'], 'src=' ) ) {
|
731 |
return true;
|
732 |
}
|
733 |
|
734 |
// Bail if the type is not js/es.
|
735 |
if (
|
736 |
-
strpos( $data['attrs'], 'type' ) !== false &&
|
737 |
! preg_match( '/type\s*=\s*["\']?(?:text|application)\/(?:(?:x\-)?javascript|ecmascript)["\']?/i', $data['attrs'] )
|
738 |
) {
|
739 |
return true;
|
@@ -749,7 +751,7 @@ class Js_Combinator extends Abstract_Combinator {
|
|
749 |
|
750 |
// Do not combine excluded content.
|
751 |
foreach ( $excluded_inline_content as $excluded_content ) {
|
752 |
-
if ( false !== strpos( $data['content'], $excluded_content ) ) {
|
753 |
return true;
|
754 |
}
|
755 |
}
|
@@ -758,7 +760,7 @@ class Js_Combinator extends Abstract_Combinator {
|
|
758 |
$move_after_scripts = apply_filters( 'sgo_javascript_combine_exclude_move_after', $this->move_after_excludes );
|
759 |
|
760 |
foreach ( $move_after_scripts as $move_after_script ) {
|
761 |
-
if ( false !== strpos( $data['content'], $move_after_script ) ) {
|
762 |
$this->move_after[] = $data[0];
|
763 |
return true;
|
764 |
}
|
@@ -782,7 +784,7 @@ class Js_Combinator extends Abstract_Combinator {
|
|
782 |
if ( true === $external ) {
|
783 |
$excluded_paths = apply_filters( 'sgo_javascript_combine_excluded_external_paths', $this->excluded_paths );
|
784 |
foreach ( $excluded_paths as $path ) {
|
785 |
-
if ( false !== strpos( $src, $path ) ) {
|
786 |
return true;
|
787 |
}
|
788 |
}
|
16 |
* @var array Array containing all excluded inline content.
|
17 |
*/
|
18 |
private $excluded_inline_content = array(
|
19 |
+
'window.opener.location.href="',
|
20 |
+
'var __CONFIG__',
|
21 |
'var DTGS_NONCE_FRONTEND',
|
22 |
'revslider_ajax_call_front',
|
23 |
'#wpb_wcma_menu_',
|
673 |
|
674 |
if (
|
675 |
@strpos( Helper::get_home_url(), parse_url( $src, PHP_URL_HOST ) ) === false &&
|
676 |
+
! @strpos( $src, 'wp-includes' )
|
677 |
) {
|
678 |
$is_external = true;
|
679 |
}
|
729 |
}
|
730 |
|
731 |
// Bail if the script doesn't a src attribute.
|
732 |
+
if ( false !== @strpos( $data['attrs'], 'src=' ) ) {
|
733 |
return true;
|
734 |
}
|
735 |
|
736 |
// Bail if the type is not js/es.
|
737 |
if (
|
738 |
+
@strpos( $data['attrs'], 'type' ) !== false &&
|
739 |
! preg_match( '/type\s*=\s*["\']?(?:text|application)\/(?:(?:x\-)?javascript|ecmascript)["\']?/i', $data['attrs'] )
|
740 |
) {
|
741 |
return true;
|
751 |
|
752 |
// Do not combine excluded content.
|
753 |
foreach ( $excluded_inline_content as $excluded_content ) {
|
754 |
+
if ( false !== @strpos( $data['content'], $excluded_content ) ) {
|
755 |
return true;
|
756 |
}
|
757 |
}
|
760 |
$move_after_scripts = apply_filters( 'sgo_javascript_combine_exclude_move_after', $this->move_after_excludes );
|
761 |
|
762 |
foreach ( $move_after_scripts as $move_after_script ) {
|
763 |
+
if ( false !== @strpos( $data['content'], $move_after_script ) ) {
|
764 |
$this->move_after[] = $data[0];
|
765 |
return true;
|
766 |
}
|
784 |
if ( true === $external ) {
|
785 |
$excluded_paths = apply_filters( 'sgo_javascript_combine_excluded_external_paths', $this->excluded_paths );
|
786 |
foreach ( $excluded_paths as $path ) {
|
787 |
+
if ( false !== @strpos( $src, $path ) ) {
|
788 |
return true;
|
789 |
}
|
790 |
}
|
core/Emojis_Removal/Emojis_Removal.php
CHANGED
@@ -65,7 +65,7 @@ class Emojis_Removal {
|
|
65 |
// Strip out any URLs referencing the WordPress.org emoji location.
|
66 |
foreach ( $urls as $key => $url ) {
|
67 |
// Continue with other urls if the url doens't match.
|
68 |
-
if ( strpos( $url, 'https://s.w.org/images/core/emoji/' ) === false ) {
|
69 |
continue;
|
70 |
}
|
71 |
|
65 |
// Strip out any URLs referencing the WordPress.org emoji location.
|
66 |
foreach ( $urls as $key => $url ) {
|
67 |
// Continue with other urls if the url doens't match.
|
68 |
+
if ( @strpos( $url, 'https://s.w.org/images/core/emoji/' ) === false ) {
|
69 |
continue;
|
70 |
}
|
71 |
|
core/Front_End_Optimization/Front_End_Optimization.php
CHANGED
@@ -232,7 +232,7 @@ class Front_End_Optimization {
|
|
232 |
$new = preg_replace( '~^https?:\/\/|^\/\/~', $replace, $original );
|
233 |
|
234 |
// Get the filepath to original file.
|
235 |
-
if ( strpos( $new, $home_url ) !== false ) {
|
236 |
$original_filepath = str_replace( $home_url, ABSPATH, $new );
|
237 |
} else {
|
238 |
$original_filepath = untrailingslashit( ABSPATH ) . $new;
|
@@ -295,7 +295,7 @@ class Front_End_Optimization {
|
|
295 |
* @param string $src Script src.
|
296 |
*/
|
297 |
public function add_async_attribute( $tag, $handle, $src ) {
|
298 |
-
if ( strpos( $src, 'siteground-async=1' ) !== false ) {
|
299 |
$new_src = remove_query_arg( 'siteground-async', $src );
|
300 |
// return the tag with the async attribute.
|
301 |
return str_replace(
|
@@ -445,7 +445,7 @@ class Front_End_Optimization {
|
|
445 |
foreach ( $items->to_do as $index => $handle ) {
|
446 |
if (
|
447 |
in_array( $handle, $excludes ) || // Do not include excluded assets.
|
448 |
-
! is_bool( strpos( $handle, 'siteground' ) ) ||
|
449 |
! is_string( $items->registered[ $handle ]->src ) // Do not include asset without source.
|
450 |
) {
|
451 |
continue;
|
@@ -484,7 +484,7 @@ class Front_End_Optimization {
|
|
484 |
'group' => ! empty( $matches[2] ) ? substr( $matches[2], 0, -1 ) : __( 'others', 'siteground-optimizer' ), // Get the group name.
|
485 |
'name' => ! empty( $matches[3] ) ? $this->get_plugin_info( $matches[3] ) : false, // The name of the parent( plugin or theme name ).
|
486 |
'in_footer' => $in_footer, // Is loaded in the footer.
|
487 |
-
'is_minified' => strpos( $item->src, '.min.' ) === false ? 0 : 1, // Is minified.
|
488 |
);
|
489 |
|
490 |
$data['group_title'] = empty( $data['name'] ) ? $data['group'] : $data['group'] . ': ' . $data['name'];
|
@@ -508,7 +508,7 @@ class Front_End_Optimization {
|
|
508 |
|
509 |
// Check if the path is presented in the active plugins.
|
510 |
foreach ( $active_plugins as $plugin_file ) {
|
511 |
-
if ( false === strpos( $plugin_file, $path ) ) {
|
512 |
continue;
|
513 |
}
|
514 |
|
@@ -539,13 +539,13 @@ class Front_End_Optimization {
|
|
539 |
|
540 |
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
|
541 |
$is_mobile = false;
|
542 |
-
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // many mobile devices (all iPhone, iPad, etc.)
|
543 |
-
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false
|
544 |
-
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false
|
545 |
-
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false
|
546 |
-
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false
|
547 |
-
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false
|
548 |
-
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) !== false ) {
|
549 |
$is_mobile = true;
|
550 |
} else {
|
551 |
$is_mobile = false;
|
232 |
$new = preg_replace( '~^https?:\/\/|^\/\/~', $replace, $original );
|
233 |
|
234 |
// Get the filepath to original file.
|
235 |
+
if ( @strpos( $new, $home_url ) !== false ) {
|
236 |
$original_filepath = str_replace( $home_url, ABSPATH, $new );
|
237 |
} else {
|
238 |
$original_filepath = untrailingslashit( ABSPATH ) . $new;
|
295 |
* @param string $src Script src.
|
296 |
*/
|
297 |
public function add_async_attribute( $tag, $handle, $src ) {
|
298 |
+
if ( @strpos( $src, 'siteground-async=1' ) !== false ) {
|
299 |
$new_src = remove_query_arg( 'siteground-async', $src );
|
300 |
// return the tag with the async attribute.
|
301 |
return str_replace(
|
445 |
foreach ( $items->to_do as $index => $handle ) {
|
446 |
if (
|
447 |
in_array( $handle, $excludes ) || // Do not include excluded assets.
|
448 |
+
! is_bool( @strpos( $handle, 'siteground' ) ) ||
|
449 |
! is_string( $items->registered[ $handle ]->src ) // Do not include asset without source.
|
450 |
) {
|
451 |
continue;
|
484 |
'group' => ! empty( $matches[2] ) ? substr( $matches[2], 0, -1 ) : __( 'others', 'siteground-optimizer' ), // Get the group name.
|
485 |
'name' => ! empty( $matches[3] ) ? $this->get_plugin_info( $matches[3] ) : false, // The name of the parent( plugin or theme name ).
|
486 |
'in_footer' => $in_footer, // Is loaded in the footer.
|
487 |
+
'is_minified' => @strpos( $item->src, '.min.' ) === false ? 0 : 1, // Is minified.
|
488 |
);
|
489 |
|
490 |
$data['group_title'] = empty( $data['name'] ) ? $data['group'] : $data['group'] . ': ' . $data['name'];
|
508 |
|
509 |
// Check if the path is presented in the active plugins.
|
510 |
foreach ( $active_plugins as $plugin_file ) {
|
511 |
+
if ( false === @strpos( $plugin_file, $path ) ) {
|
512 |
continue;
|
513 |
}
|
514 |
|
539 |
|
540 |
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
|
541 |
$is_mobile = false;
|
542 |
+
} elseif ( @strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // many mobile devices (all iPhone, iPad, etc.)
|
543 |
+
|| @strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false
|
544 |
+
|| @strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false
|
545 |
+
|| @strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false
|
546 |
+
|| @strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false
|
547 |
+
|| @strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false
|
548 |
+
|| @strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) !== false ) {
|
549 |
$is_mobile = true;
|
550 |
} else {
|
551 |
$is_mobile = false;
|
core/Heartbeat_Control/Heartbeat_Control.php
CHANGED
@@ -17,7 +17,7 @@ class Heartbeat_Control {
|
|
17 |
return;
|
18 |
}
|
19 |
|
20 |
-
if ( strpos( $_SERVER['REQUEST_URI'], '/wp-admin/admin-ajax.php' ) ) {
|
21 |
return;
|
22 |
}
|
23 |
|
@@ -103,7 +103,7 @@ class Heartbeat_Control {
|
|
103 |
|
104 |
switch ( $location ) {
|
105 |
case 'dashboard':
|
106 |
-
return ( is_admin() && false === strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post.php' ) );
|
107 |
break;
|
108 |
|
109 |
case 'frontend':
|
@@ -111,7 +111,7 @@ class Heartbeat_Control {
|
|
111 |
break;
|
112 |
|
113 |
case 'post':
|
114 |
-
return strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post.php' );
|
115 |
break;
|
116 |
default:
|
117 |
return false;
|
17 |
return;
|
18 |
}
|
19 |
|
20 |
+
if ( @strpos( $_SERVER['REQUEST_URI'], '/wp-admin/admin-ajax.php' ) ) {
|
21 |
return;
|
22 |
}
|
23 |
|
103 |
|
104 |
switch ( $location ) {
|
105 |
case 'dashboard':
|
106 |
+
return ( is_admin() && false === @strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post.php' ) );
|
107 |
break;
|
108 |
|
109 |
case 'frontend':
|
111 |
break;
|
112 |
|
113 |
case 'post':
|
114 |
+
return @strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post.php' );
|
115 |
break;
|
116 |
default:
|
117 |
return false;
|
core/Helper/Helper.php
CHANGED
@@ -153,7 +153,7 @@ class Helper {
|
|
153 |
defined( 'REST_REQUEST' ) && REST_REQUEST ||
|
154 |
(
|
155 |
isset( $_GET['rest_route'] ) &&
|
156 |
-
0 === strpos( trim( $_GET['rest_route'], '\\/' ), $prefix, 0 )
|
157 |
)
|
158 |
) {
|
159 |
return true;
|
@@ -189,7 +189,7 @@ class Helper {
|
|
189 |
$vendor = str_replace( '\\', '/', SiteGround_Optimizer\DIR . '/vendor' );
|
190 |
|
191 |
// Do nothing for errors inside of the plugins directory.
|
192 |
-
if ( strpos( $error_file, $vendor ) !== false ) {
|
193 |
return true;
|
194 |
}
|
195 |
|
153 |
defined( 'REST_REQUEST' ) && REST_REQUEST ||
|
154 |
(
|
155 |
isset( $_GET['rest_route'] ) &&
|
156 |
+
0 === @strpos( trim( $_GET['rest_route'], '\\/' ), $prefix, 0 )
|
157 |
)
|
158 |
) {
|
159 |
return true;
|
189 |
$vendor = str_replace( '\\', '/', SiteGround_Optimizer\DIR . '/vendor' );
|
190 |
|
191 |
// Do nothing for errors inside of the plugins directory.
|
192 |
+
if ( @strpos( $error_file, $vendor ) !== false ) {
|
193 |
return true;
|
194 |
}
|
195 |
|
core/Lazy_Load/Lazy_Load_Videos.php
CHANGED
@@ -27,7 +27,7 @@ class Lazy_Load_Videos extends Abstract_Lazy_Load {
|
|
27 |
* @var array
|
28 |
*/
|
29 |
public $patterns = array(
|
30 |
-
'/(<video
|
31 |
);
|
32 |
|
33 |
/**
|
27 |
* @var array
|
28 |
*/
|
29 |
public $patterns = array(
|
30 |
+
'/(<video[^>]+)(src)=["|\']((?!data).*?)["|\']/i',
|
31 |
);
|
32 |
|
33 |
/**
|
core/Memcache/Memcache.php
CHANGED
@@ -17,6 +17,24 @@ class Memcache {
|
|
17 |
*/
|
18 |
const IP = '127.0.0.1';
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
/**
|
21 |
* The constructor.
|
22 |
*
|
@@ -26,6 +44,10 @@ class Memcache {
|
|
26 |
if ( ! defined( 'WP_CLI' ) ) {
|
27 |
add_action( 'load-toplevel_page_sg-cachepress', array( $this, 'status_healthcheck' ) );
|
28 |
}
|
|
|
|
|
|
|
|
|
29 |
}
|
30 |
|
31 |
/**
|
@@ -241,4 +263,112 @@ class Memcache {
|
|
241 |
|
242 |
return true;
|
243 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
}
|
17 |
*/
|
18 |
const IP = '127.0.0.1';
|
19 |
|
20 |
+
/**
|
21 |
+
* Memcached excludes filename.
|
22 |
+
*
|
23 |
+
* @since 5.6.1
|
24 |
+
*
|
25 |
+
* @var string Path to the excludes filename.
|
26 |
+
*/
|
27 |
+
const EXCLUDES_FILENAME = WP_CONTENT_DIR . '/.sgo-memcache-excludes';
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Memcached crashed filename.
|
31 |
+
*
|
32 |
+
* @since 5.6.1
|
33 |
+
*
|
34 |
+
* @var string Path to the crashed filename.
|
35 |
+
*/
|
36 |
+
const CRASHED_FILENAME = WP_CONTENT_DIR . '/memcache-crashed.txt';
|
37 |
+
|
38 |
/**
|
39 |
* The constructor.
|
40 |
*
|
44 |
if ( ! defined( 'WP_CLI' ) ) {
|
45 |
add_action( 'load-toplevel_page_sg-cachepress', array( $this, 'status_healthcheck' ) );
|
46 |
}
|
47 |
+
|
48 |
+
add_action( 'admin_init', array( $this, 'prepare_memcache_excludes' ) );
|
49 |
+
|
50 |
+
add_filter( 'pre_cache_alloptions', array( $this, 'maybe_exclude' ) );
|
51 |
}
|
52 |
|
53 |
/**
|
263 |
|
264 |
return true;
|
265 |
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Check if there are any options that should be excluded from the memcache.
|
269 |
+
*
|
270 |
+
* @since 5.6.1
|
271 |
+
*
|
272 |
+
* @param array $alloptions Array of all autoload options.
|
273 |
+
*
|
274 |
+
* @return array Array without excluded autload options.
|
275 |
+
*/
|
276 |
+
public function maybe_exclude( $alloptions ) {
|
277 |
+
// Bail if the excludes files doesn't exists.
|
278 |
+
if ( ! file_exists( self::EXCLUDES_FILENAME ) ) {
|
279 |
+
return $alloptions;
|
280 |
+
}
|
281 |
+
|
282 |
+
// Get the content of the excludes file.
|
283 |
+
$excludes = $this->get_excludes_content();
|
284 |
+
|
285 |
+
// Bail if the excludes file is empty.
|
286 |
+
if ( empty( $excludes ) ) {
|
287 |
+
return $alloptions;
|
288 |
+
}
|
289 |
+
|
290 |
+
foreach ( $excludes as $option ) {
|
291 |
+
// Bail if the option name is empty.
|
292 |
+
if ( empty( $option ) ) {
|
293 |
+
continue;
|
294 |
+
}
|
295 |
+
|
296 |
+
// Unset the option from the cache.
|
297 |
+
unset( $alloptions[ $option ] );
|
298 |
+
}
|
299 |
+
|
300 |
+
// Return the options.
|
301 |
+
return $alloptions;
|
302 |
+
}
|
303 |
+
|
304 |
+
/**
|
305 |
+
* Prepare memcache excludes.
|
306 |
+
*
|
307 |
+
* @since 5.6.1
|
308 |
+
*/
|
309 |
+
public function prepare_memcache_excludes() {
|
310 |
+
global $wp_filesystem;
|
311 |
+
// Bail if the crashed file doesn't exists.
|
312 |
+
if ( ! $wp_filesystem->exists( self::CRASHED_FILENAME ) ) {
|
313 |
+
return;
|
314 |
+
}
|
315 |
+
|
316 |
+
// Remove the error flag file.
|
317 |
+
$wp_filesystem->delete( self::CRASHED_FILENAME );
|
318 |
+
|
319 |
+
// Create the excludes file if doesn't exists.
|
320 |
+
if ( ! file_exists( self::EXCLUDES_FILENAME ) ) {
|
321 |
+
$wp_filesystem->touch( self::EXCLUDES_FILENAME );
|
322 |
+
}
|
323 |
+
|
324 |
+
// Get the content of the excludes file.
|
325 |
+
$excludes = $this->get_excludes_content();
|
326 |
+
|
327 |
+
// Load the wpdb.
|
328 |
+
global $wpdb;
|
329 |
+
|
330 |
+
// Get the biggest option from the database.
|
331 |
+
$result = $wpdb->get_results( "
|
332 |
+
SELECT option_name
|
333 |
+
FROM $wpdb->options
|
334 |
+
WHERE autoload = 'yes'
|
335 |
+
AND option_name NOT IN ( " . implode( array_map( function( $item ) {
|
336 |
+
return "'" . $item . "'";
|
337 |
+
}, $excludes ), ',') . " )
|
338 |
+
ORDER BY LENGTH(option_value) DESC
|
339 |
+
LIMIT 1"
|
340 |
+
);
|
341 |
+
|
342 |
+
// Bail if the query doesn't return results.
|
343 |
+
if ( empty( $result[0]->option_name ) ) {
|
344 |
+
return;
|
345 |
+
}
|
346 |
+
|
347 |
+
// Add the option to the exclude list.
|
348 |
+
$excludes[] = $result[0]->option_name;
|
349 |
+
|
350 |
+
// Open the exclude list file.
|
351 |
+
$handle = fopen( self::EXCLUDES_FILENAME, 'a' );
|
352 |
+
|
353 |
+
// Write the option to the exclude list.
|
354 |
+
fputcsv( $handle, array( $result[0]->option_name ) );
|
355 |
+
|
356 |
+
// Close the file.
|
357 |
+
fclose( $handle );
|
358 |
+
}
|
359 |
+
|
360 |
+
/**
|
361 |
+
* Get the content of the excludes file.
|
362 |
+
*
|
363 |
+
* @since 5.6.1
|
364 |
+
*
|
365 |
+
* @return array Content of the excludes file in array.
|
366 |
+
*/
|
367 |
+
public function get_excludes_content() {
|
368 |
+
// Get the content of the excludes file.
|
369 |
+
$excludes_content = file_get_contents( self::EXCLUDES_FILENAME );
|
370 |
+
|
371 |
+
// Convert the csv to array.
|
372 |
+
return str_getcsv( $excludes_content, "\n" );
|
373 |
+
}
|
374 |
}
|
core/Minifier/Minify_Html.php
CHANGED
@@ -90,7 +90,7 @@ class Minify_Html {
|
|
90 |
public function process()
|
91 |
{
|
92 |
if ($this->_isXhtml === null) {
|
93 |
-
$this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
|
94 |
}
|
95 |
|
96 |
$this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
|
@@ -164,7 +164,7 @@ class Minify_Html {
|
|
164 |
|
165 |
protected function _commentCB($m)
|
166 |
{
|
167 |
-
return (0 === strpos($m[1], '[') || false !== strpos($m[1], '<!['))
|
168 |
? $m[0]
|
169 |
: '';
|
170 |
}
|
@@ -256,7 +256,7 @@ class Minify_Html {
|
|
256 |
|
257 |
protected function _removeCdata($str)
|
258 |
{
|
259 |
-
return (false !== strpos($str, '<![CDATA['))
|
260 |
? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str)
|
261 |
: $str;
|
262 |
}
|
90 |
public function process()
|
91 |
{
|
92 |
if ($this->_isXhtml === null) {
|
93 |
+
$this->_isXhtml = (false !== @strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
|
94 |
}
|
95 |
|
96 |
$this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
|
164 |
|
165 |
protected function _commentCB($m)
|
166 |
{
|
167 |
+
return (0 === @strpos($m[1], '[') || false !== @strpos($m[1], '<!['))
|
168 |
? $m[0]
|
169 |
: '';
|
170 |
}
|
256 |
|
257 |
protected function _removeCdata($str)
|
258 |
{
|
259 |
+
return (false !== @strpos($str, '<![CDATA['))
|
260 |
? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str)
|
261 |
: $str;
|
262 |
}
|
core/Rest/Rest_Helper_Environment.php
CHANGED
@@ -87,7 +87,7 @@ class Rest_Helper_Environment extends Rest_Helper {
|
|
87 |
|
88 |
// Check if the event is currently runing.
|
89 |
if ( ! wp_next_scheduled( 'siteground_optimizer_database_optimization_cron' ) ) {
|
90 |
-
|
91 |
}
|
92 |
|
93 |
wp_send_json(
|
87 |
|
88 |
// Check if the event is currently runing.
|
89 |
if ( ! wp_next_scheduled( 'siteground_optimizer_database_optimization_cron' ) ) {
|
90 |
+
wp_schedule_event( time(), 'weekly', 'siteground_optimizer_database_optimization_cron' );
|
91 |
}
|
92 |
|
93 |
wp_send_json(
|
core/Ssl/Ssl.php
CHANGED
@@ -142,7 +142,7 @@ class Ssl {
|
|
142 |
if ( ! is_multisite() ) {
|
143 |
$parsed = parse_url( get_option( 'siteurl' ) );
|
144 |
|
145 |
-
if ( strpos( $parsed['host'], 'www.' ) === 0 ) {
|
146 |
$replacements['replace'] = "RewriteCond %{HTTP_HOST} !^www\. [NC]\n RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]";
|
147 |
}
|
148 |
|
142 |
if ( ! is_multisite() ) {
|
143 |
$parsed = parse_url( get_option( 'siteurl' ) );
|
144 |
|
145 |
+
if ( @strpos( $parsed['host'], 'www.' ) === 0 ) {
|
146 |
$replacements['replace'] = "RewriteCond %{HTTP_HOST} !^www\. [NC]\n RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]";
|
147 |
}
|
148 |
|
readme.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
=== SG Optimizer ===
|
2 |
-
Contributors: Hristo Sg, siteground, sstoqnov
|
3 |
Tags: nginx, caching, speed, memcache, memcached, performance, siteground, nginx, supercacher
|
4 |
Requires at least: 4.7
|
5 |
Requires PHP: 5.5
|
@@ -208,6 +208,11 @@ Our plugin uses a cookie in order to function properly. It does not store person
|
|
208 |
|
209 |
== Changelog ==
|
210 |
|
|
|
|
|
|
|
|
|
|
|
211 |
= Version 5.6.0 =
|
212 |
* Added Heartbeat Control
|
213 |
* Added Database Optimization
|
1 |
=== SG Optimizer ===
|
2 |
+
Contributors: Hristo Sg, siteground, sstoqnov, stoyangeorgiev
|
3 |
Tags: nginx, caching, speed, memcache, memcached, performance, siteground, nginx, supercacher
|
4 |
Requires at least: 4.7
|
5 |
Requires PHP: 5.5
|
208 |
|
209 |
== Changelog ==
|
210 |
|
211 |
+
= Version 5.6.1 =
|
212 |
+
* Second stage of Memcached improvements applied
|
213 |
+
* Added WP-CLI control for heartbeat, dns-prefetching and db optimizations
|
214 |
+
* Fixed non-critical notices while using PHP 7.3
|
215 |
+
|
216 |
= Version 5.6.0 =
|
217 |
* Added Heartbeat Control
|
218 |
* Added Database Optimization
|
sg-cachepress.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
* Plugin Name: SG Optimizer
|
11 |
* Plugin URI: https://siteground.com
|
12 |
* Description: This plugin will link your WordPress application with all the performance optimizations provided by SiteGround
|
13 |
-
* Version: 5.6.
|
14 |
* Author: SiteGround
|
15 |
* Author URI: https://www.siteground.com
|
16 |
* Text Domain: sg-cachepress
|
@@ -31,7 +31,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|
31 |
|
32 |
// Define version constant.
|
33 |
if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) {
|
34 |
-
define( __NAMESPACE__ . '\VERSION', '5.6.
|
35 |
}
|
36 |
|
37 |
// Define slug constant.
|
10 |
* Plugin Name: SG Optimizer
|
11 |
* Plugin URI: https://siteground.com
|
12 |
* Description: This plugin will link your WordPress application with all the performance optimizations provided by SiteGround
|
13 |
+
* Version: 5.6.1
|
14 |
* Author: SiteGround
|
15 |
* Author URI: https://www.siteground.com
|
16 |
* Text Domain: sg-cachepress
|
31 |
|
32 |
// Define version constant.
|
33 |
if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) {
|
34 |
+
define( __NAMESPACE__ . '\VERSION', '5.6.1' );
|
35 |
}
|
36 |
|
37 |
// Define slug constant.
|
templates/memcached.tpl
CHANGED
@@ -251,10 +251,6 @@ class WP_Object_Cache {
|
|
251 |
$this->cache[$key] = $value;
|
252 |
}
|
253 |
|
254 |
-
if ( $mc->getResultCode() === Memcached::RES_E2BIG ) {
|
255 |
-
@rename( __FILE__, dirname( __FILE__ ) . '/object-cache-crashed.php' );
|
256 |
-
}
|
257 |
-
|
258 |
@ ++$this->stats['get'];
|
259 |
$this->group_ops[$group][] = "get $id";
|
260 |
|
@@ -354,6 +350,15 @@ class WP_Object_Cache {
|
|
354 |
$mc =& $this->get_mc( $group );
|
355 |
$result = $mc->set( $key, $data, $expire );
|
356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
return $result;
|
358 |
}
|
359 |
|
@@ -395,7 +400,7 @@ class WP_Object_Cache {
|
|
395 |
'delete'=> 'red'
|
396 |
);
|
397 |
|
398 |
-
$cmd = substr( $line, 0, strpos( $line, ' ' ) );
|
399 |
|
400 |
$cmd2 = "<span style='color:" . esc_attr( $colors[ $cmd ] ) . "'>" . esc_html( $cmd ) . "</span>";
|
401 |
|
251 |
$this->cache[$key] = $value;
|
252 |
}
|
253 |
|
|
|
|
|
|
|
|
|
254 |
@ ++$this->stats['get'];
|
255 |
$this->group_ops[$group][] = "get $id";
|
256 |
|
350 |
$mc =& $this->get_mc( $group );
|
351 |
$result = $mc->set( $key, $data, $expire );
|
352 |
|
353 |
+
if ( $mc->getResultCode() === Memcached::RES_E2BIG ) {
|
354 |
+
if ( 'options' === $group ) {
|
355 |
+
touch( WP_CONTENT_DIR . '/memcache-crashed.txt' );
|
356 |
+
} else {
|
357 |
+
error_log( 'Memcache Key: ' . $key );
|
358 |
+
@rename( __FILE__, dirname( __FILE__ ) . '/object-cache-crashed.php' );
|
359 |
+
}
|
360 |
+
}
|
361 |
+
|
362 |
return $result;
|
363 |
}
|
364 |
|
400 |
'delete'=> 'red'
|
401 |
);
|
402 |
|
403 |
+
$cmd = substr( $line, 0, @strpos( $line, ' ' ) );
|
404 |
|
405 |
$cmd2 = "<span style='color:" . esc_attr( $colors[ $cmd ] ) . "'>" . esc_html( $cmd ) . "</span>";
|
406 |
|
vendor/composer/ClassLoader.php
CHANGED
@@ -408,7 +408,7 @@ class ClassLoader
|
|
408 |
|
409 |
if (isset($this->prefixesPsr0[$first])) {
|
410 |
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
411 |
-
if (0 === strpos($class, $prefix)) {
|
412 |
foreach ($dirs as $dir) {
|
413 |
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
414 |
return $file;
|
408 |
|
409 |
if (isset($this->prefixesPsr0[$first])) {
|
410 |
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
411 |
+
if (0 === @strpos($class, $prefix)) {
|
412 |
foreach ($dirs as $dir) {
|
413 |
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
414 |
return $file;
|
vendor/sepia/po-parser/src/Sepia/PoParser.php
CHANGED
@@ -226,7 +226,7 @@ class PoParser
|
|
226 |
|
227 |
$entry[$key] = isset($entry[$key]) ? $entry[$key] : array('msgid' => array(), 'msgstr' => array());
|
228 |
|
229 |
-
if (strpos($key, 'obsolete') !== false) {
|
230 |
$entry['obsolete'] = true;
|
231 |
switch ($tmpKey) {
|
232 |
case 'msgid':
|
@@ -293,7 +293,7 @@ class PoParser
|
|
293 |
break;
|
294 |
|
295 |
default:
|
296 |
-
if (strpos($key, 'msgstr[') !== false) {
|
297 |
// translated-string-case-n
|
298 |
$state = $key;
|
299 |
$entry[$state][] = $data;
|
@@ -303,7 +303,7 @@ class PoParser
|
|
303 |
case 'msgctxt':
|
304 |
case 'msgid':
|
305 |
case 'msgid_plural':
|
306 |
-
case (strpos($state, 'msgstr[') !== false):
|
307 |
if (is_string($entry[$state])) {
|
308 |
// Convert it to array
|
309 |
$entry[$state] = array($entry[$state]);
|
@@ -631,7 +631,7 @@ class PoParser
|
|
631 |
if ($isPlural) {
|
632 |
$noTranslation = true;
|
633 |
foreach ($entry as $key => $value) {
|
634 |
-
if (strpos($key, 'msgstr[') === false) {
|
635 |
continue;
|
636 |
}
|
637 |
$output .= $key." ";
|
226 |
|
227 |
$entry[$key] = isset($entry[$key]) ? $entry[$key] : array('msgid' => array(), 'msgstr' => array());
|
228 |
|
229 |
+
if (@strpos($key, 'obsolete') !== false) {
|
230 |
$entry['obsolete'] = true;
|
231 |
switch ($tmpKey) {
|
232 |
case 'msgid':
|
293 |
break;
|
294 |
|
295 |
default:
|
296 |
+
if (@strpos($key, 'msgstr[') !== false) {
|
297 |
// translated-string-case-n
|
298 |
$state = $key;
|
299 |
$entry[$state][] = $data;
|
303 |
case 'msgctxt':
|
304 |
case 'msgid':
|
305 |
case 'msgid_plural':
|
306 |
+
case (@strpos($state, 'msgstr[') !== false):
|
307 |
if (is_string($entry[$state])) {
|
308 |
// Convert it to array
|
309 |
$entry[$state] = array($entry[$state]);
|
631 |
if ($isPlural) {
|
632 |
$noTranslation = true;
|
633 |
foreach ($entry as $key => $value) {
|
634 |
+
if (@strpos($key, 'msgstr[') === false) {
|
635 |
continue;
|
636 |
}
|
637 |
$output .= $key." ";
|