Version Description
- Added Scheduled Database Optimizations.
- Added support for redis object caching on A2 Hosting.
Download this release
Release Info
Developer | a2hosting |
Plugin | A2 Optimized WP |
Version | 2.1.4 |
Comparing to | |
See all releases |
Code changes from version 2.1.3.10.3 to 2.1.4
- A2_Optimized_Cache.php +136 -90
- A2_Optimized_DB_Optimizations.php +226 -0
- A2_Optimized_Optimizations.php +150 -101
- A2_Optimized_OptionsManager.php +278 -132
- A2_Optimized_Plugin.php +70 -62
- a2-optimized.php +13 -11
- readme.txt +16 -2
A2_Optimized_Cache.php
CHANGED
@@ -39,59 +39,59 @@ final class A2_Optimized_Cache {
|
|
39 |
|
40 |
public function __construct() {
|
41 |
// init hooks
|
42 |
-
add_action( 'init',
|
43 |
-
add_action( 'init',
|
44 |
-
add_action( 'init',
|
45 |
|
46 |
// public clear cache hooks
|
47 |
-
add_action( 'a2opt_cache_clear_complete_cache',
|
48 |
-
add_action( 'a2opt_cache_clear_site_cache',
|
49 |
-
add_action( 'a2opt_cache_clear_site_cache_by_blog_id',
|
50 |
-
add_action( 'a2opt_cache_clear_page_cache_by_post_id',
|
51 |
-
add_action( 'a2opt_cache_clear_page_cache_by_url',
|
52 |
|
53 |
// system clear cache hooks
|
54 |
-
add_action( '_core_updated_successfully',
|
55 |
-
add_action( 'upgrader_process_complete',
|
56 |
-
add_action( 'switch_theme',
|
57 |
-
add_action( 'permalink_structure_changed',
|
58 |
-
add_action( 'activated_plugin',
|
59 |
-
add_action( 'deactivated_plugin',
|
60 |
-
add_action( 'save_post',
|
61 |
-
add_action( 'post_updated',
|
62 |
-
add_action( 'wp_trash_post',
|
63 |
-
add_action( 'transition_post_status',
|
64 |
-
add_action( 'comment_post',
|
65 |
-
add_action( 'edit_comment',
|
66 |
-
add_action( 'transition_comment_status',
|
67 |
|
68 |
// third party clear cache hooks
|
69 |
-
add_action( 'autoptimize_action_cachepurged',
|
70 |
-
add_action( 'woocommerce_product_set_stock',
|
71 |
-
add_action( 'woocommerce_variation_set_stock',
|
72 |
-
add_action( 'woocommerce_product_set_stock_status',
|
73 |
-
add_action( 'woocommerce_variation_set_stock_status',
|
74 |
|
75 |
// multisite hooks
|
76 |
-
add_action( 'wp_initialize_site',
|
77 |
-
add_action( 'wp_uninitialize_site',
|
78 |
|
79 |
// settings hooks
|
80 |
-
add_action( 'permalink_structure_changed',
|
81 |
-
add_action( 'add_option_a2opt_cache',
|
82 |
-
add_action( 'update_option_a2opt_cache',
|
83 |
|
84 |
// admin bar hook
|
85 |
-
add_action( 'admin_bar_menu',
|
86 |
|
87 |
// admin interface hooks
|
88 |
if ( is_admin() ) {
|
89 |
// settings
|
90 |
-
add_action( 'admin_init',
|
91 |
// notices
|
92 |
-
add_action( 'admin_notices',
|
93 |
-
add_action( 'admin_notices',
|
94 |
-
add_action( 'network_admin_notices',
|
95 |
}
|
96 |
}
|
97 |
|
@@ -214,7 +214,7 @@ final class A2_Optimized_Cache {
|
|
214 |
}
|
215 |
|
216 |
// get defined settings, fall back to empty array if not found
|
217 |
-
$old_option_value = get_option( 'a2opt-cache',
|
218 |
|
219 |
// update default system settings
|
220 |
$old_option_value = wp_parse_args( self::get_default_settings( 'system' ), $old_option_value );
|
@@ -226,7 +226,7 @@ final class A2_Optimized_Cache {
|
|
226 |
update_option( 'a2opt-cache', $new_option_value );
|
227 |
|
228 |
// create settings file if action has not been registered for hook yet, like when in activation hook
|
229 |
-
if ( has_action( 'update_option_a2opt_cache',
|
230 |
A2_Optimized_Cache_Disk::create_settings_file( $new_option_value );
|
231 |
}
|
232 |
|
@@ -279,8 +279,8 @@ final class A2_Optimized_Cache {
|
|
279 |
* @return array $callback_return returned value(s) from callback function
|
280 |
*/
|
281 |
|
282 |
-
private static function each_site($network, $callback, $callback_params =
|
283 |
-
$callback_return =
|
284 |
|
285 |
if ( $network ) {
|
286 |
$blog_ids = self::get_blog_ids();
|
@@ -335,7 +335,7 @@ final class A2_Optimized_Cache {
|
|
335 |
*/
|
336 |
|
337 |
private static function get_blog_ids() {
|
338 |
-
$blog_ids =
|
339 |
|
340 |
if ( is_multisite() ) {
|
341 |
global $wpdb;
|
@@ -369,7 +369,7 @@ final class A2_Optimized_Cache {
|
|
369 |
*/
|
370 |
|
371 |
public static function get_blog_paths() {
|
372 |
-
$blog_paths =
|
373 |
|
374 |
if ( is_multisite() ) {
|
375 |
global $wpdb;
|
@@ -454,16 +454,16 @@ final class A2_Optimized_Cache {
|
|
454 |
*/
|
455 |
|
456 |
private static function get_default_settings($settings_type = null) {
|
457 |
-
$system_default_settings =
|
458 |
'version' => (string) A2OPT_VERSION,
|
459 |
'permalink_structure' => (string) self::get_permalink_structure(),
|
460 |
-
|
461 |
|
462 |
if ( $settings_type === 'system' ) {
|
463 |
return $system_default_settings;
|
464 |
}
|
465 |
|
466 |
-
$user_default_settings =
|
467 |
'cache_expires' => 0,
|
468 |
'cache_expiry_time' => 0,
|
469 |
'clear_site_cache_on_saved_post' => 1,
|
@@ -477,7 +477,7 @@ final class A2_Optimized_Cache {
|
|
477 |
'excluded_cookies' => '',
|
478 |
'minify_html' => 1,
|
479 |
'minify_inline_css_js' => 0,
|
480 |
-
|
481 |
|
482 |
// merge default settings
|
483 |
$default_settings = wp_parse_args( $user_default_settings, $system_default_settings );
|
@@ -502,31 +502,31 @@ final class A2_Optimized_Cache {
|
|
502 |
|
503 |
// add "Clear Network Cache" or "Clear Site Cache" button in admin bar
|
504 |
$wp_admin_bar->add_menu(
|
505 |
-
|
506 |
'id' => 'a2opt_cache_clear_cache',
|
507 |
-
'href' => wp_nonce_url( add_query_arg(
|
508 |
'_cache' => 'a2-optimized-wp',
|
509 |
'_action' => 'clear',
|
510 |
-
|
511 |
'parent' => 'top-secondary',
|
512 |
'title' => '<span class="ab-item">' . $title . '</span>',
|
513 |
-
'meta' =>
|
514 |
-
|
515 |
);
|
516 |
|
517 |
// add "Clear Page Cache" button in admin bar
|
518 |
if ( ! is_admin() ) {
|
519 |
$wp_admin_bar->add_menu(
|
520 |
-
|
521 |
'id' => 'a2opt_cache_clear_page_cache',
|
522 |
-
'href' => wp_nonce_url( add_query_arg(
|
523 |
'_cache' => 'a2-optimized-wp',
|
524 |
'_action' => 'clearurl',
|
525 |
-
|
526 |
'parent' => 'top-secondary',
|
527 |
'title' => '<span class="ab-item">' . esc_html__( 'Clear Page Cache', 'a2-optimized-wp' ) . '</span>',
|
528 |
-
'meta' =>
|
529 |
-
|
530 |
);
|
531 |
}
|
532 |
}
|
@@ -664,7 +664,7 @@ final class A2_Optimized_Cache {
|
|
664 |
|
665 |
public static function on_transition_post_status($new_status, $old_status, $post) {
|
666 |
// if any published post type status has changed
|
667 |
-
if ( $old_status === 'publish' && in_array( $new_status,
|
668 |
self::clear_cache_on_post_save( $post->ID );
|
669 |
}
|
670 |
}
|
@@ -759,7 +759,7 @@ final class A2_Optimized_Cache {
|
|
759 |
self::each_site( is_multisite(), 'self::clear_site_cache' );
|
760 |
|
761 |
// delete cache size transient(s)
|
762 |
-
self::each_site( is_multisite(), 'delete_transient',
|
763 |
}
|
764 |
|
765 |
/**
|
@@ -821,7 +821,7 @@ final class A2_Optimized_Cache {
|
|
821 |
foreach ( $taxonomies as $taxonomy ) {
|
822 |
if ( wp_count_terms( $taxonomy ) > 0 ) {
|
823 |
// get terms attached to post
|
824 |
-
$term_ids = wp_get_post_terms( $post_id, $taxonomy,
|
825 |
foreach ( $term_ids as $term_id ) {
|
826 |
$term_archives_url = get_term_link( (int) $term_id, $taxonomy );
|
827 |
// validate URL and ensure it does not have a query string
|
@@ -1086,8 +1086,10 @@ final class A2_Optimized_Cache {
|
|
1086 |
*/
|
1087 |
|
1088 |
public static function register_settings() {
|
1089 |
-
register_setting( 'a2opt-cache', 'a2opt-cache',
|
1090 |
-
register_setting( 'a2opt-cache', '
|
|
|
|
|
1091 |
}
|
1092 |
|
1093 |
/**
|
@@ -1128,7 +1130,7 @@ final class A2_Optimized_Cache {
|
|
1128 |
return;
|
1129 |
}
|
1130 |
|
1131 |
-
$validated_settings =
|
1132 |
'cache_expires' => (int) ( ! empty( $settings['cache_expires'] ) ),
|
1133 |
'cache_expiry_time' => (int) @$settings['cache_expiry_time'],
|
1134 |
'clear_site_cache_on_saved_post' => (int) ( ! empty( $settings['clear_site_cache_on_saved_post'] ) ),
|
@@ -1142,7 +1144,7 @@ final class A2_Optimized_Cache {
|
|
1142 |
'excluded_cookies' => (string) self::validate_regex( @$settings['excluded_cookies'] ),
|
1143 |
'minify_html' => (int) ( ! empty( $settings['minify_html'] ) ),
|
1144 |
'minify_inline_css_js' => (int) ( ! empty( $settings['minify_inline_css_js'] ) ),
|
1145 |
-
|
1146 |
|
1147 |
// add default system settings
|
1148 |
$validated_settings = wp_parse_args( $validated_settings, self::get_default_settings( 'system' ) );
|
@@ -1153,9 +1155,15 @@ final class A2_Optimized_Cache {
|
|
1153 |
set_transient( self::get_cache_cleared_transient_name(), 1 );
|
1154 |
}
|
1155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1156 |
return $validated_settings;
|
1157 |
}
|
1158 |
-
|
1159 |
/**
|
1160 |
* validate memcached settings
|
1161 |
*
|
@@ -1163,38 +1171,76 @@ final class A2_Optimized_Cache {
|
|
1163 |
* @return string $validated_settings validated settings
|
1164 |
*/
|
1165 |
|
1166 |
-
public static function
|
|
|
|
|
|
|
1167 |
$options_manager = new A2_Optimized_OptionsManager;
|
1168 |
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
if (
|
1177 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1178 |
}
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1182 |
}
|
1183 |
-
}
|
1184 |
-
$instances[] = array( $node, $port, 1 );
|
1185 |
|
1186 |
-
|
1187 |
-
$memcached_available = $memcached->getStats();
|
1188 |
-
if ($memcached_available) {
|
1189 |
-
$options_manager->write_wp_config();
|
1190 |
-
delete_option('a2_optimized_memcached_invalid');
|
1191 |
-
} else {
|
1192 |
-
update_option('a2_optimized_memcached_invalid', 'Unable to connect to Memcached Server');
|
1193 |
-
}
|
1194 |
-
} else {
|
1195 |
-
update_option('a2_optimized_memcached_invalid', 'Missing Memcached extension');
|
1196 |
}
|
1197 |
|
1198 |
-
return $
|
1199 |
}
|
1200 |
}
|
39 |
|
40 |
public function __construct() {
|
41 |
// init hooks
|
42 |
+
add_action( 'init', [ 'A2_Optimized_Cache_Engine', 'start' ] );
|
43 |
+
add_action( 'init', [ __CLASS__, 'process_clear_cache_request' ] );
|
44 |
+
add_action( 'init', [ __CLASS__, 'register_textdomain' ] );
|
45 |
|
46 |
// public clear cache hooks
|
47 |
+
add_action( 'a2opt_cache_clear_complete_cache', [ __CLASS__, 'clear_complete_cache' ] );
|
48 |
+
add_action( 'a2opt_cache_clear_site_cache', [ __CLASS__, 'clear_site_cache' ] );
|
49 |
+
add_action( 'a2opt_cache_clear_site_cache_by_blog_id', [ __CLASS__, 'clear_site_cache_by_blog_id' ] );
|
50 |
+
add_action( 'a2opt_cache_clear_page_cache_by_post_id', [ __CLASS__, 'clear_page_cache_by_post_id' ] );
|
51 |
+
add_action( 'a2opt_cache_clear_page_cache_by_url', [ __CLASS__, 'clear_page_cache_by_url' ] );
|
52 |
|
53 |
// system clear cache hooks
|
54 |
+
add_action( '_core_updated_successfully', [ __CLASS__, 'clear_complete_cache' ] );
|
55 |
+
add_action( 'upgrader_process_complete', [ __CLASS__, 'on_upgrade' ], 10, 2 );
|
56 |
+
add_action( 'switch_theme', [ __CLASS__, 'clear_complete_cache' ] );
|
57 |
+
add_action( 'permalink_structure_changed', [ __CLASS__, 'clear_site_cache' ] );
|
58 |
+
add_action( 'activated_plugin', [ __CLASS__, 'on_plugin_activation_deactivation' ], 10, 2 );
|
59 |
+
add_action( 'deactivated_plugin', [ __CLASS__, 'on_plugin_activation_deactivation' ], 10, 2 );
|
60 |
+
add_action( 'save_post', [ __CLASS__, 'on_save_post' ] );
|
61 |
+
add_action( 'post_updated', [ __CLASS__, 'on_post_updated' ], 10, 3 );
|
62 |
+
add_action( 'wp_trash_post', [ __CLASS__, 'on_trash_post' ] );
|
63 |
+
add_action( 'transition_post_status', [ __CLASS__, 'on_transition_post_status' ], 10, 3 );
|
64 |
+
add_action( 'comment_post', [ __CLASS__, 'on_comment_post' ], 99, 2 );
|
65 |
+
add_action( 'edit_comment', [ __CLASS__, 'on_edit_comment' ], 10, 2 );
|
66 |
+
add_action( 'transition_comment_status', [ __CLASS__, 'on_transition_comment_status' ], 10, 3 );
|
67 |
|
68 |
// third party clear cache hooks
|
69 |
+
add_action( 'autoptimize_action_cachepurged', [ __CLASS__, 'clear_complete_cache' ] );
|
70 |
+
add_action( 'woocommerce_product_set_stock', [ __CLASS__, 'on_woocommerce_stock_update' ] );
|
71 |
+
add_action( 'woocommerce_variation_set_stock', [ __CLASS__, 'on_woocommerce_stock_update' ] );
|
72 |
+
add_action( 'woocommerce_product_set_stock_status', [ __CLASS__, 'on_woocommerce_stock_update' ] );
|
73 |
+
add_action( 'woocommerce_variation_set_stock_status', [ __CLASS__, 'on_woocommerce_stock_update' ] );
|
74 |
|
75 |
// multisite hooks
|
76 |
+
add_action( 'wp_initialize_site', [ __CLASS__, 'install_later' ] );
|
77 |
+
add_action( 'wp_uninitialize_site', [ __CLASS__, 'uninstall_later' ] );
|
78 |
|
79 |
// settings hooks
|
80 |
+
add_action( 'permalink_structure_changed', [ __CLASS__, 'update_backend' ] );
|
81 |
+
add_action( 'add_option_a2opt_cache', [ __CLASS__, 'on_update_backend' ], 10, 2 );
|
82 |
+
add_action( 'update_option_a2opt_cache', [ __CLASS__, 'on_update_backend' ], 10, 2 );
|
83 |
|
84 |
// admin bar hook
|
85 |
+
add_action( 'admin_bar_menu', [ __CLASS__, 'add_admin_bar_items' ], 90 );
|
86 |
|
87 |
// admin interface hooks
|
88 |
if ( is_admin() ) {
|
89 |
// settings
|
90 |
+
add_action( 'admin_init', [ __CLASS__, 'register_settings' ] );
|
91 |
// notices
|
92 |
+
add_action( 'admin_notices', [ __CLASS__, 'requirements_check' ] );
|
93 |
+
add_action( 'admin_notices', [ __CLASS__, 'cache_cleared_notice' ] );
|
94 |
+
add_action( 'network_admin_notices', [ __CLASS__, 'cache_cleared_notice' ] );
|
95 |
}
|
96 |
}
|
97 |
|
214 |
}
|
215 |
|
216 |
// get defined settings, fall back to empty array if not found
|
217 |
+
$old_option_value = get_option( 'a2opt-cache', [] );
|
218 |
|
219 |
// update default system settings
|
220 |
$old_option_value = wp_parse_args( self::get_default_settings( 'system' ), $old_option_value );
|
226 |
update_option( 'a2opt-cache', $new_option_value );
|
227 |
|
228 |
// create settings file if action has not been registered for hook yet, like when in activation hook
|
229 |
+
if ( has_action( 'update_option_a2opt_cache', [ __CLASS__, 'on_update_backend' ] ) === false ) {
|
230 |
A2_Optimized_Cache_Disk::create_settings_file( $new_option_value );
|
231 |
}
|
232 |
|
279 |
* @return array $callback_return returned value(s) from callback function
|
280 |
*/
|
281 |
|
282 |
+
private static function each_site($network, $callback, $callback_params = []) {
|
283 |
+
$callback_return = [];
|
284 |
|
285 |
if ( $network ) {
|
286 |
$blog_ids = self::get_blog_ids();
|
335 |
*/
|
336 |
|
337 |
private static function get_blog_ids() {
|
338 |
+
$blog_ids = [ 1 ];
|
339 |
|
340 |
if ( is_multisite() ) {
|
341 |
global $wpdb;
|
369 |
*/
|
370 |
|
371 |
public static function get_blog_paths() {
|
372 |
+
$blog_paths = [ '/' ];
|
373 |
|
374 |
if ( is_multisite() ) {
|
375 |
global $wpdb;
|
454 |
*/
|
455 |
|
456 |
private static function get_default_settings($settings_type = null) {
|
457 |
+
$system_default_settings = [
|
458 |
'version' => (string) A2OPT_VERSION,
|
459 |
'permalink_structure' => (string) self::get_permalink_structure(),
|
460 |
+
];
|
461 |
|
462 |
if ( $settings_type === 'system' ) {
|
463 |
return $system_default_settings;
|
464 |
}
|
465 |
|
466 |
+
$user_default_settings = [
|
467 |
'cache_expires' => 0,
|
468 |
'cache_expiry_time' => 0,
|
469 |
'clear_site_cache_on_saved_post' => 1,
|
477 |
'excluded_cookies' => '',
|
478 |
'minify_html' => 1,
|
479 |
'minify_inline_css_js' => 0,
|
480 |
+
];
|
481 |
|
482 |
// merge default settings
|
483 |
$default_settings = wp_parse_args( $user_default_settings, $system_default_settings );
|
502 |
|
503 |
// add "Clear Network Cache" or "Clear Site Cache" button in admin bar
|
504 |
$wp_admin_bar->add_menu(
|
505 |
+
[
|
506 |
'id' => 'a2opt_cache_clear_cache',
|
507 |
+
'href' => wp_nonce_url( add_query_arg( [
|
508 |
'_cache' => 'a2-optimized-wp',
|
509 |
'_action' => 'clear',
|
510 |
+
] ), 'a2opt_cache_clear_cache_nonce' ),
|
511 |
'parent' => 'top-secondary',
|
512 |
'title' => '<span class="ab-item">' . $title . '</span>',
|
513 |
+
'meta' => [ 'title' => $title ],
|
514 |
+
]
|
515 |
);
|
516 |
|
517 |
// add "Clear Page Cache" button in admin bar
|
518 |
if ( ! is_admin() ) {
|
519 |
$wp_admin_bar->add_menu(
|
520 |
+
[
|
521 |
'id' => 'a2opt_cache_clear_page_cache',
|
522 |
+
'href' => wp_nonce_url( add_query_arg( [
|
523 |
'_cache' => 'a2-optimized-wp',
|
524 |
'_action' => 'clearurl',
|
525 |
+
] ), 'a2opt_cache_clear_cache_nonce' ),
|
526 |
'parent' => 'top-secondary',
|
527 |
'title' => '<span class="ab-item">' . esc_html__( 'Clear Page Cache', 'a2-optimized-wp' ) . '</span>',
|
528 |
+
'meta' => [ 'title' => esc_html__( 'Clear Page Cache', 'a2-optimized-wp' ) ],
|
529 |
+
]
|
530 |
);
|
531 |
}
|
532 |
}
|
664 |
|
665 |
public static function on_transition_post_status($new_status, $old_status, $post) {
|
666 |
// if any published post type status has changed
|
667 |
+
if ( $old_status === 'publish' && in_array( $new_status, [ 'future', 'draft', 'pending', 'private' ] ) ) {
|
668 |
self::clear_cache_on_post_save( $post->ID );
|
669 |
}
|
670 |
}
|
759 |
self::each_site( is_multisite(), 'self::clear_site_cache' );
|
760 |
|
761 |
// delete cache size transient(s)
|
762 |
+
self::each_site( is_multisite(), 'delete_transient', [ self::get_cache_size_transient_name() ] );
|
763 |
}
|
764 |
|
765 |
/**
|
821 |
foreach ( $taxonomies as $taxonomy ) {
|
822 |
if ( wp_count_terms( $taxonomy ) > 0 ) {
|
823 |
// get terms attached to post
|
824 |
+
$term_ids = wp_get_post_terms( $post_id, $taxonomy, [ 'fields' => 'ids' ] );
|
825 |
foreach ( $term_ids as $term_id ) {
|
826 |
$term_archives_url = get_term_link( (int) $term_id, $taxonomy );
|
827 |
// validate URL and ensure it does not have a query string
|
1086 |
*/
|
1087 |
|
1088 |
public static function register_settings() {
|
1089 |
+
register_setting( 'a2opt-cache', 'a2opt-cache', [ __CLASS__, 'validate_settings' ] );
|
1090 |
+
register_setting( 'a2opt-cache', 'a2_optimized_objectcache_type' );
|
1091 |
+
register_setting( 'a2opt-cache', 'a2_optimized_memcached_server', [ __CLASS__, 'validate_object_cache' ]);
|
1092 |
+
register_setting( 'a2opt-cache', 'a2_optimized_redis_server', [ __CLASS__, 'validate_object_cache' ]);
|
1093 |
}
|
1094 |
|
1095 |
/**
|
1130 |
return;
|
1131 |
}
|
1132 |
|
1133 |
+
$validated_settings = [
|
1134 |
'cache_expires' => (int) ( ! empty( $settings['cache_expires'] ) ),
|
1135 |
'cache_expiry_time' => (int) @$settings['cache_expiry_time'],
|
1136 |
'clear_site_cache_on_saved_post' => (int) ( ! empty( $settings['clear_site_cache_on_saved_post'] ) ),
|
1144 |
'excluded_cookies' => (string) self::validate_regex( @$settings['excluded_cookies'] ),
|
1145 |
'minify_html' => (int) ( ! empty( $settings['minify_html'] ) ),
|
1146 |
'minify_inline_css_js' => (int) ( ! empty( $settings['minify_inline_css_js'] ) ),
|
1147 |
+
];
|
1148 |
|
1149 |
// add default system settings
|
1150 |
$validated_settings = wp_parse_args( $validated_settings, self::get_default_settings( 'system' ) );
|
1155 |
set_transient( self::get_cache_cleared_transient_name(), 1 );
|
1156 |
}
|
1157 |
|
1158 |
+
// check if database optimizations should be executed
|
1159 |
+
if ( ! empty( $settings['apply_db_optimizations_on_saved_settings'] ) ) {
|
1160 |
+
$a2_db_optimizations = new A2_Optimized_DBOptimizations;
|
1161 |
+
$a2_db_optimizations->execute_optimizations();
|
1162 |
+
}
|
1163 |
+
|
1164 |
return $validated_settings;
|
1165 |
}
|
1166 |
+
|
1167 |
/**
|
1168 |
* validate memcached settings
|
1169 |
*
|
1171 |
* @return string $validated_settings validated settings
|
1172 |
*/
|
1173 |
|
1174 |
+
public static function validate_object_cache($server_address) {
|
1175 |
+
if (!$server_address) {
|
1176 |
+
return;
|
1177 |
+
}
|
1178 |
$options_manager = new A2_Optimized_OptionsManager;
|
1179 |
|
1180 |
+
$object_cache_type = '';
|
1181 |
+
if (get_option('a2_optimized_objectcache_type')) {
|
1182 |
+
$object_cache_type = get_option('a2_optimized_objectcache_type');
|
1183 |
+
}
|
1184 |
+
|
1185 |
+
switch ($object_cache_type) {
|
1186 |
+
case 'memcached':
|
1187 |
+
if (class_exists('Memcached')) {
|
1188 |
+
$memcached = new Memcached;
|
1189 |
+
if ( 'unix://' == substr( $server_address, 0, 7 ) ) {
|
1190 |
+
$node = str_replace('unix://', '', $server_address);
|
1191 |
+
$port = 0;
|
1192 |
+
} else {
|
1193 |
+
list( $node, $port ) = explode( ':', $server_address );
|
1194 |
+
if ( ! $port ) {
|
1195 |
+
$port = ini_get( 'memcache.default_port' );
|
1196 |
+
}
|
1197 |
+
$port = intval( $port );
|
1198 |
+
if ( ! $port ) {
|
1199 |
+
$port = 11211;
|
1200 |
+
}
|
1201 |
+
}
|
1202 |
+
$instances[] = [ $node, $port, 1 ];
|
1203 |
+
|
1204 |
+
$memcached->addServers($instances);
|
1205 |
+
$memcached_available = $memcached->getStats();
|
1206 |
+
if ($memcached_available) {
|
1207 |
+
$options_manager->write_wp_config();
|
1208 |
+
delete_option('a2_optimized_memcached_invalid');
|
1209 |
+
update_option('litespeed.conf.object-kind', 0);
|
1210 |
+
update_option('litespeed.conf.object-host', $server_address);
|
1211 |
+
update_option('litespeed.conf.object-post', 0);
|
1212 |
+
} else {
|
1213 |
+
update_option('a2_optimized_memcached_invalid', 'Unable to connect to Memcached Server');
|
1214 |
+
}
|
1215 |
+
} else {
|
1216 |
+
update_option('a2_optimized_memcached_invalid', 'Missing Memcached extension');
|
1217 |
}
|
1218 |
+
|
1219 |
+
break;
|
1220 |
+
case 'redis':
|
1221 |
+
if (class_exists('Redis')) {
|
1222 |
+
$conn = new Redis() ;
|
1223 |
+
$conn->connect( $server_address, 0 ) ;
|
1224 |
+
$conn->select( 0 ); // default db
|
1225 |
+
|
1226 |
+
$redis_available = $conn->ping();
|
1227 |
+
|
1228 |
+
if ($redis_available) {
|
1229 |
+
update_option('litespeed.conf.object-kind', 1);
|
1230 |
+
update_option('litespeed.conf.object-host', $server_address);
|
1231 |
+
update_option('litespeed.conf.object-post', 0);
|
1232 |
+
|
1233 |
+
delete_option('a2_optimized_memcached_invalid');
|
1234 |
+
} else {
|
1235 |
+
update_option('a2_optimized_memcached_invalid', 'Unable to connect to Redis Server');
|
1236 |
+
}
|
1237 |
+
} else {
|
1238 |
+
update_option('a2_optimized_memcached_invalid', 'Missing Redis extension');
|
1239 |
}
|
|
|
|
|
1240 |
|
1241 |
+
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1242 |
}
|
1243 |
|
1244 |
+
return $server_address;
|
1245 |
}
|
1246 |
}
|
A2_Optimized_DB_Optimizations.php
ADDED
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//@TODO: Button run optimizations. deactivate hook to remove cron task
|
4 |
+
|
5 |
+
class A2_Optimized_DBOptimizations {
|
6 |
+
public $wpdb;
|
7 |
+
public const WP_SETTING = 'a2_db_optimizations';
|
8 |
+
public const REMOVE_REVISION_POSTS = 'remove_revision_posts';
|
9 |
+
public const REMOVE_TRASHED_POSTS = 'remove_trashed_posts';
|
10 |
+
public const REMOVE_SPAM_COMMENTS = 'remove_spam_comments';
|
11 |
+
public const REMOVE_TRASHED_COMMENTS = 'remove_trashed_comments';
|
12 |
+
public const REMOVE_EXPIRED_TRANSIENTS = 'remove_expired_transients';
|
13 |
+
public const OPTIMIZE_TABLES = 'optimize_tables';
|
14 |
+
public const EXECUTE_OPTIMIZATIONS_HOOK = 'a2_execute_db_optimizations';
|
15 |
+
public const CRON_ACTIVE = 'cron_active';
|
16 |
+
|
17 |
+
public function __construct() {
|
18 |
+
if ( ! $this->allow_load() ) {
|
19 |
+
return;
|
20 |
+
}
|
21 |
+
$this->hooks();
|
22 |
+
|
23 |
+
global $wpdb;
|
24 |
+
$this->wpdb = $wpdb;
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Indicate if Site Health is allowed to load.
|
29 |
+
*
|
30 |
+
* @return bool
|
31 |
+
*/
|
32 |
+
private function allow_load() {
|
33 |
+
global $wp_version;
|
34 |
+
|
35 |
+
return version_compare( $wp_version, '5.2', '>=' );
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Integration hooks.
|
40 |
+
*/
|
41 |
+
protected function hooks() {
|
42 |
+
$toggles = get_option(self::WP_SETTING);
|
43 |
+
if ($toggles && isset($toggles[self::CRON_ACTIVE]) && $toggles[self::CRON_ACTIVE]) {
|
44 |
+
add_action(self::EXECUTE_OPTIMIZATIONS_HOOK, [&$this, 'execute_optimizations']);
|
45 |
+
if (!wp_next_scheduled(self::EXECUTE_OPTIMIZATIONS_HOOK)) {
|
46 |
+
wp_schedule_event(time(), 'weekly', self::EXECUTE_OPTIMIZATIONS_HOOK);
|
47 |
+
}
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
public static function validate_db_optimization_settings($settings) {
|
52 |
+
$final_settings = self::zero_settings();
|
53 |
+
|
54 |
+
foreach ($settings as $key => $value) {
|
55 |
+
$final_settings[$key] = intval($value);
|
56 |
+
}
|
57 |
+
|
58 |
+
return $final_settings;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Get the default values for the optimization toggles
|
63 |
+
*/
|
64 |
+
private static function get_defaults() {
|
65 |
+
$default_toggles = [
|
66 |
+
self::REMOVE_REVISION_POSTS => 0,
|
67 |
+
self::REMOVE_TRASHED_POSTS => 0,
|
68 |
+
self::REMOVE_SPAM_COMMENTS => 1,
|
69 |
+
self::REMOVE_TRASHED_COMMENTS => 1,
|
70 |
+
self::REMOVE_EXPIRED_TRANSIENTS => 1,
|
71 |
+
self::OPTIMIZE_TABLES => 1
|
72 |
+
];
|
73 |
+
|
74 |
+
return $default_toggles;
|
75 |
+
}
|
76 |
+
|
77 |
+
private static function zero_settings() {
|
78 |
+
$default_toggles = [
|
79 |
+
self::REMOVE_REVISION_POSTS => 0,
|
80 |
+
self::REMOVE_TRASHED_POSTS => 0,
|
81 |
+
self::REMOVE_SPAM_COMMENTS => 0,
|
82 |
+
self::REMOVE_TRASHED_COMMENTS => 0,
|
83 |
+
self::REMOVE_EXPIRED_TRANSIENTS => 0,
|
84 |
+
self::OPTIMIZE_TABLES => 0
|
85 |
+
];
|
86 |
+
|
87 |
+
return $default_toggles;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Update a Wordpress setting in the toggles array.
|
92 |
+
*
|
93 |
+
* @param string $setting The setting to update in the toggles array
|
94 |
+
* @param bool $value Update the setting to true or false
|
95 |
+
*/
|
96 |
+
public static function set($setting, $value) {
|
97 |
+
$toggles = get_option(self::WP_SETTING);
|
98 |
+
$defaults = self::get_defaults();
|
99 |
+
$combined = wp_parse_args($toggles, $defaults);
|
100 |
+
$combined[$setting] = $value;
|
101 |
+
update_option(self::WP_SETTING, $combined);
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Execute optimizations that have been enabled by the user
|
106 |
+
*/
|
107 |
+
public function execute_optimizations() {
|
108 |
+
$toggles = get_option(self::WP_SETTING);
|
109 |
+
|
110 |
+
if ($toggles[self::REMOVE_REVISION_POSTS]) {
|
111 |
+
$this->remove_revisions_posts();
|
112 |
+
}
|
113 |
+
if ($toggles[self::REMOVE_TRASHED_POSTS]) {
|
114 |
+
$this->remove_trashed_posts();
|
115 |
+
}
|
116 |
+
if ($toggles[self::REMOVE_SPAM_COMMENTS]) {
|
117 |
+
$this->remove_spam_comments();
|
118 |
+
}
|
119 |
+
if ($toggles[self::REMOVE_TRASHED_COMMENTS]) {
|
120 |
+
$this->remove_trashed_comments();
|
121 |
+
}
|
122 |
+
if ($toggles[self::REMOVE_EXPIRED_TRANSIENTS]) {
|
123 |
+
$this->remove_expired_transients();
|
124 |
+
}
|
125 |
+
if ($toggles[self::OPTIMIZE_TABLES]) {
|
126 |
+
$this->remove_optimize_tables();
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Remove "revisions" posts from the DB
|
132 |
+
*/
|
133 |
+
public function remove_revisions_posts() {
|
134 |
+
$post_table = $this->wpdb->posts;
|
135 |
+
$query = 'SELECT ID FROM ' . $post_table . ' WHERE post_type = "revision"';
|
136 |
+
$ids = $this->wpdb->get_col($query);
|
137 |
+
if (!$ids) {
|
138 |
+
return;
|
139 |
+
}
|
140 |
+
|
141 |
+
foreach ($ids as $id) {
|
142 |
+
wp_delete_post_revision($id);
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Remove trashed posts from the DB
|
148 |
+
*/
|
149 |
+
public function remove_trashed_posts() {
|
150 |
+
$post_table = $this->wpdb->posts;
|
151 |
+
$query = 'SELECT ID FROM ' . $post_table . ' WHERE post_status = "trash"';
|
152 |
+
$ids = $this->wpdb->get_col($query);
|
153 |
+
if (!$ids) {
|
154 |
+
return;
|
155 |
+
}
|
156 |
+
|
157 |
+
foreach ($ids as $id) {
|
158 |
+
wp_delete_post($id, true);
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Remove spam comments from the DB
|
164 |
+
*/
|
165 |
+
public function remove_spam_comments() {
|
166 |
+
$comment_table = $this->wpdb->comments;
|
167 |
+
$query = 'SELECT comment_ID FROM ' . $comment_table . ' WHERE comment_approved = "spam"';
|
168 |
+
$ids = $this->wpdb->get_col($query);
|
169 |
+
if (!$ids) {
|
170 |
+
return;
|
171 |
+
}
|
172 |
+
|
173 |
+
foreach ($ids as $id) {
|
174 |
+
wp_delete_comment($id, true);
|
175 |
+
}
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Remove trashed comments from the DB
|
180 |
+
*/
|
181 |
+
public function remove_trashed_comments() {
|
182 |
+
$comment_table = $this->wpdb->comments;
|
183 |
+
$query = 'SELECT comment_ID FROM ' . $comment_table . ' WHERE comment_approved = "trash"';
|
184 |
+
$ids = $this->wpdb->get_col($query);
|
185 |
+
if (!$ids) {
|
186 |
+
return;
|
187 |
+
}
|
188 |
+
|
189 |
+
foreach ($ids as $id) {
|
190 |
+
wp_delete_comment($id, true);
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Delete expired transients from the DB
|
196 |
+
*/
|
197 |
+
public function remove_expired_transients() {
|
198 |
+
$options_table = $this->wpdb->options;
|
199 |
+
$query = 'SELECT option_name FROM ' . $options_table . ' WHERE option_name LIKE %s AND option_value < %d';
|
200 |
+
$time = $_SERVER['REQUEST_TIME'];
|
201 |
+
$transients = $this->wpdb->get_col($this->wpdb->prepare($query, $this->wpdb->esc_like( '_transient_timeout' ) . '%', $time));
|
202 |
+
if (!$transients) {
|
203 |
+
return;
|
204 |
+
}
|
205 |
+
|
206 |
+
foreach ($transients as $transient) {
|
207 |
+
delete_transient(str_replace( '_transient_timeout_', '', $transient));
|
208 |
+
}
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* Optimize Wordpress tables
|
213 |
+
*/
|
214 |
+
public function optimize_tables() {
|
215 |
+
$query = 'SHOW TABLES';
|
216 |
+
$tables = $this->wpdb->get_results($query);
|
217 |
+
|
218 |
+
foreach ($tables as $obj) {
|
219 |
+
$pair = json_decode(json_encode($obj), true);
|
220 |
+
foreach ($pair as $table => $name) {
|
221 |
+
$opt_query = 'OPTIMIZE TABLE ' . $name;
|
222 |
+
$this->wpdb->query($opt_query);
|
223 |
+
}
|
224 |
+
}
|
225 |
+
}
|
226 |
+
}
|
A2_Optimized_Optimizations.php
CHANGED
@@ -60,14 +60,14 @@ class A2_Optimized_Optimizations {
|
|
60 |
|
61 |
$a2_object_cache_additional_info = '';
|
62 |
|
63 |
-
if (get_option('a2_optimized_memcached_invalid')
|
64 |
-
$a2_object_cache_additional_info = '<p><strong>Please confirm your
|
65 |
}
|
66 |
|
67 |
if (is_plugin_active('a2-w3-total-cache/a2-w3-total-cache.php')) {
|
68 |
/* W3 Total Cache Caching */
|
69 |
-
$optimizations =
|
70 |
-
'page_cache' =>
|
71 |
'slug' => 'page_cache',
|
72 |
'name' => 'Page Caching with W3 Total Cache',
|
73 |
'plugin' => 'W3 Total Cache',
|
@@ -78,7 +78,7 @@ class A2_Optimized_Optimizations {
|
|
78 |
if ($w3tc['pgcache.enabled']) {
|
79 |
$item['configured'] = true;
|
80 |
$permalink_structure = get_option('permalink_structure');
|
81 |
-
$vars =
|
82 |
if ($w3tc['pgcache.engine'] == 'apc') {
|
83 |
if ($permalink_structure == '') {
|
84 |
$vars['pgcache.engine'] = 'file';
|
@@ -109,8 +109,8 @@ class A2_Optimized_Optimizations {
|
|
109 |
'enable' => function () use (&$thisclass) {
|
110 |
$thisclass->enable_w3tc_page_cache();
|
111 |
}
|
112 |
-
|
113 |
-
'db_cache' =>
|
114 |
'slug' => 'db_cache',
|
115 |
'name' => 'DB Caching with W3 Total Cache',
|
116 |
'plugin' => 'W3 Total Cache',
|
@@ -119,7 +119,7 @@ class A2_Optimized_Optimizations {
|
|
119 |
'is_configured' => function (&$item) use (&$thisclass) {
|
120 |
$w3tc = $thisclass->get_w3tc_config();
|
121 |
if ($w3tc['dbcache.enabled']) {
|
122 |
-
$vars =
|
123 |
$item['configured'] = true;
|
124 |
if (class_exists('W3_Config')) {
|
125 |
if (class_exists('WooCommerce')) {
|
@@ -145,8 +145,8 @@ class A2_Optimized_Optimizations {
|
|
145 |
'enable' => function () use (&$thisclass) {
|
146 |
$thisclass->enable_w3tc_db_cache();
|
147 |
}
|
148 |
-
|
149 |
-
'object_cache' =>
|
150 |
'slug' => 'object_cache',
|
151 |
'name' => 'Object Caching with W3 Total Cache',
|
152 |
'plugin' => 'W3 Total Cache',
|
@@ -168,8 +168,8 @@ class A2_Optimized_Optimizations {
|
|
168 |
'enable' => function () use (&$thisclass) {
|
169 |
$thisclass->enable_w3tc_object_cache();
|
170 |
}
|
171 |
-
|
172 |
-
'browser_cache' =>
|
173 |
'slug' => 'browser_cache',
|
174 |
'name' => 'Browser Caching with W3 Total Cache',
|
175 |
'plugin' => 'W3 Total Cache',
|
@@ -191,8 +191,8 @@ class A2_Optimized_Optimizations {
|
|
191 |
'enable' => function () use (&$thisclass) {
|
192 |
$thisclass->enable_w3tc_browser_cache();
|
193 |
}
|
194 |
-
|
195 |
-
'minify' =>
|
196 |
'name' => 'Minify HTML Pages',
|
197 |
'slug' => 'minify',
|
198 |
'plugin' => 'W3 Total Cache',
|
@@ -215,8 +215,8 @@ class A2_Optimized_Optimizations {
|
|
215 |
'disable' => function () use (&$thisclass) {
|
216 |
$thisclass->disable_html_minify();
|
217 |
}
|
218 |
-
|
219 |
-
'css_minify' =>
|
220 |
'name' => 'Minify CSS Files',
|
221 |
'slug' => 'css_minify',
|
222 |
'plugin' => 'W3 Total Cache',
|
@@ -233,21 +233,21 @@ class A2_Optimized_Optimizations {
|
|
233 |
}
|
234 |
},
|
235 |
'enable' => function () use (&$thisclass) {
|
236 |
-
$thisclass->update_w3tc(
|
237 |
'minify.css.enable' => true,
|
238 |
'minify.enabled' => true,
|
239 |
'minify.auto' => 0,
|
240 |
'minify.engine' => 'file'
|
241 |
-
)
|
242 |
},
|
243 |
'disable' => function () use (&$thisclass) {
|
244 |
-
$thisclass->update_w3tc(
|
245 |
'minify.css.enable' => false,
|
246 |
'minify.auto' => 0
|
247 |
-
)
|
248 |
}
|
249 |
-
|
250 |
-
'js_minify' =>
|
251 |
'name' => 'Minify JS Files',
|
252 |
'slug' => 'js_minify',
|
253 |
'plugin' => 'W3 Total Cache',
|
@@ -264,21 +264,21 @@ class A2_Optimized_Optimizations {
|
|
264 |
}
|
265 |
},
|
266 |
'enable' => function () use (&$thisclass) {
|
267 |
-
$thisclass->update_w3tc(
|
268 |
'minify.js.enable' => true,
|
269 |
'minify.enabled' => true,
|
270 |
'minify.auto' => 0,
|
271 |
'minify.engine' => 'file'
|
272 |
-
)
|
273 |
},
|
274 |
'disable' => function () use (&$thisclass) {
|
275 |
-
$thisclass->update_w3tc(
|
276 |
'minify.js.enable' => false,
|
277 |
'minify.auto' => 0
|
278 |
-
)
|
279 |
}
|
280 |
-
|
281 |
-
'gzip' =>
|
282 |
'name' => 'Gzip Compression Enabled',
|
283 |
'slug' => 'gzip',
|
284 |
'plugin' => 'W3 Total Cache',
|
@@ -300,12 +300,12 @@ class A2_Optimized_Optimizations {
|
|
300 |
$thisclass->disable_w3tc_gzip();
|
301 |
},
|
302 |
'remove_link' => true
|
303 |
-
|
304 |
-
|
305 |
} else {
|
306 |
/* Internal Caching */
|
307 |
-
$optimizations =
|
308 |
-
'a2_page_cache' =>
|
309 |
'slug' => 'a2_page_cache',
|
310 |
'name' => 'Page Caching',
|
311 |
'plugin' => 'A2 Optimized',
|
@@ -326,8 +326,8 @@ class A2_Optimized_Optimizations {
|
|
326 |
'enable' => function () use (&$thisclass) {
|
327 |
$thisclass->enable_a2_page_cache();
|
328 |
}
|
329 |
-
|
330 |
-
'a2_page_cache_gzip' =>
|
331 |
'slug' => 'a2_page_cache_gzip',
|
332 |
'name' => 'Gzip Compression Enabled',
|
333 |
'plugin' => 'A2 Optimized',
|
@@ -349,8 +349,8 @@ class A2_Optimized_Optimizations {
|
|
349 |
$thisclass->enable_a2_page_cache_gzip();
|
350 |
},
|
351 |
'remove_link' => true
|
352 |
-
|
353 |
-
'a2_object_cache' =>
|
354 |
'slug' => 'a2_object_cache',
|
355 |
'name' => 'Memcache Object Caching',
|
356 |
'plugin' => 'A2 Optimized',
|
@@ -358,11 +358,11 @@ class A2_Optimized_Optimizations {
|
|
358 |
'description' => '
|
359 |
<ul>
|
360 |
<li>Extremely fast and powerful caching system.</li>
|
361 |
-
<li>Store frequently used database queries and WordPress objects in
|
362 |
-
<li>
|
363 |
<li>Take advantage of A2 Hosting's one-click memcached configuration for WordPress.</li>
|
364 |
</ul>
|
365 |
-
<strong>A
|
366 |
' . $a2_object_cache_additional_info,
|
367 |
'is_configured' => function (&$item) use (&$thisclass) {
|
368 |
if (get_option('a2_object_cache_enabled') == 1 && file_exists( WP_CONTENT_DIR . '/object-cache.php')) {
|
@@ -379,8 +379,8 @@ class A2_Optimized_Optimizations {
|
|
379 |
'enable' => function () use (&$thisclass) {
|
380 |
$thisclass->enable_a2_object_cache();
|
381 |
}
|
382 |
-
|
383 |
-
'a2_page_cache_minify_html' =>
|
384 |
'slug' => 'a2_page_cache_minify_html',
|
385 |
'name' => 'Minify HTML Pages',
|
386 |
'plugin' => 'A2 Optimized',
|
@@ -402,8 +402,8 @@ class A2_Optimized_Optimizations {
|
|
402 |
$thisclass->enable_a2_page_cache_minify_html();
|
403 |
},
|
404 |
'remove_link' => true
|
405 |
-
|
406 |
-
'a2_page_cache_minify_jscss' =>
|
407 |
'slug' => 'a2_page_cache_minify_jscss',
|
408 |
'name' => 'Minify Inline CSS and Javascript',
|
409 |
'plugin' => 'A2 Optimized',
|
@@ -426,13 +426,36 @@ class A2_Optimized_Optimizations {
|
|
426 |
$thisclass->enable_a2_page_cache_minify_jscss();
|
427 |
},
|
428 |
'remove_link' => true
|
429 |
-
|
430 |
-
|
431 |
}
|
432 |
|
433 |
/* Common optimizations */
|
434 |
-
$common_optimizations =
|
435 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
436 |
'name' => 'Dequeue WooCommerce Cart Fragments AJAX calls',
|
437 |
'slug' => 'woo-cart-fragments',
|
438 |
'plugin' => 'A2 Optimized',
|
@@ -453,8 +476,8 @@ class A2_Optimized_Optimizations {
|
|
453 |
'disable' => function () use (&$thisclass) {
|
454 |
$thisclass->disable_woo_cart_fragments();
|
455 |
},
|
456 |
-
|
457 |
-
'xmlrpc-requests' =>
|
458 |
'name' => 'Block Unauthorized XML-RPC Requests',
|
459 |
'slug' => 'xmlrpc-requests',
|
460 |
'plugin' => 'A2 Optimized',
|
@@ -477,8 +500,8 @@ class A2_Optimized_Optimizations {
|
|
477 |
'disable' => function () use (&$thisclass) {
|
478 |
$thisclass->disable_xmlrpc_requests();
|
479 |
},
|
480 |
-
|
481 |
-
'regenerate-salts' =>
|
482 |
'name' => 'Regenerate wp-config salts',
|
483 |
'slug' => 'regenerate-salts',
|
484 |
'plugin' => 'A2 Optimized',
|
@@ -498,8 +521,8 @@ class A2_Optimized_Optimizations {
|
|
498 |
'enable' => function () use (&$thisclass) {
|
499 |
$thisclass->regenerate_wpconfig_salts();
|
500 |
},
|
501 |
-
|
502 |
-
'htaccess' =>
|
503 |
'name' => 'Deny Direct Access to Configuration Files and Comment Form',
|
504 |
'slug' => 'htaccess',
|
505 |
'plugin' => 'A2 Optimized',
|
@@ -529,8 +552,8 @@ class A2_Optimized_Optimizations {
|
|
529 |
$thisclass->set_deny_direct(false);
|
530 |
$thisclass->write_htaccess();
|
531 |
}
|
532 |
-
|
533 |
-
'lock' =>
|
534 |
'name' => 'Lock Editing of Plugins and Themes from the WP Admin',
|
535 |
'slug' => 'lock',
|
536 |
'plugin' => 'A2 Optimized',
|
@@ -558,8 +581,8 @@ class A2_Optimized_Optimizations {
|
|
558 |
$thisclass->set_lockdown(false);
|
559 |
$thisclass->write_wp_config();
|
560 |
}
|
561 |
-
|
562 |
-
'wp-login' =>
|
563 |
'name' => 'Login URL Change',
|
564 |
'slug' => 'wp-login',
|
565 |
'premium' => true,
|
@@ -572,8 +595,8 @@ class A2_Optimized_Optimizations {
|
|
572 |
'is_configured' => function () {
|
573 |
return false;
|
574 |
}
|
575 |
-
|
576 |
-
'captcha' =>
|
577 |
'name' => 'reCAPTCHA on comments and login',
|
578 |
'plugin' => 'reCAPTCHA',
|
579 |
'slug' => 'captcha',
|
@@ -583,8 +606,8 @@ class A2_Optimized_Optimizations {
|
|
583 |
'is_configured' => function () {
|
584 |
return false;
|
585 |
}
|
586 |
-
|
587 |
-
'images' =>
|
588 |
'name' => 'Compress Images on Upload',
|
589 |
'plugin' => 'Image Optimizer',
|
590 |
'slug' => 'images',
|
@@ -594,8 +617,8 @@ class A2_Optimized_Optimizations {
|
|
594 |
'is_configured' => function () {
|
595 |
return false;
|
596 |
}
|
597 |
-
|
598 |
-
'turbo' =>
|
599 |
'name' => 'Turbo Web Hosting',
|
600 |
'slug' => 'turbo',
|
601 |
'configured' => false,
|
@@ -612,17 +635,43 @@ class A2_Optimized_Optimizations {
|
|
612 |
'is_configured' => function () {
|
613 |
return false;
|
614 |
}
|
615 |
-
|
616 |
-
|
617 |
|
618 |
$optimizations = array_merge($optimizations, $common_optimizations);
|
619 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
620 |
if (get_template() == 'Divi') {
|
621 |
$optimizations['minify']['optional'] = true;
|
622 |
$optimizations['css_minify']['optional'] = true;
|
623 |
$optimizations['js_minify']['optional'] = true;
|
624 |
}
|
625 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
626 |
return $optimizations;
|
627 |
}
|
628 |
|
@@ -632,7 +681,7 @@ class A2_Optimized_Optimizations {
|
|
632 |
|
633 |
return $a2opt_priv->get_optimizations($this->thisclass);
|
634 |
} else {
|
635 |
-
return
|
636 |
}
|
637 |
}
|
638 |
|
@@ -646,8 +695,8 @@ class A2_Optimized_Optimizations {
|
|
646 |
protected function get_public_advanced() {
|
647 |
$thisclass = $this->thisclass;
|
648 |
|
649 |
-
return
|
650 |
-
'gtmetrix' =>
|
651 |
'slug' => 'gtmetrix',
|
652 |
'name' => 'GTmetrix',
|
653 |
'plugin' => 'GTmetrix',
|
@@ -655,7 +704,7 @@ class A2_Optimized_Optimizations {
|
|
655 |
'file' => 'gtmetrix-for-wordpress/gtmetrix-for-wordpress.php',
|
656 |
'configured' => false,
|
657 |
'partially_configured' => false,
|
658 |
-
'required_options' =>
|
659 |
'description' => '
|
660 |
<p>
|
661 |
Plugin that actively keeps track of your WP install and sends you alerts if your site falls below certain criteria.
|
@@ -665,15 +714,15 @@ class A2_Optimized_Optimizations {
|
|
665 |
<b>Use this plugin only if your site is experiencing issues with slow load times.</b><br><b style="color:red">The GTMetrix plugin will slow down your site.</b>
|
666 |
</p>
|
667 |
',
|
668 |
-
'not_configured_links' =>
|
669 |
-
'configured_links' =>
|
670 |
'Configure GTmetrix' => 'admin.php?page=gfw_settings',
|
671 |
'GTmetrix Tests' => 'admin.php?page=gfw_tests',
|
672 |
-
|
673 |
-
'partially_configured_links' =>
|
674 |
'Configure GTmetrix' => 'admin.php?page=gfw_settings',
|
675 |
'GTmetrix Tests' => 'admin.php?page=gfw_tests',
|
676 |
-
|
677 |
'partially_configured_message' => 'Click "Configure GTmetrix" to enter your GTmetrix Account Email and GTmetrix API Key.',
|
678 |
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
|
679 |
'is_configured' => function (&$item) use (&$thisclass) {
|
@@ -702,8 +751,8 @@ class A2_Optimized_Optimizations {
|
|
702 |
$item = $item[$slug];
|
703 |
$thisclass->deactivate_plugin($item['file']);
|
704 |
}
|
705 |
-
|
706 |
-
'cloudflare' =>
|
707 |
'slug' => 'cloudflare',
|
708 |
'name' => 'CloudFlare',
|
709 |
'premium' => true,
|
@@ -730,9 +779,9 @@ class A2_Optimized_Optimizations {
|
|
730 |
'is_configured' => function () {
|
731 |
return false;
|
732 |
},
|
733 |
-
'not_configured_links' =>
|
734 |
-
|
735 |
-
|
736 |
}
|
737 |
|
738 |
protected function get_private_advanced() {
|
@@ -741,7 +790,7 @@ class A2_Optimized_Optimizations {
|
|
741 |
|
742 |
return $a2opt_priv->get_advanced($this->thisclass);
|
743 |
} else {
|
744 |
-
return
|
745 |
}
|
746 |
}
|
747 |
|
@@ -753,43 +802,43 @@ class A2_Optimized_Optimizations {
|
|
753 |
}
|
754 |
|
755 |
protected function get_public_warnings() {
|
756 |
-
return
|
757 |
-
'Bad WP Options' =>
|
758 |
-
'posts_per_page' =>
|
759 |
'title' => 'Recent Post Limit',
|
760 |
'description' => 'The number of recent posts per page is set greater than five. This could be slowing down page loads.',
|
761 |
'type' => 'numeric',
|
762 |
'threshold_type' => '>',
|
763 |
'threshold' => 5,
|
764 |
'config_url' => admin_url() . 'options-reading.php'
|
765 |
-
|
766 |
-
'posts_per_rss' =>
|
767 |
'title' => 'RSS Post Limit',
|
768 |
'description' => 'The number of posts from external feeds is set greater than 5. This could be slowing down page loads.',
|
769 |
'type' => 'numeric',
|
770 |
'threshold_type' => '>',
|
771 |
'threshold' => 5,
|
772 |
'config_url' => admin_url() . 'options-reading.php'
|
773 |
-
|
774 |
-
'show_on_front' =>
|
775 |
'title' => 'Recent Posts showing on home page',
|
776 |
'description' => 'Speed up your home page by selecting a static page to display.',
|
777 |
'type' => 'text',
|
778 |
'threshold_type' => '=',
|
779 |
'threshold' => 'posts',
|
780 |
'config_url' => admin_url() . 'options-reading.php'
|
781 |
-
|
782 |
-
'permalink_structure' =>
|
783 |
'title' => 'Permalink Structure',
|
784 |
'description' => 'To fully optimize page caching with "Disk Enhanced" mode:<br>you must set a permalink structure other than "Default".',
|
785 |
'type' => 'text',
|
786 |
'threshold_type' => '=',
|
787 |
'threshold' => '',
|
788 |
'config_url' => admin_url() . 'options-permalink.php'
|
789 |
-
|
790 |
-
|
791 |
-
'Advanced Warnings' =>
|
792 |
-
'themes' =>
|
793 |
'is_warning' => function () {
|
794 |
$theme_count = 0;
|
795 |
$themes = wp_get_themes();
|
@@ -814,8 +863,8 @@ class A2_Optimized_Optimizations {
|
|
814 |
'title' => 'Unused Themes',
|
815 |
'description' => 'One or more unused non-default themes are installed. Unused non-default themes should be deleted. For more information read the Wordpress.org Codex on <a target="_blank" href="http://codex.wordpress.org/WordPress_Housekeeping#Theme_Housekeeping">WordPress Housekeeping</a>',
|
816 |
'config_url' => admin_url() . 'themes.php'
|
817 |
-
|
818 |
-
'a2_hosting' =>
|
819 |
'title' => 'Not Hosted with A2 Hosting',
|
820 |
'description' => 'Get faster page load times and more optimizations when you <a href="https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized" target="_blank">host with A2 Hosting</a>.',
|
821 |
'is_warning' => function () {
|
@@ -826,14 +875,14 @@ class A2_Optimized_Optimizations {
|
|
826 |
return true;
|
827 |
},
|
828 |
'config_url' => 'https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized'
|
829 |
-
|
830 |
-
|
831 |
-
'Bad Plugins' =>
|
832 |
'wp-super-cache',
|
833 |
'wp-file-cache',
|
834 |
'wp-db-backup',
|
835 |
-
|
836 |
-
|
837 |
}
|
838 |
|
839 |
protected function get_private_warnings() {
|
@@ -842,7 +891,7 @@ class A2_Optimized_Optimizations {
|
|
842 |
|
843 |
return $a2opt_priv->get_warnings($this->thisclass);
|
844 |
} else {
|
845 |
-
return
|
846 |
}
|
847 |
}
|
848 |
}
|
60 |
|
61 |
$a2_object_cache_additional_info = '';
|
62 |
|
63 |
+
if (get_option('a2_optimized_memcached_invalid')) {
|
64 |
+
$a2_object_cache_additional_info = '<p><strong>Please confirm your server settings before enabling Object Caching.</strong><br />' . get_option('a2_optimized_memcached_invalid') . '</p>';
|
65 |
}
|
66 |
|
67 |
if (is_plugin_active('a2-w3-total-cache/a2-w3-total-cache.php')) {
|
68 |
/* W3 Total Cache Caching */
|
69 |
+
$optimizations = [
|
70 |
+
'page_cache' => [
|
71 |
'slug' => 'page_cache',
|
72 |
'name' => 'Page Caching with W3 Total Cache',
|
73 |
'plugin' => 'W3 Total Cache',
|
78 |
if ($w3tc['pgcache.enabled']) {
|
79 |
$item['configured'] = true;
|
80 |
$permalink_structure = get_option('permalink_structure');
|
81 |
+
$vars = [];
|
82 |
if ($w3tc['pgcache.engine'] == 'apc') {
|
83 |
if ($permalink_structure == '') {
|
84 |
$vars['pgcache.engine'] = 'file';
|
109 |
'enable' => function () use (&$thisclass) {
|
110 |
$thisclass->enable_w3tc_page_cache();
|
111 |
}
|
112 |
+
],
|
113 |
+
'db_cache' => [
|
114 |
'slug' => 'db_cache',
|
115 |
'name' => 'DB Caching with W3 Total Cache',
|
116 |
'plugin' => 'W3 Total Cache',
|
119 |
'is_configured' => function (&$item) use (&$thisclass) {
|
120 |
$w3tc = $thisclass->get_w3tc_config();
|
121 |
if ($w3tc['dbcache.enabled']) {
|
122 |
+
$vars = [];
|
123 |
$item['configured'] = true;
|
124 |
if (class_exists('W3_Config')) {
|
125 |
if (class_exists('WooCommerce')) {
|
145 |
'enable' => function () use (&$thisclass) {
|
146 |
$thisclass->enable_w3tc_db_cache();
|
147 |
}
|
148 |
+
],
|
149 |
+
'object_cache' => [
|
150 |
'slug' => 'object_cache',
|
151 |
'name' => 'Object Caching with W3 Total Cache',
|
152 |
'plugin' => 'W3 Total Cache',
|
168 |
'enable' => function () use (&$thisclass) {
|
169 |
$thisclass->enable_w3tc_object_cache();
|
170 |
}
|
171 |
+
],
|
172 |
+
'browser_cache' => [
|
173 |
'slug' => 'browser_cache',
|
174 |
'name' => 'Browser Caching with W3 Total Cache',
|
175 |
'plugin' => 'W3 Total Cache',
|
191 |
'enable' => function () use (&$thisclass) {
|
192 |
$thisclass->enable_w3tc_browser_cache();
|
193 |
}
|
194 |
+
],
|
195 |
+
'minify' => [
|
196 |
'name' => 'Minify HTML Pages',
|
197 |
'slug' => 'minify',
|
198 |
'plugin' => 'W3 Total Cache',
|
215 |
'disable' => function () use (&$thisclass) {
|
216 |
$thisclass->disable_html_minify();
|
217 |
}
|
218 |
+
],
|
219 |
+
'css_minify' => [
|
220 |
'name' => 'Minify CSS Files',
|
221 |
'slug' => 'css_minify',
|
222 |
'plugin' => 'W3 Total Cache',
|
233 |
}
|
234 |
},
|
235 |
'enable' => function () use (&$thisclass) {
|
236 |
+
$thisclass->update_w3tc([
|
237 |
'minify.css.enable' => true,
|
238 |
'minify.enabled' => true,
|
239 |
'minify.auto' => 0,
|
240 |
'minify.engine' => 'file'
|
241 |
+
]);
|
242 |
},
|
243 |
'disable' => function () use (&$thisclass) {
|
244 |
+
$thisclass->update_w3tc([
|
245 |
'minify.css.enable' => false,
|
246 |
'minify.auto' => 0
|
247 |
+
]);
|
248 |
}
|
249 |
+
],
|
250 |
+
'js_minify' => [
|
251 |
'name' => 'Minify JS Files',
|
252 |
'slug' => 'js_minify',
|
253 |
'plugin' => 'W3 Total Cache',
|
264 |
}
|
265 |
},
|
266 |
'enable' => function () use (&$thisclass) {
|
267 |
+
$thisclass->update_w3tc([
|
268 |
'minify.js.enable' => true,
|
269 |
'minify.enabled' => true,
|
270 |
'minify.auto' => 0,
|
271 |
'minify.engine' => 'file'
|
272 |
+
]);
|
273 |
},
|
274 |
'disable' => function () use (&$thisclass) {
|
275 |
+
$thisclass->update_w3tc([
|
276 |
'minify.js.enable' => false,
|
277 |
'minify.auto' => 0
|
278 |
+
]);
|
279 |
}
|
280 |
+
],
|
281 |
+
'gzip' => [
|
282 |
'name' => 'Gzip Compression Enabled',
|
283 |
'slug' => 'gzip',
|
284 |
'plugin' => 'W3 Total Cache',
|
300 |
$thisclass->disable_w3tc_gzip();
|
301 |
},
|
302 |
'remove_link' => true
|
303 |
+
]
|
304 |
+
];
|
305 |
} else {
|
306 |
/* Internal Caching */
|
307 |
+
$optimizations = [
|
308 |
+
'a2_page_cache' => [
|
309 |
'slug' => 'a2_page_cache',
|
310 |
'name' => 'Page Caching',
|
311 |
'plugin' => 'A2 Optimized',
|
326 |
'enable' => function () use (&$thisclass) {
|
327 |
$thisclass->enable_a2_page_cache();
|
328 |
}
|
329 |
+
],
|
330 |
+
'a2_page_cache_gzip' => [
|
331 |
'slug' => 'a2_page_cache_gzip',
|
332 |
'name' => 'Gzip Compression Enabled',
|
333 |
'plugin' => 'A2 Optimized',
|
349 |
$thisclass->enable_a2_page_cache_gzip();
|
350 |
},
|
351 |
'remove_link' => true
|
352 |
+
],
|
353 |
+
'a2_object_cache' => [
|
354 |
'slug' => 'a2_object_cache',
|
355 |
'name' => 'Memcache Object Caching',
|
356 |
'plugin' => 'A2 Optimized',
|
358 |
'description' => '
|
359 |
<ul>
|
360 |
<li>Extremely fast and powerful caching system.</li>
|
361 |
+
<li>Store frequently used database queries and WordPress objects in an in-memory object cache.</li>
|
362 |
+
<li>Object caching is a key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.</li>
|
363 |
<li>Take advantage of A2 Hosting's one-click memcached configuration for WordPress.</li>
|
364 |
</ul>
|
365 |
+
<strong>A supported object cache server and the corresponding PHP extension are required.</strong><br /><a href="admin.php?a2-page=cache_settings&page=A2_Optimized_Plugin_admin">Configure Object Cache Settings</a>
|
366 |
' . $a2_object_cache_additional_info,
|
367 |
'is_configured' => function (&$item) use (&$thisclass) {
|
368 |
if (get_option('a2_object_cache_enabled') == 1 && file_exists( WP_CONTENT_DIR . '/object-cache.php')) {
|
379 |
'enable' => function () use (&$thisclass) {
|
380 |
$thisclass->enable_a2_object_cache();
|
381 |
}
|
382 |
+
],
|
383 |
+
'a2_page_cache_minify_html' => [
|
384 |
'slug' => 'a2_page_cache_minify_html',
|
385 |
'name' => 'Minify HTML Pages',
|
386 |
'plugin' => 'A2 Optimized',
|
402 |
$thisclass->enable_a2_page_cache_minify_html();
|
403 |
},
|
404 |
'remove_link' => true
|
405 |
+
],
|
406 |
+
'a2_page_cache_minify_jscss' => [
|
407 |
'slug' => 'a2_page_cache_minify_jscss',
|
408 |
'name' => 'Minify Inline CSS and Javascript',
|
409 |
'plugin' => 'A2 Optimized',
|
426 |
$thisclass->enable_a2_page_cache_minify_jscss();
|
427 |
},
|
428 |
'remove_link' => true
|
429 |
+
]
|
430 |
+
];
|
431 |
}
|
432 |
|
433 |
/* Common optimizations */
|
434 |
+
$common_optimizations = [
|
435 |
+
'a2-db-optimizations' => [
|
436 |
+
'name' => 'Schedule Automatic Database Optimizations',
|
437 |
+
'slug' => 'a2-db-optimizations',
|
438 |
+
'plugin' => 'A2 Optimized',
|
439 |
+
'configured' => false,
|
440 |
+
'description' => 'If enabled, will periodically clean the MySQL database of expired transients, trashed comments, spam comments, and optimize all tables. You may also select to remove post revisions and trashed posts from the Database Optimization Settings.<br />
|
441 |
+
<a href="admin.php?a2-page=cache_settings&page=A2_Optimized_Plugin_admin">Configure Database Optimization Settings</a>',
|
442 |
+
'is_configured' => function (&$item) use (&$thisclass) {
|
443 |
+
$toggles = get_option(A2_Optimized_DBOptimizations::WP_SETTING);
|
444 |
+
if (isset($toggles[A2_Optimized_DBOptimizations::CRON_ACTIVE]) && $toggles[A2_Optimized_DBOptimizations::CRON_ACTIVE]) {
|
445 |
+
$item['configured'] = true;
|
446 |
+
$thisclass->set_install_status('a2-db-optimizations', true);
|
447 |
+
} else {
|
448 |
+
$thisclass->set_install_status('a2-db-optimizations', false);
|
449 |
+
}
|
450 |
+
},
|
451 |
+
'enable' => function () use (&$thisclass) {
|
452 |
+
A2_Optimized_DBOptimizations::set(A2_Optimized_DBOptimizations::CRON_ACTIVE, true);
|
453 |
+
},
|
454 |
+
'disable' => function () use (&$thisclass) {
|
455 |
+
A2_Optimized_DBOptimizations::set(A2_Optimized_DBOptimizations::CRON_ACTIVE, false);
|
456 |
+
},
|
457 |
+
],
|
458 |
+
'woo-cart-fragments' => [
|
459 |
'name' => 'Dequeue WooCommerce Cart Fragments AJAX calls',
|
460 |
'slug' => 'woo-cart-fragments',
|
461 |
'plugin' => 'A2 Optimized',
|
476 |
'disable' => function () use (&$thisclass) {
|
477 |
$thisclass->disable_woo_cart_fragments();
|
478 |
},
|
479 |
+
],
|
480 |
+
'xmlrpc-requests' => [
|
481 |
'name' => 'Block Unauthorized XML-RPC Requests',
|
482 |
'slug' => 'xmlrpc-requests',
|
483 |
'plugin' => 'A2 Optimized',
|
500 |
'disable' => function () use (&$thisclass) {
|
501 |
$thisclass->disable_xmlrpc_requests();
|
502 |
},
|
503 |
+
],
|
504 |
+
'regenerate-salts' => [
|
505 |
'name' => 'Regenerate wp-config salts',
|
506 |
'slug' => 'regenerate-salts',
|
507 |
'plugin' => 'A2 Optimized',
|
521 |
'enable' => function () use (&$thisclass) {
|
522 |
$thisclass->regenerate_wpconfig_salts();
|
523 |
},
|
524 |
+
],
|
525 |
+
'htaccess' => [
|
526 |
'name' => 'Deny Direct Access to Configuration Files and Comment Form',
|
527 |
'slug' => 'htaccess',
|
528 |
'plugin' => 'A2 Optimized',
|
552 |
$thisclass->set_deny_direct(false);
|
553 |
$thisclass->write_htaccess();
|
554 |
}
|
555 |
+
],
|
556 |
+
'lock' => [
|
557 |
'name' => 'Lock Editing of Plugins and Themes from the WP Admin',
|
558 |
'slug' => 'lock',
|
559 |
'plugin' => 'A2 Optimized',
|
581 |
$thisclass->set_lockdown(false);
|
582 |
$thisclass->write_wp_config();
|
583 |
}
|
584 |
+
],
|
585 |
+
'wp-login' => [
|
586 |
'name' => 'Login URL Change',
|
587 |
'slug' => 'wp-login',
|
588 |
'premium' => true,
|
595 |
'is_configured' => function () {
|
596 |
return false;
|
597 |
}
|
598 |
+
],
|
599 |
+
'captcha' => [
|
600 |
'name' => 'reCAPTCHA on comments and login',
|
601 |
'plugin' => 'reCAPTCHA',
|
602 |
'slug' => 'captcha',
|
606 |
'is_configured' => function () {
|
607 |
return false;
|
608 |
}
|
609 |
+
],
|
610 |
+
'images' => [
|
611 |
'name' => 'Compress Images on Upload',
|
612 |
'plugin' => 'Image Optimizer',
|
613 |
'slug' => 'images',
|
617 |
'is_configured' => function () {
|
618 |
return false;
|
619 |
}
|
620 |
+
],
|
621 |
+
'turbo' => [
|
622 |
'name' => 'Turbo Web Hosting',
|
623 |
'slug' => 'turbo',
|
624 |
'configured' => false,
|
635 |
'is_configured' => function () {
|
636 |
return false;
|
637 |
}
|
638 |
+
]
|
639 |
+
];
|
640 |
|
641 |
$optimizations = array_merge($optimizations, $common_optimizations);
|
642 |
|
643 |
+
$optimizations = $this->apply_optimization_filter($optimizations);
|
644 |
+
|
645 |
+
return $optimizations;
|
646 |
+
}
|
647 |
+
|
648 |
+
/*
|
649 |
+
* Changes to optimizations based on various factors
|
650 |
+
*/
|
651 |
+
public function apply_optimization_filter($optimizations) {
|
652 |
if (get_template() == 'Divi') {
|
653 |
$optimizations['minify']['optional'] = true;
|
654 |
$optimizations['css_minify']['optional'] = true;
|
655 |
$optimizations['js_minify']['optional'] = true;
|
656 |
}
|
657 |
|
658 |
+
if (is_plugin_active('litespeed-cache/litespeed-cache.php')) {
|
659 |
+
$optimizations['a2_object_cache']['name'] = 'Object Caching with Memcached or Redis';
|
660 |
+
if (get_option('litespeed.conf.object') == 1) {
|
661 |
+
$optimizations['a2_object_cache']['configured'] = true;
|
662 |
+
$optimizations['a2_object_cache']['description'] .= '<br /><strong>This feature is provided by the LiteSpeed Cache plugin.</strong></p>';
|
663 |
+
unset($optimizations['a2_object_cache']['disable']);
|
664 |
+
}
|
665 |
+
if (class_exists('A2_Optimized_Private_Optimizations')) {
|
666 |
+
$a2opt_priv = new A2_Optimized_Private_Optimizations();
|
667 |
+
$file_path = $a2opt_priv->get_redis_socket();
|
668 |
+
$optimizations['a2_object_cache']['description'] .= "<br />$file_path";
|
669 |
+
}
|
670 |
+
}
|
671 |
+
if (get_option('a2_optimized_memcached_invalid')) {
|
672 |
+
unset($optimizations['a2_object_cache']['enable']);
|
673 |
+
}
|
674 |
+
|
675 |
return $optimizations;
|
676 |
}
|
677 |
|
681 |
|
682 |
return $a2opt_priv->get_optimizations($this->thisclass);
|
683 |
} else {
|
684 |
+
return [];
|
685 |
}
|
686 |
}
|
687 |
|
695 |
protected function get_public_advanced() {
|
696 |
$thisclass = $this->thisclass;
|
697 |
|
698 |
+
return [
|
699 |
+
'gtmetrix' => [
|
700 |
'slug' => 'gtmetrix',
|
701 |
'name' => 'GTmetrix',
|
702 |
'plugin' => 'GTmetrix',
|
704 |
'file' => 'gtmetrix-for-wordpress/gtmetrix-for-wordpress.php',
|
705 |
'configured' => false,
|
706 |
'partially_configured' => false,
|
707 |
+
'required_options' => ['gfw_options' => ['authorized']],
|
708 |
'description' => '
|
709 |
<p>
|
710 |
Plugin that actively keeps track of your WP install and sends you alerts if your site falls below certain criteria.
|
714 |
<b>Use this plugin only if your site is experiencing issues with slow load times.</b><br><b style="color:red">The GTMetrix plugin will slow down your site.</b>
|
715 |
</p>
|
716 |
',
|
717 |
+
'not_configured_links' => [],
|
718 |
+
'configured_links' => [
|
719 |
'Configure GTmetrix' => 'admin.php?page=gfw_settings',
|
720 |
'GTmetrix Tests' => 'admin.php?page=gfw_tests',
|
721 |
+
],
|
722 |
+
'partially_configured_links' => [
|
723 |
'Configure GTmetrix' => 'admin.php?page=gfw_settings',
|
724 |
'GTmetrix Tests' => 'admin.php?page=gfw_tests',
|
725 |
+
],
|
726 |
'partially_configured_message' => 'Click "Configure GTmetrix" to enter your GTmetrix Account Email and GTmetrix API Key.',
|
727 |
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
|
728 |
'is_configured' => function (&$item) use (&$thisclass) {
|
751 |
$item = $item[$slug];
|
752 |
$thisclass->deactivate_plugin($item['file']);
|
753 |
}
|
754 |
+
],
|
755 |
+
'cloudflare' => [
|
756 |
'slug' => 'cloudflare',
|
757 |
'name' => 'CloudFlare',
|
758 |
'premium' => true,
|
779 |
'is_configured' => function () {
|
780 |
return false;
|
781 |
},
|
782 |
+
'not_configured_links' => ['Host with A2' => 'https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized']
|
783 |
+
]
|
784 |
+
];
|
785 |
}
|
786 |
|
787 |
protected function get_private_advanced() {
|
790 |
|
791 |
return $a2opt_priv->get_advanced($this->thisclass);
|
792 |
} else {
|
793 |
+
return [];
|
794 |
}
|
795 |
}
|
796 |
|
802 |
}
|
803 |
|
804 |
protected function get_public_warnings() {
|
805 |
+
return [
|
806 |
+
'Bad WP Options' => [
|
807 |
+
'posts_per_page' => [
|
808 |
'title' => 'Recent Post Limit',
|
809 |
'description' => 'The number of recent posts per page is set greater than five. This could be slowing down page loads.',
|
810 |
'type' => 'numeric',
|
811 |
'threshold_type' => '>',
|
812 |
'threshold' => 5,
|
813 |
'config_url' => admin_url() . 'options-reading.php'
|
814 |
+
],
|
815 |
+
'posts_per_rss' => [
|
816 |
'title' => 'RSS Post Limit',
|
817 |
'description' => 'The number of posts from external feeds is set greater than 5. This could be slowing down page loads.',
|
818 |
'type' => 'numeric',
|
819 |
'threshold_type' => '>',
|
820 |
'threshold' => 5,
|
821 |
'config_url' => admin_url() . 'options-reading.php'
|
822 |
+
],
|
823 |
+
'show_on_front' => [
|
824 |
'title' => 'Recent Posts showing on home page',
|
825 |
'description' => 'Speed up your home page by selecting a static page to display.',
|
826 |
'type' => 'text',
|
827 |
'threshold_type' => '=',
|
828 |
'threshold' => 'posts',
|
829 |
'config_url' => admin_url() . 'options-reading.php'
|
830 |
+
],
|
831 |
+
'permalink_structure' => [
|
832 |
'title' => 'Permalink Structure',
|
833 |
'description' => 'To fully optimize page caching with "Disk Enhanced" mode:<br>you must set a permalink structure other than "Default".',
|
834 |
'type' => 'text',
|
835 |
'threshold_type' => '=',
|
836 |
'threshold' => '',
|
837 |
'config_url' => admin_url() . 'options-permalink.php'
|
838 |
+
]
|
839 |
+
],
|
840 |
+
'Advanced Warnings' => [
|
841 |
+
'themes' => [
|
842 |
'is_warning' => function () {
|
843 |
$theme_count = 0;
|
844 |
$themes = wp_get_themes();
|
863 |
'title' => 'Unused Themes',
|
864 |
'description' => 'One or more unused non-default themes are installed. Unused non-default themes should be deleted. For more information read the Wordpress.org Codex on <a target="_blank" href="http://codex.wordpress.org/WordPress_Housekeeping#Theme_Housekeeping">WordPress Housekeeping</a>',
|
865 |
'config_url' => admin_url() . 'themes.php'
|
866 |
+
],
|
867 |
+
'a2_hosting' => [
|
868 |
'title' => 'Not Hosted with A2 Hosting',
|
869 |
'description' => 'Get faster page load times and more optimizations when you <a href="https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized" target="_blank">host with A2 Hosting</a>.',
|
870 |
'is_warning' => function () {
|
875 |
return true;
|
876 |
},
|
877 |
'config_url' => 'https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized'
|
878 |
+
]
|
879 |
+
],
|
880 |
+
'Bad Plugins' => [
|
881 |
'wp-super-cache',
|
882 |
'wp-file-cache',
|
883 |
'wp-db-backup',
|
884 |
+
]
|
885 |
+
];
|
886 |
}
|
887 |
|
888 |
protected function get_private_warnings() {
|
891 |
|
892 |
return $a2opt_priv->get_warnings($this->thisclass);
|
893 |
} else {
|
894 |
+
return [];
|
895 |
}
|
896 |
}
|
897 |
}
|
A2_Optimized_OptionsManager.php
CHANGED
@@ -69,7 +69,7 @@ class A2_Optimized_OptionsManager {
|
|
69 |
* @return array
|
70 |
*/
|
71 |
public function get_w3tc_defaults() {
|
72 |
-
return
|
73 |
'pgcache.check.domain' => true,
|
74 |
'pgcache.prime.post.enabled' => true,
|
75 |
'pgcache.reject.logged' => true,
|
@@ -90,12 +90,12 @@ class A2_Optimized_OptionsManager {
|
|
90 |
'pgcache.cache.feed' => true,
|
91 |
'pgcache.debug' => false,
|
92 |
'pgcache.purge.postpages_limit' => 0,//purge all pages that list posts
|
93 |
-
'pgcache.purge.feed.types' =>
|
94 |
0 => 'rdf',
|
95 |
1 => 'rss',
|
96 |
2 => 'rss2',
|
97 |
3 => 'atom'
|
98 |
-
|
99 |
'pgcache.compatibility' => true,
|
100 |
'minify.debug' => false,
|
101 |
'dbcache.debug' => false,
|
@@ -154,7 +154,7 @@ class A2_Optimized_OptionsManager {
|
|
154 |
'config.check' => true,
|
155 |
|
156 |
'varnish.enabled' => false
|
157 |
-
|
158 |
}
|
159 |
|
160 |
/**
|
@@ -191,7 +191,7 @@ class A2_Optimized_OptionsManager {
|
|
191 |
public function install_plugin($slug, $activate = false) {
|
192 |
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
193 |
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
|
194 |
-
$api = plugins_api('plugin_information',
|
195 |
$response = true;
|
196 |
|
197 |
$found = false;
|
@@ -256,9 +256,9 @@ class A2_Optimized_OptionsManager {
|
|
256 |
*
|
257 |
*/
|
258 |
public function hit_the_w3tc_page() {
|
259 |
-
$disregarded_cookies =
|
260 |
'PHPSESSID',
|
261 |
-
|
262 |
|
263 |
$cookie = '';
|
264 |
foreach ($_COOKIE as $name => $val) {
|
@@ -304,7 +304,7 @@ class A2_Optimized_OptionsManager {
|
|
304 |
*/
|
305 |
public function enable_w3tc_cache() {
|
306 |
$permalink_structure = get_option('permalink_structure');
|
307 |
-
$vars =
|
308 |
if ($permalink_structure == '') {
|
309 |
$vars['pgcache.engine'] = 'file';
|
310 |
} else {
|
@@ -329,7 +329,7 @@ class A2_Optimized_OptionsManager {
|
|
329 |
*/
|
330 |
public function enable_w3tc_page_cache() {
|
331 |
$permalink_structure = get_option('permalink_structure');
|
332 |
-
$vars =
|
333 |
if ($permalink_structure == '') {
|
334 |
$vars['pgcache.engine'] = 'file';
|
335 |
} else {
|
@@ -348,7 +348,7 @@ class A2_Optimized_OptionsManager {
|
|
348 |
*
|
349 |
*/
|
350 |
public function enable_w3tc_db_cache() {
|
351 |
-
$vars =
|
352 |
|
353 |
$vars['dbcache.engine'] = 'file';
|
354 |
$vars['dbcache.enabled'] = true;
|
@@ -361,7 +361,7 @@ class A2_Optimized_OptionsManager {
|
|
361 |
*
|
362 |
*/
|
363 |
public function enable_w3tc_object_cache() {
|
364 |
-
$vars =
|
365 |
|
366 |
$vars['objectcache.engine'] = 'file';
|
367 |
$vars['objectcache.enabled'] = true;
|
@@ -374,7 +374,7 @@ class A2_Optimized_OptionsManager {
|
|
374 |
*
|
375 |
*/
|
376 |
public function enable_w3tc_browser_cache() {
|
377 |
-
$vars =
|
378 |
|
379 |
$vars['browsercache.enabled'] = true;
|
380 |
|
@@ -386,7 +386,7 @@ class A2_Optimized_OptionsManager {
|
|
386 |
*
|
387 |
*/
|
388 |
public function enable_w3tc_gzip() {
|
389 |
-
$vars =
|
390 |
|
391 |
$vars['browsercache.other.compression'] = true;
|
392 |
$vars['browsercache.html.compression'] = true;
|
@@ -400,7 +400,7 @@ class A2_Optimized_OptionsManager {
|
|
400 |
*
|
401 |
*/
|
402 |
public function disable_w3tc_gzip() {
|
403 |
-
$vars =
|
404 |
|
405 |
$vars['browsercache.other.compression'] = false;
|
406 |
$vars['browsercache.html.compression'] = false;
|
@@ -408,7 +408,7 @@ class A2_Optimized_OptionsManager {
|
|
408 |
|
409 |
$this->update_w3tc($vars);
|
410 |
}
|
411 |
-
|
412 |
/**
|
413 |
* Enable built-in page cache
|
414 |
*
|
@@ -419,7 +419,7 @@ class A2_Optimized_OptionsManager {
|
|
419 |
|
420 |
update_option('a2_cache_enabled', 1);
|
421 |
}
|
422 |
-
|
423 |
/**
|
424 |
* Disable built-in page cache
|
425 |
*
|
@@ -427,37 +427,87 @@ class A2_Optimized_OptionsManager {
|
|
427 |
public function disable_a2_page_cache() {
|
428 |
A2_Optimized_Cache_Disk::clean();
|
429 |
A2_Optimized_Cache::update_backend();
|
430 |
-
|
431 |
update_option('a2_cache_enabled', 0);
|
432 |
}
|
433 |
-
|
434 |
/**
|
435 |
* Enable memcached object cache
|
436 |
*
|
437 |
*/
|
438 |
public function enable_a2_object_cache() {
|
439 |
-
if (get_option('a2_optimized_memcached_invalid')
|
|
|
440 |
return false;
|
441 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
|
443 |
-
|
|
|
|
|
|
|
444 |
|
445 |
-
|
446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
}
|
448 |
-
|
449 |
/**
|
450 |
* Disable memcached object cache
|
451 |
*
|
452 |
*/
|
453 |
public function disable_a2_object_cache() {
|
454 |
@unlink( WP_CONTENT_DIR . '/object-cache.php' );
|
455 |
-
|
456 |
$this->write_wp_config();
|
457 |
|
458 |
update_option('a2_object_cache_enabled', 0);
|
459 |
}
|
460 |
-
|
461 |
/**
|
462 |
* Enable built-in page cache gzip
|
463 |
*
|
@@ -473,7 +523,7 @@ class A2_Optimized_OptionsManager {
|
|
473 |
// Rebuild cache settings file
|
474 |
A2_Optimized_Cache_Disk::create_settings_file( $cache_settings );
|
475 |
}
|
476 |
-
|
477 |
/**
|
478 |
* Disable built-in page cache gzip
|
479 |
*
|
@@ -504,7 +554,7 @@ class A2_Optimized_OptionsManager {
|
|
504 |
// Rebuild cache settings file
|
505 |
A2_Optimized_Cache_Disk::create_settings_file( $cache_settings );
|
506 |
}
|
507 |
-
|
508 |
/**
|
509 |
* Disable built-in page cache html minification
|
510 |
*
|
@@ -537,7 +587,7 @@ class A2_Optimized_OptionsManager {
|
|
537 |
// Rebuild cache settings file
|
538 |
A2_Optimized_Cache_Disk::create_settings_file( $cache_settings );
|
539 |
}
|
540 |
-
|
541 |
/**
|
542 |
* Disable built-in page cache css/js minification
|
543 |
*
|
@@ -552,7 +602,7 @@ class A2_Optimized_OptionsManager {
|
|
552 |
// Rebuild cache settings file
|
553 |
A2_Optimized_Cache_Disk::create_settings_file( $cache_settings );
|
554 |
}
|
555 |
-
|
556 |
/**
|
557 |
* Enable WooCommerce Cart Fragment Dequeuing
|
558 |
*
|
@@ -561,7 +611,7 @@ class A2_Optimized_OptionsManager {
|
|
561 |
update_option('a2_wc_cart_fragments', 1);
|
562 |
update_option('woocommerce_cart_redirect_after_add', 'yes'); // Recommended WooCommerce setting when disabling cart fragments
|
563 |
}
|
564 |
-
|
565 |
/**
|
566 |
* Disable WooCommerce Cart Fragment Dequeuing
|
567 |
*
|
@@ -570,7 +620,7 @@ class A2_Optimized_OptionsManager {
|
|
570 |
delete_option('a2_wc_cart_fragments');
|
571 |
delete_option('woocommerce_cart_redirect_after_add');
|
572 |
}
|
573 |
-
|
574 |
/**
|
575 |
* Enable Blocking of XML-RPC Requests
|
576 |
*
|
@@ -578,7 +628,7 @@ class A2_Optimized_OptionsManager {
|
|
578 |
public function enable_xmlrpc_requests() {
|
579 |
update_option('a2_block_xmlrpc', 1);
|
580 |
}
|
581 |
-
|
582 |
/**
|
583 |
* Disable Blocking of XML-RPC Requests
|
584 |
*
|
@@ -592,7 +642,7 @@ class A2_Optimized_OptionsManager {
|
|
592 |
*
|
593 |
*/
|
594 |
public function regenerate_wpconfig_salts() {
|
595 |
-
$this->salts_array =
|
596 |
"define('AUTH_KEY',",
|
597 |
'SECURE_AUTH_KEY',
|
598 |
'LOGGED_IN_KEY',
|
@@ -601,7 +651,7 @@ class A2_Optimized_OptionsManager {
|
|
601 |
'SECURE_AUTH_SALT',
|
602 |
'LOGGED_IN_SALT',
|
603 |
'NONCE_SALT',
|
604 |
-
|
605 |
|
606 |
$returned_salts = file_get_contents('https://api.wordpress.org/secret-key/1.1/salt/');
|
607 |
$this->new_salts = explode("\n", $returned_salts);
|
@@ -613,7 +663,7 @@ class A2_Optimized_OptionsManager {
|
|
613 |
|
614 |
public function regenerate_wpconfig_desc() {
|
615 |
$output = '<p>Generate new salt values for wp-config.php<br /><strong>This will log out all users including yourself</strong><br />Last regenerated:</p>';
|
616 |
-
|
617 |
return $output;
|
618 |
}
|
619 |
|
@@ -646,7 +696,7 @@ class A2_Optimized_OptionsManager {
|
|
646 |
}
|
647 |
}
|
648 |
}
|
649 |
-
|
650 |
private function config_file_path() {
|
651 |
$salts_file_name = 'wp-config';
|
652 |
$config_file = ABSPATH . $salts_file_name . '.php';
|
@@ -686,12 +736,12 @@ class A2_Optimized_OptionsManager {
|
|
686 |
*
|
687 |
*/
|
688 |
public function disable_w3tc_cache() {
|
689 |
-
$this->update_w3tc(
|
690 |
'pgcache.enabled' => false,
|
691 |
'dbcache.enabled' => false,
|
692 |
'objectcache.enabled' => false,
|
693 |
'browsercache.enabled' => false,
|
694 |
-
)
|
695 |
}
|
696 |
|
697 |
/**
|
@@ -699,7 +749,7 @@ class A2_Optimized_OptionsManager {
|
|
699 |
*
|
700 |
*/
|
701 |
public function disable_w3tc_page_cache() {
|
702 |
-
$vars =
|
703 |
$vars['pgcache.enabled'] = false;
|
704 |
$this->update_w3tc($vars);
|
705 |
}
|
@@ -709,7 +759,7 @@ class A2_Optimized_OptionsManager {
|
|
709 |
*
|
710 |
*/
|
711 |
public function disable_w3tc_db_cache() {
|
712 |
-
$vars =
|
713 |
$vars['dbcache.enabled'] = false;
|
714 |
$this->update_w3tc($vars);
|
715 |
}
|
@@ -719,7 +769,7 @@ class A2_Optimized_OptionsManager {
|
|
719 |
*
|
720 |
*/
|
721 |
public function disable_w3tc_object_cache() {
|
722 |
-
$vars =
|
723 |
$vars['objectcache.enabled'] = false;
|
724 |
$this->update_w3tc($vars);
|
725 |
}
|
@@ -729,7 +779,7 @@ class A2_Optimized_OptionsManager {
|
|
729 |
*
|
730 |
*/
|
731 |
public function disable_w3tc_browser_cache() {
|
732 |
-
$vars =
|
733 |
$vars['browsercache.enabled'] = false;
|
734 |
$this->update_w3tc($vars);
|
735 |
}
|
@@ -739,11 +789,11 @@ class A2_Optimized_OptionsManager {
|
|
739 |
*
|
740 |
*/
|
741 |
public function disable_html_minify() {
|
742 |
-
$this->update_w3tc(
|
743 |
'minify.html.enable' => false,
|
744 |
'minify.html.enabled' => false,
|
745 |
'minify.auto' => false
|
746 |
-
)
|
747 |
}
|
748 |
|
749 |
/**
|
@@ -751,12 +801,12 @@ class A2_Optimized_OptionsManager {
|
|
751 |
*
|
752 |
*/
|
753 |
public function enable_html_minify() {
|
754 |
-
$this->update_w3tc(
|
755 |
'minify.html.enable' => true,
|
756 |
'minify.enabled' => true,
|
757 |
'minify.auto' => false,
|
758 |
'minify.engine' => 'file'
|
759 |
-
)
|
760 |
}
|
761 |
|
762 |
public function curl_save_w3tc($cookie, $url) {
|
@@ -795,7 +845,7 @@ class A2_Optimized_OptionsManager {
|
|
795 |
|
796 |
wp_enqueue_style('bootstrap', plugins_url('/assets/bootstrap/css/bootstrap.css', __FILE__), '', $thisclass->getVersion());
|
797 |
wp_enqueue_style('bootstrap-theme', plugins_url('/assets/bootstrap/css/bootstrap-theme.css', __FILE__), '', $thisclass->getVersion());
|
798 |
-
wp_enqueue_script('bootstrap-theme', plugins_url('/assets/bootstrap/js/bootstrap.js', __FILE__),
|
799 |
|
800 |
$image_dir = plugins_url('/assets/images', __FILE__);
|
801 |
|
@@ -849,7 +899,7 @@ class A2_Optimized_OptionsManager {
|
|
849 |
}
|
850 |
|
851 |
if ($_GET['a2-page'] == 'dismiss_notice') {
|
852 |
-
$allowed_notices =
|
853 |
'a2_login_bookmark',
|
854 |
'a2_notice_incompatible_plugins',
|
855 |
'a2_notice_w3totalcache',
|
@@ -858,7 +908,7 @@ class A2_Optimized_OptionsManager {
|
|
858 |
'a2_notice_wordfence_waf',
|
859 |
'a2_notice_configpage',
|
860 |
'a2_notice_diviminify',
|
861 |
-
|
862 |
if (isset($_GET['a2-option']) && in_array($_GET['a2-option'], $allowed_notices)) {
|
863 |
if ($_GET['a2-option'] == 'a2_login_bookmark') {
|
864 |
update_option('a2_login_bookmark', get_option('a2_login_page'));
|
@@ -1005,7 +1055,7 @@ HTML;
|
|
1005 |
if (isset($_GET['save_settings']) && $_GET['save_settings']) {
|
1006 |
$save_alert = '<div class="alert alert-success">Settings Saved</div>';
|
1007 |
}
|
1008 |
-
|
1009 |
if (isset($_GET['msg']) && $_GET['msg'] == 'token') {
|
1010 |
$save_alert = '<div class="alert alert-danger">Session timed out, please try to configure your optimization again.</div>';
|
1011 |
}
|
@@ -1020,8 +1070,6 @@ HTML;
|
|
1020 |
$settingsGroup = get_class($this) . '-settings-group';
|
1021 |
$description = $this->get_plugin_description();
|
1022 |
|
1023 |
-
|
1024 |
-
|
1025 |
if ($this->is_a2()) {
|
1026 |
$feedback = <<<HTML
|
1027 |
<div style="margin:10px 0;" class="alert alert-success">
|
@@ -1254,7 +1302,7 @@ HTML;
|
|
1254 |
|
1255 |
HTML;
|
1256 |
}
|
1257 |
-
|
1258 |
/**
|
1259 |
* Wizard to migrate from the W3TC plugin
|
1260 |
* @param integer $setup_step The step to begin install process
|
@@ -1264,43 +1312,43 @@ HTML;
|
|
1264 |
$image_dir = plugins_url('/assets/images', __FILE__);
|
1265 |
$kb_search_box = $this->kb_searchbox_html();
|
1266 |
$w3tc_settings = $this->get_w3tc_config();
|
1267 |
-
$migrated_settings =
|
1268 |
-
$migrated_settings['page_cache'] =
|
1269 |
'name' => 'Enable Page Caching',
|
1270 |
'w3tc_value' => $w3tc_settings['pgcache.enabled']
|
1271 |
-
|
1272 |
-
$migrated_settings['excluded_cookies'] =
|
1273 |
'name' => 'Do not cache requests that have these cookies',
|
1274 |
'w3tc_value' => $w3tc_settings['pgcache.reject.cookie']
|
1275 |
-
|
1276 |
-
$migrated_settings['object_cache'] =
|
1277 |
'name' => 'Enable Memcached Object Caching',
|
1278 |
'w3tc_value' => $w3tc_settings['objectcache.enabled']
|
1279 |
-
|
1280 |
-
$migrated_settings['memcached_server'] =
|
1281 |
'name' => 'Memcached Servers',
|
1282 |
'w3tc_value' => $w3tc_settings['objectcache.memcached.servers']
|
1283 |
-
|
1284 |
-
$migrated_settings['clear_site_cache_on_saved_post'] =
|
1285 |
'name' => 'Clear cache when saving post',
|
1286 |
'w3tc_value' => $w3tc_settings['pgcache.purge.post']
|
1287 |
-
|
1288 |
-
$migrated_settings['clear_site_cache_on_saved_comment'] =
|
1289 |
'name' => 'Clear cache when a new comment is added',
|
1290 |
'w3tc_value' => $w3tc_settings['pgcache.purge.comments']
|
1291 |
-
|
1292 |
-
$migrated_settings['compress_cache'] =
|
1293 |
'name' => 'GZIP compress cached pages',
|
1294 |
'w3tc_value' => $w3tc_settings['browsercache.html.compression']
|
1295 |
-
|
1296 |
-
$migrated_settings['minify_html'] =
|
1297 |
'name' => 'HTML Minification',
|
1298 |
'w3tc_value' => $w3tc_settings['minify.html.enable']
|
1299 |
-
|
1300 |
-
$migrated_settings['minify_inline_css_js'] =
|
1301 |
'name' => 'Javascript and CSS Minification',
|
1302 |
'w3tc_value' => $w3tc_settings['minify.js.enable']
|
1303 |
-
|
1304 |
|
1305 |
if ($setup_step == 1) {
|
1306 |
echo <<<HTML
|
@@ -1350,10 +1398,10 @@ HTML;
|
|
1350 |
$value = 'Not set';
|
1351 |
}
|
1352 |
}
|
1353 |
-
|
1354 |
$step_output .= '<li><strong>' . $item['name'] . '</strong>: ' . $value . '</li>';
|
1355 |
}
|
1356 |
-
|
1357 |
$step_output .= "</ul><p>Next we will need to deactivate the W3 Total Cache plugin.</p><p><a href='" . admin_url('admin.php?a2-page=w3tc_migration_wizard&page=A2_Optimized_Plugin_admin&step=2') . "' class='btn btn-success'>Deactivate</a></p>";
|
1358 |
echo <<<HTML
|
1359 |
<div>
|
@@ -1673,7 +1721,7 @@ HTML;
|
|
1673 |
update_option('a2_recaptcha_secretkey', sanitize_text_field($_POST['a2_recaptcha_secretkey']));
|
1674 |
update_option('a2_recaptcha_theme', sanitize_text_field($_POST['a2_recaptcha_theme']));
|
1675 |
}
|
1676 |
-
|
1677 |
/**
|
1678 |
* Cache Settings Page
|
1679 |
*
|
@@ -1681,7 +1729,8 @@ HTML;
|
|
1681 |
private function cache_settings_html() {
|
1682 |
$image_dir = plugins_url('/assets/images', __FILE__);
|
1683 |
$kb_search_box = $this->kb_searchbox_html();
|
1684 |
-
$admin_url = 'options.php';
|
|
|
1685 |
<section id="a2opt-content-general">
|
1686 |
<div class="wrap">
|
1687 |
<div>
|
@@ -1704,7 +1753,7 @@ HTML;
|
|
1704 |
<?php if (get_option('a2_optimized_memcached_invalid')) { ?>
|
1705 |
<div class="notice notice-error"><p>There is an issue with your Memcached settings<br /><?php echo get_option('a2_optimized_memcached_invalid'); ?></p></div>
|
1706 |
<?php } ?>
|
1707 |
-
<h3>Advanced
|
1708 |
<div>
|
1709 |
<form method="post" action="<?php echo $admin_url; ?>">
|
1710 |
<?php settings_fields( 'a2opt-cache' ); ?>
|
@@ -1767,10 +1816,10 @@ HTML;
|
|
1767 |
</label>
|
1768 |
<label for="minify_inline_css_js">
|
1769 |
<?php
|
1770 |
-
$minify_inline_css_js_options =
|
1771 |
esc_html__( 'excluding', 'a2-optimized-wp' ) => 0,
|
1772 |
esc_html__( 'including', 'a2-optimized-wp' ) => 1,
|
1773 |
-
|
1774 |
$minify_inline_css_js = '<select name="a2opt-cache[minify_inline_css_js]" id="minify_inline_css_js">';
|
1775 |
foreach ( $minify_inline_css_js_options as $key => $value ) {
|
1776 |
$minify_inline_css_js .= '<option value="' . esc_attr( $value ) . '"' . selected( $value, A2_Optimized_Cache_Engine::$settings['minify_inline_css_js'], false ) . '>' . $key . '</option>';
|
@@ -1840,6 +1889,39 @@ HTML;
|
|
1840 |
</th>
|
1841 |
<td>
|
1842 |
<fieldset>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1843 |
<p class="subheading"><?php esc_html_e( 'Memcached Server', 'a2-optimized-wp' ); ?></p>
|
1844 |
<label for="memcached_server">
|
1845 |
<input name="a2_optimized_memcached_server" type="text" id="memcached_server" value="<?php echo esc_attr( get_option('a2_optimized_memcached_server') ) ?>" class="regular-text" />
|
@@ -1852,12 +1934,64 @@ HTML;
|
|
1852 |
</fieldset>
|
1853 |
</td>
|
1854 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1855 |
</table>
|
1856 |
|
1857 |
<p class="submit">
|
1858 |
<?php wp_nonce_field( 'a2opt-cache-save', 'a2opt-cache-nonce' ); ?>
|
1859 |
<input type="submit" class="button-secondary" value="<?php esc_html_e( 'Save Changes', 'a2-optimized-wp' ); ?>" />
|
1860 |
<input name="a2opt-cache[clear_site_cache_on_saved_settings]" type="submit" class="button-primary" value="<?php esc_html_e( 'Save Changes and Clear Site Cache', 'a2-optimized-wp' ); ?>" />
|
|
|
1861 |
</p>
|
1862 |
</form>
|
1863 |
</div>
|
@@ -1880,6 +2014,7 @@ HTML;
|
|
1880 |
}
|
1881 |
|
1882 |
if (check_admin_referer('a2opt-cache-save', 'a2opt-cache-nonce')) {
|
|
|
1883 |
$a2opt_cache = sanitize_text_field($_REQUEST['a2opt-cache']);
|
1884 |
$a2_memcached_server = sanitize_text_field($_REQUEST['a2_optimized_memcached_server']);
|
1885 |
update_option('a2opt-cache', $a2opt_cache);
|
@@ -1887,7 +2022,7 @@ HTML;
|
|
1887 |
$this->write_wp_config();
|
1888 |
}
|
1889 |
}
|
1890 |
-
|
1891 |
/**
|
1892 |
* Site Health View Page
|
1893 |
*
|
@@ -1899,26 +2034,24 @@ HTML;
|
|
1899 |
}
|
1900 |
|
1901 |
$saved_health_items = get_option('a2opt-sitehealth-results');
|
1902 |
-
|
1903 |
$current_site_health = null;
|
1904 |
|
1905 |
if (isset($_REQUEST['view_report'])) {
|
1906 |
-
foreach($saved_health_items as $date => $item){
|
1907 |
-
if(md5($date) == $_REQUEST['view_report']){
|
1908 |
$current_site_health = $item;
|
1909 |
$site_health_date = $date;
|
1910 |
-
}
|
1911 |
-
}
|
1912 |
}
|
1913 |
-
if(!$current_site_health){
|
1914 |
$WP_Debug_Data = new WP_Debug_Data();
|
1915 |
new A2_Optimized_SiteHealth;
|
1916 |
$info = $WP_Debug_Data::debug_data();
|
1917 |
$current_site_health = $WP_Debug_Data::format( $info, 'debug' );
|
1918 |
$site_health_date = date('Y-m-d H:i:s');
|
1919 |
-
}
|
1920 |
-
|
1921 |
-
?>
|
1922 |
<section id="a2opt-content-general">
|
1923 |
<div class="wrap">
|
1924 |
<div>
|
@@ -1947,17 +2080,17 @@ HTML;
|
|
1947 |
<?php } else { ?>
|
1948 |
<h3>Site Health Results</h3>
|
1949 |
<p><a href="admin.php?a2-page=site_health_save&page=A2_Optimized_Plugin_admin" class="button">Save current results</a> <a href="site-health.php?tab=debug" class="button">Back to Site Health</a></p>
|
1950 |
-
<?php }
|
1951 |
-
<?php if(count($saved_health_items) > 0){ ?>
|
1952 |
<p>
|
1953 |
<strong>Saved reports</strong>
|
1954 |
<ul>
|
1955 |
-
<?php foreach($saved_health_items as $date => $item){ ?>
|
1956 |
<li><a href="admin.php?a2-page=site_health&page=A2_Optimized_Plugin_admin&view_report=<?php echo md5($date); ?>"><?php echo $date; ?></a></li>
|
1957 |
-
<?php }
|
1958 |
</ul>
|
1959 |
</p>
|
1960 |
-
<?php }
|
1961 |
<div>
|
1962 |
<pre>
|
1963 |
<?php echo $current_site_health; ?>
|
@@ -1980,14 +2113,14 @@ HTML;
|
|
1980 |
if (!current_user_can('manage_options')) {
|
1981 |
die('Cheating eh?');
|
1982 |
}
|
1983 |
-
|
1984 |
if ( ! class_exists( 'WP_Debug_Data' ) ) {
|
1985 |
require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php';
|
1986 |
}
|
1987 |
|
1988 |
$existing_health = get_option('a2opt-sitehealth-results');
|
1989 |
|
1990 |
-
if(!$existing_health){
|
1991 |
$existing_health = [];
|
1992 |
}
|
1993 |
|
@@ -1997,10 +2130,10 @@ HTML;
|
|
1997 |
$current_site_health = $WP_Debug_Data::format( $info, 'debug' );
|
1998 |
|
1999 |
$existing_health[date('Y-m-d H:i:s')] = $current_site_health;
|
2000 |
-
|
2001 |
update_option('a2opt-sitehealth-results', $existing_health);
|
2002 |
}
|
2003 |
-
|
2004 |
/**
|
2005 |
* Remove Site Health Results
|
2006 |
*
|
@@ -2009,22 +2142,21 @@ HTML;
|
|
2009 |
if (!current_user_can('manage_options')) {
|
2010 |
die('Cheating eh?');
|
2011 |
}
|
2012 |
-
|
2013 |
$existing_health = get_option('a2opt-sitehealth-results');
|
2014 |
|
2015 |
-
if(is_array($existing_health)){
|
2016 |
$index_to_remove = 0;
|
2017 |
-
foreach($existing_health as $date => $item){
|
2018 |
-
if(md5($date) == $_REQUEST['remove_report']){
|
2019 |
$index_to_remove = $date;
|
2020 |
}
|
2021 |
}
|
2022 |
-
if($index_to_remove !== 0){
|
2023 |
unset($existing_health[$index_to_remove]);
|
2024 |
update_option('a2opt-sitehealth-results', $existing_health);
|
2025 |
}
|
2026 |
}
|
2027 |
-
|
2028 |
}
|
2029 |
|
2030 |
/**
|
@@ -2054,7 +2186,7 @@ HTML;
|
|
2054 |
private function get_a2_token($slug) {
|
2055 |
return get_transient('a2_token-' . $slug);
|
2056 |
}
|
2057 |
-
|
2058 |
/**
|
2059 |
* Set a2 token in transients
|
2060 |
*/
|
@@ -2085,7 +2217,7 @@ HTML;
|
|
2085 |
|
2086 |
if (isset($_GET['disable_optimization']) && $url_token) {
|
2087 |
$hash = '';
|
2088 |
-
|
2089 |
$optimization = sanitize_text_field($_GET['disable_optimization']);
|
2090 |
|
2091 |
$a2_token = $this->get_a2_token($optimization);
|
@@ -2112,7 +2244,7 @@ JAVASCRIPT;
|
|
2112 |
|
2113 |
if (isset($_GET['enable_optimization']) && $url_token) {
|
2114 |
$hash = '';
|
2115 |
-
|
2116 |
$optimization = sanitize_text_field($_GET['enable_optimization']);
|
2117 |
|
2118 |
$a2_token = $this->get_a2_token($optimization);
|
@@ -2136,7 +2268,7 @@ JAVASCRIPT;
|
|
2136 |
JAVASCRIPT;
|
2137 |
exit();
|
2138 |
}
|
2139 |
-
|
2140 |
if (isset($_GET['apply_divi_settings']) && $url_token) {
|
2141 |
$this->optimizations['minify']['disable']('minify');
|
2142 |
$this->optimizations['css_minify']['disable']('css_minify');
|
@@ -2178,6 +2310,7 @@ JAVASCRIPT;
|
|
2178 |
*/
|
2179 |
public function addOption($optionName, $value) {
|
2180 |
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
|
|
|
2181 |
return add_option($prefixedOptionName, $value);
|
2182 |
}
|
2183 |
|
@@ -2226,7 +2359,7 @@ JAVASCRIPT;
|
|
2226 |
$this->deactivate_plugin($file);
|
2227 |
uninstall_plugin($file);
|
2228 |
if ($delete) {
|
2229 |
-
delete_plugins(
|
2230 |
}
|
2231 |
unset($this->plugin_list[$file]);
|
2232 |
$this->clear_w3_total_cache();
|
@@ -2262,7 +2395,7 @@ JAVASCRIPT;
|
|
2262 |
* 'Rating:', 'Excellent', 'Good', 'Fair', 'Poor')
|
2263 |
*/
|
2264 |
public function getOptionMetaData() {
|
2265 |
-
return
|
2266 |
}
|
2267 |
|
2268 |
private function curl($url) {
|
@@ -2297,7 +2430,7 @@ JAVASCRIPT;
|
|
2297 |
$active_color = 'danger';
|
2298 |
$active_text = 'Not Activated';
|
2299 |
$glyph = 'exclamation-sign';
|
2300 |
-
$links =
|
2301 |
|
2302 |
$active_class = '';
|
2303 |
if (
|
@@ -2323,19 +2456,19 @@ JAVASCRIPT;
|
|
2323 |
// used for Gzip options
|
2324 |
} else {
|
2325 |
$a2_token = $this->set_a2_token($item['slug']);
|
2326 |
-
$links[] =
|
2327 |
}
|
2328 |
}
|
2329 |
if (isset($item['settings'])) {
|
2330 |
-
$links[] =
|
2331 |
}
|
2332 |
|
2333 |
if (isset($item['configured_links'])) {
|
2334 |
foreach ($item['configured_links'] as $name => $link) {
|
2335 |
if (gettype($link) == 'array') {
|
2336 |
-
$links[] =
|
2337 |
} else {
|
2338 |
-
$links[] =
|
2339 |
}
|
2340 |
}
|
2341 |
}
|
@@ -2349,18 +2482,18 @@ JAVASCRIPT;
|
|
2349 |
|
2350 |
if (isset($item['disable'])) {
|
2351 |
$a2_token = $this->set_a2_token($item['slug']);
|
2352 |
-
$links[] =
|
2353 |
}
|
2354 |
if (isset($item['settings'])) {
|
2355 |
-
$links[] =
|
2356 |
}
|
2357 |
|
2358 |
if (isset($item['partially_configured_links'])) {
|
2359 |
foreach ($item['partially_configured_links'] as $name => $link) {
|
2360 |
if (gettype($link) == 'array') {
|
2361 |
-
$links[] =
|
2362 |
} else {
|
2363 |
-
$links[] =
|
2364 |
}
|
2365 |
}
|
2366 |
}
|
@@ -2374,36 +2507,36 @@ JAVASCRIPT;
|
|
2374 |
$action_text = 'Update Now';
|
2375 |
}
|
2376 |
$a2_token = $this->set_a2_token($item['slug']);
|
2377 |
-
$links[] =
|
2378 |
}
|
2379 |
|
2380 |
if (isset($item['not_configured_links'])) {
|
2381 |
foreach ($item['not_configured_links'] as $name => $link) {
|
2382 |
if (gettype($link) == 'array') {
|
2383 |
-
$links[] =
|
2384 |
} else {
|
2385 |
-
$links[] =
|
2386 |
}
|
2387 |
}
|
2388 |
}
|
2389 |
} else {
|
2390 |
if (isset($item['enable']) && $active_class == '') {
|
2391 |
$a2_token = $this->set_a2_token($item['slug']);
|
2392 |
-
$links[] =
|
2393 |
}
|
2394 |
|
2395 |
if (isset($item['not_configured_links'])) {
|
2396 |
foreach ($item['not_configured_links'] as $name => $link) {
|
2397 |
if (gettype($link) == 'array') {
|
2398 |
-
$links[] =
|
2399 |
} else {
|
2400 |
-
$links[] =
|
2401 |
}
|
2402 |
}
|
2403 |
}
|
2404 |
}
|
2405 |
if (isset($item['kb'])) {
|
2406 |
-
$links[] =
|
2407 |
}
|
2408 |
$link_html = '';
|
2409 |
foreach ($links as $i => $link) {
|
@@ -2482,20 +2615,24 @@ HTML;
|
|
2482 |
$warning_html .= $this->warning_display($warning);
|
2483 |
$num_warnings++;
|
2484 |
}
|
|
|
2485 |
break;
|
2486 |
case '<':
|
2487 |
if ($value < $warning['threshold']) {
|
2488 |
$warning_html .= $this->warning_display($warning);
|
2489 |
$num_warnings++;
|
2490 |
}
|
|
|
2491 |
break;
|
2492 |
case '=':
|
2493 |
if ($value == $warning['threshold']) {
|
2494 |
$warning_html .= $this->warning_display($warning);
|
2495 |
$num_warnings++;
|
2496 |
}
|
|
|
2497 |
break;
|
2498 |
}
|
|
|
2499 |
break;
|
2500 |
case 'text':
|
2501 |
switch ($warning['threshold_type']) {
|
@@ -2504,14 +2641,17 @@ HTML;
|
|
2504 |
$warning_html .= $this->warning_display($warning);
|
2505 |
$num_warnings++;
|
2506 |
}
|
|
|
2507 |
break;
|
2508 |
case '!=':
|
2509 |
if ($value != $warning['threshold']) {
|
2510 |
$warning_html .= $this->warning_display($warning);
|
2511 |
$num_warnings++;
|
2512 |
}
|
|
|
2513 |
break;
|
2514 |
}
|
|
|
2515 |
break;
|
2516 |
case 'array_count':
|
2517 |
switch ($warning['threshold_type']) {
|
@@ -2520,11 +2660,14 @@ HTML;
|
|
2520 |
$warning_html .= $this->warning_display($warning);
|
2521 |
$num_warnings++;
|
2522 |
}
|
|
|
2523 |
break;
|
2524 |
}
|
|
|
2525 |
break;
|
2526 |
}
|
2527 |
}
|
|
|
2528 |
break;
|
2529 |
case 'Advanced Warnings':
|
2530 |
foreach ($warning_set as $name => $warning) {
|
@@ -2533,6 +2676,7 @@ HTML;
|
|
2533 |
$num_warnings++;
|
2534 |
}
|
2535 |
}
|
|
|
2536 |
break;
|
2537 |
case 'Bad Plugins':
|
2538 |
foreach ($warning_set as $plugin_folder => $warning) {
|
@@ -2551,7 +2695,7 @@ HTML;
|
|
2551 |
}
|
2552 |
}
|
2553 |
|
2554 |
-
return
|
2555 |
}
|
2556 |
|
2557 |
/**
|
@@ -2728,7 +2872,7 @@ define('DISALLOW_FILE_MODS', true);
|
|
2728 |
|
2729 |
PHP;
|
2730 |
}
|
2731 |
-
|
2732 |
if ($obj_server) {
|
2733 |
$a2_config .= <<<PHP
|
2734 |
|
@@ -2736,7 +2880,7 @@ define('MEMCACHED_SERVERS', array('default' => array('{$obj_server}')));
|
|
2736 |
|
2737 |
PHP;
|
2738 |
}
|
2739 |
-
|
2740 |
$a2_config .= <<<PHP
|
2741 |
// END A2 CONFIG
|
2742 |
PHP;
|
@@ -2775,7 +2919,7 @@ PHP;
|
|
2775 |
public function get_nomods() {
|
2776 |
return get_option('a2_optimized_nomods');
|
2777 |
}
|
2778 |
-
|
2779 |
/**
|
2780 |
* Check if there is a memcached server set
|
2781 |
*
|
@@ -2797,7 +2941,7 @@ PHP;
|
|
2797 |
//make sure it is writable by owner and readable by everybody
|
2798 |
chmod(ABSPATH . '.htaccess', 0644);
|
2799 |
|
2800 |
-
$home_path = explode('/', str_replace(
|
2801 |
|
2802 |
if (!isset($home_path[1]) || $home_path[1] == '') {
|
2803 |
$home_path = '/';
|
@@ -2878,6 +3022,7 @@ HTACCESS;
|
|
2878 |
*/
|
2879 |
public function deleteOption($optionName) {
|
2880 |
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
|
|
|
2881 |
return delete_option($prefixedOptionName);
|
2882 |
}
|
2883 |
|
@@ -2890,6 +3035,7 @@ HTACCESS;
|
|
2890 |
*/
|
2891 |
public function updateOption($optionName, $value) {
|
2892 |
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
|
|
|
2893 |
return update_option($prefixedOptionName, $value);
|
2894 |
}
|
2895 |
|
@@ -3065,7 +3211,7 @@ HTACCESS;
|
|
3065 |
public function getPluginHeaderValue($key) {
|
3066 |
// Read the string from the comment header of the main plugin file
|
3067 |
$data = file_get_contents($this->getPluginDir() . DIRECTORY_SEPARATOR . $this->getMainPluginFileName());
|
3068 |
-
$match =
|
3069 |
preg_match('/' . $key . ':\s*(\S+)/', $data, $match);
|
3070 |
if (count($match) >= 1) {
|
3071 |
return $match[1];
|
69 |
* @return array
|
70 |
*/
|
71 |
public function get_w3tc_defaults() {
|
72 |
+
return [
|
73 |
'pgcache.check.domain' => true,
|
74 |
'pgcache.prime.post.enabled' => true,
|
75 |
'pgcache.reject.logged' => true,
|
90 |
'pgcache.cache.feed' => true,
|
91 |
'pgcache.debug' => false,
|
92 |
'pgcache.purge.postpages_limit' => 0,//purge all pages that list posts
|
93 |
+
'pgcache.purge.feed.types' => [
|
94 |
0 => 'rdf',
|
95 |
1 => 'rss',
|
96 |
2 => 'rss2',
|
97 |
3 => 'atom'
|
98 |
+
],
|
99 |
'pgcache.compatibility' => true,
|
100 |
'minify.debug' => false,
|
101 |
'dbcache.debug' => false,
|
154 |
'config.check' => true,
|
155 |
|
156 |
'varnish.enabled' => false
|
157 |
+
];
|
158 |
}
|
159 |
|
160 |
/**
|
191 |
public function install_plugin($slug, $activate = false) {
|
192 |
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
193 |
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
|
194 |
+
$api = plugins_api('plugin_information', ['slug' => $slug]);
|
195 |
$response = true;
|
196 |
|
197 |
$found = false;
|
256 |
*
|
257 |
*/
|
258 |
public function hit_the_w3tc_page() {
|
259 |
+
$disregarded_cookies = [
|
260 |
'PHPSESSID',
|
261 |
+
];
|
262 |
|
263 |
$cookie = '';
|
264 |
foreach ($_COOKIE as $name => $val) {
|
304 |
*/
|
305 |
public function enable_w3tc_cache() {
|
306 |
$permalink_structure = get_option('permalink_structure');
|
307 |
+
$vars = [];
|
308 |
if ($permalink_structure == '') {
|
309 |
$vars['pgcache.engine'] = 'file';
|
310 |
} else {
|
329 |
*/
|
330 |
public function enable_w3tc_page_cache() {
|
331 |
$permalink_structure = get_option('permalink_structure');
|
332 |
+
$vars = [];
|
333 |
if ($permalink_structure == '') {
|
334 |
$vars['pgcache.engine'] = 'file';
|
335 |
} else {
|
348 |
*
|
349 |
*/
|
350 |
public function enable_w3tc_db_cache() {
|
351 |
+
$vars = [];
|
352 |
|
353 |
$vars['dbcache.engine'] = 'file';
|
354 |
$vars['dbcache.enabled'] = true;
|
361 |
*
|
362 |
*/
|
363 |
public function enable_w3tc_object_cache() {
|
364 |
+
$vars = [];
|
365 |
|
366 |
$vars['objectcache.engine'] = 'file';
|
367 |
$vars['objectcache.enabled'] = true;
|
374 |
*
|
375 |
*/
|
376 |
public function enable_w3tc_browser_cache() {
|
377 |
+
$vars = [];
|
378 |
|
379 |
$vars['browsercache.enabled'] = true;
|
380 |
|
386 |
*
|
387 |
*/
|
388 |
public function enable_w3tc_gzip() {
|
389 |
+
$vars = [];
|
390 |
|
391 |
$vars['browsercache.other.compression'] = true;
|
392 |
$vars['browsercache.html.compression'] = true;
|
400 |
*
|
401 |
*/
|
402 |
public function disable_w3tc_gzip() {
|
403 |
+
$vars = [];
|
404 |
|
405 |
$vars['browsercache.other.compression'] = false;
|
406 |
$vars['browsercache.html.compression'] = false;
|
408 |
|
409 |
$this->update_w3tc($vars);
|
410 |
}
|
411 |
+
|
412 |
/**
|
413 |
* Enable built-in page cache
|
414 |
*
|
419 |
|
420 |
update_option('a2_cache_enabled', 1);
|
421 |
}
|
422 |
+
|
423 |
/**
|
424 |
* Disable built-in page cache
|
425 |
*
|
427 |
public function disable_a2_page_cache() {
|
428 |
A2_Optimized_Cache_Disk::clean();
|
429 |
A2_Optimized_Cache::update_backend();
|
430 |
+
|
431 |
update_option('a2_cache_enabled', 0);
|
432 |
}
|
433 |
+
|
434 |
/**
|
435 |
* Enable memcached object cache
|
436 |
*
|
437 |
*/
|
438 |
public function enable_a2_object_cache() {
|
439 |
+
if (get_option('a2_optimized_memcached_invalid')) {
|
440 |
+
// Object cache server did not validate. exit.
|
441 |
return false;
|
442 |
}
|
443 |
+
if (is_plugin_active('litespeed-cache/litespeed-cache.php')) {
|
444 |
+
// Litespeed cache plugin is active, use that
|
445 |
+
return $this->enable_lscache_object_cache();
|
446 |
+
} else {
|
447 |
+
// Try to enable A2 memcached object caching
|
448 |
+
if (get_option('a2_optimized_memcached_server') == false) {
|
449 |
+
// Second check for object cache server
|
450 |
+
return false;
|
451 |
+
}
|
452 |
+
copy( A2OPT_DIR . '/object-cache.php', WP_CONTENT_DIR . '/object-cache.php' );
|
453 |
|
454 |
+
update_option('a2_object_cache_enabled', 1);
|
455 |
+
$this->write_wp_config();
|
456 |
+
}
|
457 |
+
}
|
458 |
|
459 |
+
/**
|
460 |
+
* Enable litespeed object cache
|
461 |
+
*
|
462 |
+
*/
|
463 |
+
public function enable_lscache_object_cache() {
|
464 |
+
$object_cache_type = 'memcached';
|
465 |
+
|
466 |
+
if (get_option('a2_optimized_objectcache_type')) {
|
467 |
+
$object_cache_type = get_option('a2_optimized_objectcache_type');
|
468 |
+
}
|
469 |
+
|
470 |
+
/* Set type of object cache */
|
471 |
+
if ($object_cache_type == 'memcached') {
|
472 |
+
$server_host = get_option('a2_optimized_memcached_server');
|
473 |
+
update_option('litespeed.conf.object-kind', 0);
|
474 |
+
}
|
475 |
+
if ($object_cache_type == 'redis') {
|
476 |
+
$server_host = get_option('a2_optimized_redis_server');
|
477 |
+
update_option('litespeed.conf.object-kind', 1);
|
478 |
+
}
|
479 |
+
|
480 |
+
update_option('litespeed.conf.object', 1); // Enable object cache
|
481 |
+
update_option('litespeed.conf.object-host', $server_host); // Server host
|
482 |
+
update_option('litespeed.conf.object-port', '0'); // Port is 0 for socket connections
|
483 |
+
|
484 |
+
update_option('a2_object_cache_enabled', 1); // Flag that we have this enabled
|
485 |
+
}
|
486 |
+
|
487 |
+
/* Is redis supported */
|
488 |
+
private function is_redis_supported() {
|
489 |
+
if (class_exists('A2_Optimized_Private_Optimizations') && is_plugin_active('litespeed-cache/litespeed-cache.php')) {
|
490 |
+
$a2opt_priv = new A2_Optimized_Private_Optimizations();
|
491 |
+
|
492 |
+
return $a2opt_priv->is_redis_supported();
|
493 |
+
}
|
494 |
+
update_option('a2_optimized_objectcache_type', 'memcached');
|
495 |
+
|
496 |
+
return false;
|
497 |
}
|
498 |
+
|
499 |
/**
|
500 |
* Disable memcached object cache
|
501 |
*
|
502 |
*/
|
503 |
public function disable_a2_object_cache() {
|
504 |
@unlink( WP_CONTENT_DIR . '/object-cache.php' );
|
505 |
+
|
506 |
$this->write_wp_config();
|
507 |
|
508 |
update_option('a2_object_cache_enabled', 0);
|
509 |
}
|
510 |
+
|
511 |
/**
|
512 |
* Enable built-in page cache gzip
|
513 |
*
|
523 |
// Rebuild cache settings file
|
524 |
A2_Optimized_Cache_Disk::create_settings_file( $cache_settings );
|
525 |
}
|
526 |
+
|
527 |
/**
|
528 |
* Disable built-in page cache gzip
|
529 |
*
|
554 |
// Rebuild cache settings file
|
555 |
A2_Optimized_Cache_Disk::create_settings_file( $cache_settings );
|
556 |
}
|
557 |
+
|
558 |
/**
|
559 |
* Disable built-in page cache html minification
|
560 |
*
|
587 |
// Rebuild cache settings file
|
588 |
A2_Optimized_Cache_Disk::create_settings_file( $cache_settings );
|
589 |
}
|
590 |
+
|
591 |
/**
|
592 |
* Disable built-in page cache css/js minification
|
593 |
*
|
602 |
// Rebuild cache settings file
|
603 |
A2_Optimized_Cache_Disk::create_settings_file( $cache_settings );
|
604 |
}
|
605 |
+
|
606 |
/**
|
607 |
* Enable WooCommerce Cart Fragment Dequeuing
|
608 |
*
|
611 |
update_option('a2_wc_cart_fragments', 1);
|
612 |
update_option('woocommerce_cart_redirect_after_add', 'yes'); // Recommended WooCommerce setting when disabling cart fragments
|
613 |
}
|
614 |
+
|
615 |
/**
|
616 |
* Disable WooCommerce Cart Fragment Dequeuing
|
617 |
*
|
620 |
delete_option('a2_wc_cart_fragments');
|
621 |
delete_option('woocommerce_cart_redirect_after_add');
|
622 |
}
|
623 |
+
|
624 |
/**
|
625 |
* Enable Blocking of XML-RPC Requests
|
626 |
*
|
628 |
public function enable_xmlrpc_requests() {
|
629 |
update_option('a2_block_xmlrpc', 1);
|
630 |
}
|
631 |
+
|
632 |
/**
|
633 |
* Disable Blocking of XML-RPC Requests
|
634 |
*
|
642 |
*
|
643 |
*/
|
644 |
public function regenerate_wpconfig_salts() {
|
645 |
+
$this->salts_array = [
|
646 |
"define('AUTH_KEY',",
|
647 |
'SECURE_AUTH_KEY',
|
648 |
'LOGGED_IN_KEY',
|
651 |
'SECURE_AUTH_SALT',
|
652 |
'LOGGED_IN_SALT',
|
653 |
'NONCE_SALT',
|
654 |
+
];
|
655 |
|
656 |
$returned_salts = file_get_contents('https://api.wordpress.org/secret-key/1.1/salt/');
|
657 |
$this->new_salts = explode("\n", $returned_salts);
|
663 |
|
664 |
public function regenerate_wpconfig_desc() {
|
665 |
$output = '<p>Generate new salt values for wp-config.php<br /><strong>This will log out all users including yourself</strong><br />Last regenerated:</p>';
|
666 |
+
|
667 |
return $output;
|
668 |
}
|
669 |
|
696 |
}
|
697 |
}
|
698 |
}
|
699 |
+
|
700 |
private function config_file_path() {
|
701 |
$salts_file_name = 'wp-config';
|
702 |
$config_file = ABSPATH . $salts_file_name . '.php';
|
736 |
*
|
737 |
*/
|
738 |
public function disable_w3tc_cache() {
|
739 |
+
$this->update_w3tc([
|
740 |
'pgcache.enabled' => false,
|
741 |
'dbcache.enabled' => false,
|
742 |
'objectcache.enabled' => false,
|
743 |
'browsercache.enabled' => false,
|
744 |
+
]);
|
745 |
}
|
746 |
|
747 |
/**
|
749 |
*
|
750 |
*/
|
751 |
public function disable_w3tc_page_cache() {
|
752 |
+
$vars = [];
|
753 |
$vars['pgcache.enabled'] = false;
|
754 |
$this->update_w3tc($vars);
|
755 |
}
|
759 |
*
|
760 |
*/
|
761 |
public function disable_w3tc_db_cache() {
|
762 |
+
$vars = [];
|
763 |
$vars['dbcache.enabled'] = false;
|
764 |
$this->update_w3tc($vars);
|
765 |
}
|
769 |
*
|
770 |
*/
|
771 |
public function disable_w3tc_object_cache() {
|
772 |
+
$vars = [];
|
773 |
$vars['objectcache.enabled'] = false;
|
774 |
$this->update_w3tc($vars);
|
775 |
}
|
779 |
*
|
780 |
*/
|
781 |
public function disable_w3tc_browser_cache() {
|
782 |
+
$vars = [];
|
783 |
$vars['browsercache.enabled'] = false;
|
784 |
$this->update_w3tc($vars);
|
785 |
}
|
789 |
*
|
790 |
*/
|
791 |
public function disable_html_minify() {
|
792 |
+
$this->update_w3tc([
|
793 |
'minify.html.enable' => false,
|
794 |
'minify.html.enabled' => false,
|
795 |
'minify.auto' => false
|
796 |
+
]);
|
797 |
}
|
798 |
|
799 |
/**
|
801 |
*
|
802 |
*/
|
803 |
public function enable_html_minify() {
|
804 |
+
$this->update_w3tc([
|
805 |
'minify.html.enable' => true,
|
806 |
'minify.enabled' => true,
|
807 |
'minify.auto' => false,
|
808 |
'minify.engine' => 'file'
|
809 |
+
]);
|
810 |
}
|
811 |
|
812 |
public function curl_save_w3tc($cookie, $url) {
|
845 |
|
846 |
wp_enqueue_style('bootstrap', plugins_url('/assets/bootstrap/css/bootstrap.css', __FILE__), '', $thisclass->getVersion());
|
847 |
wp_enqueue_style('bootstrap-theme', plugins_url('/assets/bootstrap/css/bootstrap-theme.css', __FILE__), '', $thisclass->getVersion());
|
848 |
+
wp_enqueue_script('bootstrap-theme', plugins_url('/assets/bootstrap/js/bootstrap.js', __FILE__), ['jquery'], $thisclass->getVersion());
|
849 |
|
850 |
$image_dir = plugins_url('/assets/images', __FILE__);
|
851 |
|
899 |
}
|
900 |
|
901 |
if ($_GET['a2-page'] == 'dismiss_notice') {
|
902 |
+
$allowed_notices = [
|
903 |
'a2_login_bookmark',
|
904 |
'a2_notice_incompatible_plugins',
|
905 |
'a2_notice_w3totalcache',
|
908 |
'a2_notice_wordfence_waf',
|
909 |
'a2_notice_configpage',
|
910 |
'a2_notice_diviminify',
|
911 |
+
];
|
912 |
if (isset($_GET['a2-option']) && in_array($_GET['a2-option'], $allowed_notices)) {
|
913 |
if ($_GET['a2-option'] == 'a2_login_bookmark') {
|
914 |
update_option('a2_login_bookmark', get_option('a2_login_page'));
|
1055 |
if (isset($_GET['save_settings']) && $_GET['save_settings']) {
|
1056 |
$save_alert = '<div class="alert alert-success">Settings Saved</div>';
|
1057 |
}
|
1058 |
+
|
1059 |
if (isset($_GET['msg']) && $_GET['msg'] == 'token') {
|
1060 |
$save_alert = '<div class="alert alert-danger">Session timed out, please try to configure your optimization again.</div>';
|
1061 |
}
|
1070 |
$settingsGroup = get_class($this) . '-settings-group';
|
1071 |
$description = $this->get_plugin_description();
|
1072 |
|
|
|
|
|
1073 |
if ($this->is_a2()) {
|
1074 |
$feedback = <<<HTML
|
1075 |
<div style="margin:10px 0;" class="alert alert-success">
|
1302 |
|
1303 |
HTML;
|
1304 |
}
|
1305 |
+
|
1306 |
/**
|
1307 |
* Wizard to migrate from the W3TC plugin
|
1308 |
* @param integer $setup_step The step to begin install process
|
1312 |
$image_dir = plugins_url('/assets/images', __FILE__);
|
1313 |
$kb_search_box = $this->kb_searchbox_html();
|
1314 |
$w3tc_settings = $this->get_w3tc_config();
|
1315 |
+
$migrated_settings = [];
|
1316 |
+
$migrated_settings['page_cache'] = [
|
1317 |
'name' => 'Enable Page Caching',
|
1318 |
'w3tc_value' => $w3tc_settings['pgcache.enabled']
|
1319 |
+
];
|
1320 |
+
$migrated_settings['excluded_cookies'] = [
|
1321 |
'name' => 'Do not cache requests that have these cookies',
|
1322 |
'w3tc_value' => $w3tc_settings['pgcache.reject.cookie']
|
1323 |
+
];
|
1324 |
+
$migrated_settings['object_cache'] = [
|
1325 |
'name' => 'Enable Memcached Object Caching',
|
1326 |
'w3tc_value' => $w3tc_settings['objectcache.enabled']
|
1327 |
+
];
|
1328 |
+
$migrated_settings['memcached_server'] = [
|
1329 |
'name' => 'Memcached Servers',
|
1330 |
'w3tc_value' => $w3tc_settings['objectcache.memcached.servers']
|
1331 |
+
];
|
1332 |
+
$migrated_settings['clear_site_cache_on_saved_post'] = [
|
1333 |
'name' => 'Clear cache when saving post',
|
1334 |
'w3tc_value' => $w3tc_settings['pgcache.purge.post']
|
1335 |
+
];
|
1336 |
+
$migrated_settings['clear_site_cache_on_saved_comment'] = [
|
1337 |
'name' => 'Clear cache when a new comment is added',
|
1338 |
'w3tc_value' => $w3tc_settings['pgcache.purge.comments']
|
1339 |
+
];
|
1340 |
+
$migrated_settings['compress_cache'] = [
|
1341 |
'name' => 'GZIP compress cached pages',
|
1342 |
'w3tc_value' => $w3tc_settings['browsercache.html.compression']
|
1343 |
+
];
|
1344 |
+
$migrated_settings['minify_html'] = [
|
1345 |
'name' => 'HTML Minification',
|
1346 |
'w3tc_value' => $w3tc_settings['minify.html.enable']
|
1347 |
+
];
|
1348 |
+
$migrated_settings['minify_inline_css_js'] = [
|
1349 |
'name' => 'Javascript and CSS Minification',
|
1350 |
'w3tc_value' => $w3tc_settings['minify.js.enable']
|
1351 |
+
];
|
1352 |
|
1353 |
if ($setup_step == 1) {
|
1354 |
echo <<<HTML
|
1398 |
$value = 'Not set';
|
1399 |
}
|
1400 |
}
|
1401 |
+
|
1402 |
$step_output .= '<li><strong>' . $item['name'] . '</strong>: ' . $value . '</li>';
|
1403 |
}
|
1404 |
+
|
1405 |
$step_output .= "</ul><p>Next we will need to deactivate the W3 Total Cache plugin.</p><p><a href='" . admin_url('admin.php?a2-page=w3tc_migration_wizard&page=A2_Optimized_Plugin_admin&step=2') . "' class='btn btn-success'>Deactivate</a></p>";
|
1406 |
echo <<<HTML
|
1407 |
<div>
|
1721 |
update_option('a2_recaptcha_secretkey', sanitize_text_field($_POST['a2_recaptcha_secretkey']));
|
1722 |
update_option('a2_recaptcha_theme', sanitize_text_field($_POST['a2_recaptcha_theme']));
|
1723 |
}
|
1724 |
+
|
1725 |
/**
|
1726 |
* Cache Settings Page
|
1727 |
*
|
1729 |
private function cache_settings_html() {
|
1730 |
$image_dir = plugins_url('/assets/images', __FILE__);
|
1731 |
$kb_search_box = $this->kb_searchbox_html();
|
1732 |
+
$admin_url = 'options.php';
|
1733 |
+
$db_optimization_settings = get_option(A2_Optimized_DBOptimizations::WP_SETTING); ?>
|
1734 |
<section id="a2opt-content-general">
|
1735 |
<div class="wrap">
|
1736 |
<div>
|
1753 |
<?php if (get_option('a2_optimized_memcached_invalid')) { ?>
|
1754 |
<div class="notice notice-error"><p>There is an issue with your Memcached settings<br /><?php echo get_option('a2_optimized_memcached_invalid'); ?></p></div>
|
1755 |
<?php } ?>
|
1756 |
+
<h3>Advanced A2 Optimized Settings</h3>
|
1757 |
<div>
|
1758 |
<form method="post" action="<?php echo $admin_url; ?>">
|
1759 |
<?php settings_fields( 'a2opt-cache' ); ?>
|
1816 |
</label>
|
1817 |
<label for="minify_inline_css_js">
|
1818 |
<?php
|
1819 |
+
$minify_inline_css_js_options = [
|
1820 |
esc_html__( 'excluding', 'a2-optimized-wp' ) => 0,
|
1821 |
esc_html__( 'including', 'a2-optimized-wp' ) => 1,
|
1822 |
+
];
|
1823 |
$minify_inline_css_js = '<select name="a2opt-cache[minify_inline_css_js]" id="minify_inline_css_js">';
|
1824 |
foreach ( $minify_inline_css_js_options as $key => $value ) {
|
1825 |
$minify_inline_css_js .= '<option value="' . esc_attr( $value ) . '"' . selected( $value, A2_Optimized_Cache_Engine::$settings['minify_inline_css_js'], false ) . '>' . $key . '</option>';
|
1889 |
</th>
|
1890 |
<td>
|
1891 |
<fieldset>
|
1892 |
+
<?php if ($this->is_redis_supported()) { ?>
|
1893 |
+
<p class="subheading"><?php esc_html_e( 'Object Cache Type', 'a2-optimized-wp' ); ?></p>
|
1894 |
+
<label for="object_cache_server">
|
1895 |
+
<?php
|
1896 |
+
$object_cache_options = [
|
1897 |
+
esc_html__( 'Memcached', 'a2-optimized-wp' ) => 'memcached',
|
1898 |
+
esc_html__( 'Redis', 'a2-optimized-wp' ) => 'redis',
|
1899 |
+
];?>
|
1900 |
+
<select name="a2_optimized_objectcache_type" id="objet_cache_server">
|
1901 |
+
<option value="memcached" <?php if (get_option('a2_optimized_objectcache_type') == 'memcached') {
|
1902 |
+
echo 'selected';
|
1903 |
+
} ?>>Memcached</option>
|
1904 |
+
<option value="redis" <?php if (get_option('a2_optimized_objectcache_type') == 'redis') {
|
1905 |
+
echo 'selected';
|
1906 |
+
} ?>>Redis</option>
|
1907 |
+
</select>
|
1908 |
+
<p class="description">
|
1909 |
+
<?php
|
1910 |
+
// translators: %s: ,
|
1911 |
+
printf( esc_html__( 'Redis or Memcached', 'a2-optimized-wp' ), '<code class="code--form-control">,</code>' ); ?>
|
1912 |
+
</p>
|
1913 |
+
</label>
|
1914 |
+
|
1915 |
+
<p class="subheading"><?php esc_html_e( 'Redis Server', 'a2-optimized-wp' ); ?></p>
|
1916 |
+
<label for="redis_server">
|
1917 |
+
<input name="a2_optimized_redis_server" type="text" id="redis_server" value="<?php echo esc_attr( get_option('a2_optimized_redis_server') ) ?>" class="regular-text" />
|
1918 |
+
<p class="description">
|
1919 |
+
<?php
|
1920 |
+
// translators: %s: ,
|
1921 |
+
printf( esc_html__( 'Address and port of the redis server for object caching', 'a2-optimized-wp' ), '<code class="code--form-control">,</code>' ); ?>
|
1922 |
+
</p>
|
1923 |
+
</label>
|
1924 |
+
<?php } ?>
|
1925 |
<p class="subheading"><?php esc_html_e( 'Memcached Server', 'a2-optimized-wp' ); ?></p>
|
1926 |
<label for="memcached_server">
|
1927 |
<input name="a2_optimized_memcached_server" type="text" id="memcached_server" value="<?php echo esc_attr( get_option('a2_optimized_memcached_server') ) ?>" class="regular-text" />
|
1934 |
</fieldset>
|
1935 |
</td>
|
1936 |
</tr>
|
1937 |
+
|
1938 |
+
<tr valign="top">
|
1939 |
+
<th scope="row">
|
1940 |
+
<?php esc_html_e( 'Database Optimizations', 'a2-optimized-wp'); ?>
|
1941 |
+
</th>
|
1942 |
+
<td>
|
1943 |
+
<fieldset>
|
1944 |
+
<label for="remove_revision_posts">
|
1945 |
+
<input name="a2_db_optimizations[remove_revision_posts]" type="checkbox" id="remove_revision_posts" value="1" <?php checked( '1', $db_optimization_settings[A2_Optimized_DBOptimizations::REMOVE_REVISION_POSTS] ); ?> />
|
1946 |
+
<?php esc_html_e( 'Delete all history of post revisions', 'a2-optimized-wp' ); ?>
|
1947 |
+
</label>
|
1948 |
+
|
1949 |
+
<br />
|
1950 |
+
|
1951 |
+
<label for="remove_trashed_posts">
|
1952 |
+
<input name="a2_db_optimizations[remove_trashed_posts]" type="checkbox" id="remove_trashed_posts" value="1" <?php checked( '1', $db_optimization_settings[A2_Optimized_DBOptimizations::REMOVE_TRASHED_POSTS] ); ?> />
|
1953 |
+
<?php esc_html_e( 'Permanently delete all posts in trash', 'a2-optimized-wp' ); ?>
|
1954 |
+
</label>
|
1955 |
+
|
1956 |
+
<br />
|
1957 |
+
|
1958 |
+
<label for="remove_spam_comments">
|
1959 |
+
<input name="a2_db_optimizations[remove_spam_comments]" type="checkbox" id="remove_spam_comments" value="1" <?php checked( '1', $db_optimization_settings[A2_Optimized_DBOptimizations::REMOVE_SPAM_COMMENTS] ); ?> />
|
1960 |
+
<?php esc_html_e( 'Delete all comments marked as spam', 'a2-optimized-wp' ); ?>
|
1961 |
+
</label>
|
1962 |
+
|
1963 |
+
<br />
|
1964 |
+
|
1965 |
+
<label for="remove_trashed_comments">
|
1966 |
+
<input name="a2_db_optimizations[remove_trashed_comments]" type="checkbox" id="remove_trashed_comments" value="1" <?php checked( '1', $db_optimization_settings[A2_Optimized_DBOptimizations::REMOVE_TRASHED_COMMENTS] ); ?> />
|
1967 |
+
<?php esc_html_e( 'Permanently delete all comments in trash', 'a2-optimized-wp' ); ?>
|
1968 |
+
</label>
|
1969 |
+
|
1970 |
+
<br />
|
1971 |
+
|
1972 |
+
<label for="remove_expired_transients">
|
1973 |
+
<input name="a2_db_optimizations[remove_expired_transients]" type="checkbox" id="remove_expired_transients" value="1" <?php checked( '1', $db_optimization_settings[A2_Optimized_DBOptimizations::REMOVE_EXPIRED_TRANSIENTS] ); ?> />
|
1974 |
+
<?php esc_html_e( 'Delete temporary data that has expired', 'a2-optimized-wp' ); ?>
|
1975 |
+
</label>
|
1976 |
+
|
1977 |
+
<br />
|
1978 |
+
|
1979 |
+
<label for="optimize_tables">
|
1980 |
+
<input name="a2_db_optimizations[optimize_tables]" type="checkbox" id="optimize_tables" value="1" <?php checked( '1', $db_optimization_settings[A2_Optimized_DBOptimizations::OPTIMIZE_TABLES] ); ?> />
|
1981 |
+
<?php esc_html_e( 'Perform optimizations on all database tables', 'a2-optimized-wp' ); ?>
|
1982 |
+
</label>
|
1983 |
+
|
1984 |
+
</fieldset>
|
1985 |
+
</td>
|
1986 |
+
</tr>
|
1987 |
+
|
1988 |
</table>
|
1989 |
|
1990 |
<p class="submit">
|
1991 |
<?php wp_nonce_field( 'a2opt-cache-save', 'a2opt-cache-nonce' ); ?>
|
1992 |
<input type="submit" class="button-secondary" value="<?php esc_html_e( 'Save Changes', 'a2-optimized-wp' ); ?>" />
|
1993 |
<input name="a2opt-cache[clear_site_cache_on_saved_settings]" type="submit" class="button-primary" value="<?php esc_html_e( 'Save Changes and Clear Site Cache', 'a2-optimized-wp' ); ?>" />
|
1994 |
+
<input name="a2opt-cache[apply_db_optimizations_on_saved_settings]" type="submit" class="button-primary" value="<?php esc_html_e( 'Save Changes and Apply Database Optimizations', 'a2-optimized-wp' ); ?>" />
|
1995 |
</p>
|
1996 |
</form>
|
1997 |
</div>
|
2014 |
}
|
2015 |
|
2016 |
if (check_admin_referer('a2opt-cache-save', 'a2opt-cache-nonce')) {
|
2017 |
+
$a2opt_db_optimizations = sanitize_text_field($_REQUEST['a2_db_optimizations']);
|
2018 |
$a2opt_cache = sanitize_text_field($_REQUEST['a2opt-cache']);
|
2019 |
$a2_memcached_server = sanitize_text_field($_REQUEST['a2_optimized_memcached_server']);
|
2020 |
update_option('a2opt-cache', $a2opt_cache);
|
2022 |
$this->write_wp_config();
|
2023 |
}
|
2024 |
}
|
2025 |
+
|
2026 |
/**
|
2027 |
* Site Health View Page
|
2028 |
*
|
2034 |
}
|
2035 |
|
2036 |
$saved_health_items = get_option('a2opt-sitehealth-results');
|
2037 |
+
|
2038 |
$current_site_health = null;
|
2039 |
|
2040 |
if (isset($_REQUEST['view_report'])) {
|
2041 |
+
foreach ($saved_health_items as $date => $item) {
|
2042 |
+
if (md5($date) == $_REQUEST['view_report']) {
|
2043 |
$current_site_health = $item;
|
2044 |
$site_health_date = $date;
|
2045 |
+
}
|
2046 |
+
}
|
2047 |
}
|
2048 |
+
if (!$current_site_health) {
|
2049 |
$WP_Debug_Data = new WP_Debug_Data();
|
2050 |
new A2_Optimized_SiteHealth;
|
2051 |
$info = $WP_Debug_Data::debug_data();
|
2052 |
$current_site_health = $WP_Debug_Data::format( $info, 'debug' );
|
2053 |
$site_health_date = date('Y-m-d H:i:s');
|
2054 |
+
} ?>
|
|
|
|
|
2055 |
<section id="a2opt-content-general">
|
2056 |
<div class="wrap">
|
2057 |
<div>
|
2080 |
<?php } else { ?>
|
2081 |
<h3>Site Health Results</h3>
|
2082 |
<p><a href="admin.php?a2-page=site_health_save&page=A2_Optimized_Plugin_admin" class="button">Save current results</a> <a href="site-health.php?tab=debug" class="button">Back to Site Health</a></p>
|
2083 |
+
<?php } ?>
|
2084 |
+
<?php if (count($saved_health_items) > 0) { ?>
|
2085 |
<p>
|
2086 |
<strong>Saved reports</strong>
|
2087 |
<ul>
|
2088 |
+
<?php foreach ($saved_health_items as $date => $item) { ?>
|
2089 |
<li><a href="admin.php?a2-page=site_health&page=A2_Optimized_Plugin_admin&view_report=<?php echo md5($date); ?>"><?php echo $date; ?></a></li>
|
2090 |
+
<?php } ?>
|
2091 |
</ul>
|
2092 |
</p>
|
2093 |
+
<?php } ?>
|
2094 |
<div>
|
2095 |
<pre>
|
2096 |
<?php echo $current_site_health; ?>
|
2113 |
if (!current_user_can('manage_options')) {
|
2114 |
die('Cheating eh?');
|
2115 |
}
|
2116 |
+
|
2117 |
if ( ! class_exists( 'WP_Debug_Data' ) ) {
|
2118 |
require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php';
|
2119 |
}
|
2120 |
|
2121 |
$existing_health = get_option('a2opt-sitehealth-results');
|
2122 |
|
2123 |
+
if (!$existing_health) {
|
2124 |
$existing_health = [];
|
2125 |
}
|
2126 |
|
2130 |
$current_site_health = $WP_Debug_Data::format( $info, 'debug' );
|
2131 |
|
2132 |
$existing_health[date('Y-m-d H:i:s')] = $current_site_health;
|
2133 |
+
|
2134 |
update_option('a2opt-sitehealth-results', $existing_health);
|
2135 |
}
|
2136 |
+
|
2137 |
/**
|
2138 |
* Remove Site Health Results
|
2139 |
*
|
2142 |
if (!current_user_can('manage_options')) {
|
2143 |
die('Cheating eh?');
|
2144 |
}
|
2145 |
+
|
2146 |
$existing_health = get_option('a2opt-sitehealth-results');
|
2147 |
|
2148 |
+
if (is_array($existing_health)) {
|
2149 |
$index_to_remove = 0;
|
2150 |
+
foreach ($existing_health as $date => $item) {
|
2151 |
+
if (md5($date) == $_REQUEST['remove_report']) {
|
2152 |
$index_to_remove = $date;
|
2153 |
}
|
2154 |
}
|
2155 |
+
if ($index_to_remove !== 0) {
|
2156 |
unset($existing_health[$index_to_remove]);
|
2157 |
update_option('a2opt-sitehealth-results', $existing_health);
|
2158 |
}
|
2159 |
}
|
|
|
2160 |
}
|
2161 |
|
2162 |
/**
|
2186 |
private function get_a2_token($slug) {
|
2187 |
return get_transient('a2_token-' . $slug);
|
2188 |
}
|
2189 |
+
|
2190 |
/**
|
2191 |
* Set a2 token in transients
|
2192 |
*/
|
2217 |
|
2218 |
if (isset($_GET['disable_optimization']) && $url_token) {
|
2219 |
$hash = '';
|
2220 |
+
|
2221 |
$optimization = sanitize_text_field($_GET['disable_optimization']);
|
2222 |
|
2223 |
$a2_token = $this->get_a2_token($optimization);
|
2244 |
|
2245 |
if (isset($_GET['enable_optimization']) && $url_token) {
|
2246 |
$hash = '';
|
2247 |
+
|
2248 |
$optimization = sanitize_text_field($_GET['enable_optimization']);
|
2249 |
|
2250 |
$a2_token = $this->get_a2_token($optimization);
|
2268 |
JAVASCRIPT;
|
2269 |
exit();
|
2270 |
}
|
2271 |
+
|
2272 |
if (isset($_GET['apply_divi_settings']) && $url_token) {
|
2273 |
$this->optimizations['minify']['disable']('minify');
|
2274 |
$this->optimizations['css_minify']['disable']('css_minify');
|
2310 |
*/
|
2311 |
public function addOption($optionName, $value) {
|
2312 |
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
|
2313 |
+
|
2314 |
return add_option($prefixedOptionName, $value);
|
2315 |
}
|
2316 |
|
2359 |
$this->deactivate_plugin($file);
|
2360 |
uninstall_plugin($file);
|
2361 |
if ($delete) {
|
2362 |
+
delete_plugins([$file]);
|
2363 |
}
|
2364 |
unset($this->plugin_list[$file]);
|
2365 |
$this->clear_w3_total_cache();
|
2395 |
* 'Rating:', 'Excellent', 'Good', 'Fair', 'Poor')
|
2396 |
*/
|
2397 |
public function getOptionMetaData() {
|
2398 |
+
return [];
|
2399 |
}
|
2400 |
|
2401 |
private function curl($url) {
|
2430 |
$active_color = 'danger';
|
2431 |
$active_text = 'Not Activated';
|
2432 |
$glyph = 'exclamation-sign';
|
2433 |
+
$links = [];
|
2434 |
|
2435 |
$active_class = '';
|
2436 |
if (
|
2456 |
// used for Gzip options
|
2457 |
} else {
|
2458 |
$a2_token = $this->set_a2_token($item['slug']);
|
2459 |
+
$links[] = ["?page=$settings_slug&disable_optimization={$item['slug']}&a2_token={$a2_token}", 'Disable', '_self'];
|
2460 |
}
|
2461 |
}
|
2462 |
if (isset($item['settings'])) {
|
2463 |
+
$links[] = ["{$item['settings']}", 'Configure', '_self'];
|
2464 |
}
|
2465 |
|
2466 |
if (isset($item['configured_links'])) {
|
2467 |
foreach ($item['configured_links'] as $name => $link) {
|
2468 |
if (gettype($link) == 'array') {
|
2469 |
+
$links[] = [$link[0], $name, $link[1]];
|
2470 |
} else {
|
2471 |
+
$links[] = [$link, $name, '_self'];
|
2472 |
}
|
2473 |
}
|
2474 |
}
|
2482 |
|
2483 |
if (isset($item['disable'])) {
|
2484 |
$a2_token = $this->set_a2_token($item['slug']);
|
2485 |
+
$links[] = ["?page=$settings_slug&disable_optimization={$item['slug']}&a2_token={$a2_token}", 'Disable', '_self'];
|
2486 |
}
|
2487 |
if (isset($item['settings'])) {
|
2488 |
+
$links[] = ["{$item['settings']}", 'Configure', '_self'];
|
2489 |
}
|
2490 |
|
2491 |
if (isset($item['partially_configured_links'])) {
|
2492 |
foreach ($item['partially_configured_links'] as $name => $link) {
|
2493 |
if (gettype($link) == 'array') {
|
2494 |
+
$links[] = [$link[0], $name, $link[1]];
|
2495 |
} else {
|
2496 |
+
$links[] = [$link, $name, '_self'];
|
2497 |
}
|
2498 |
}
|
2499 |
}
|
2507 |
$action_text = 'Update Now';
|
2508 |
}
|
2509 |
$a2_token = $this->set_a2_token($item['slug']);
|
2510 |
+
$links[] = ["?page=$settings_slug&enable_optimization={$item['slug']}&a2_token={$a2_token}", $action_text, '_self'];
|
2511 |
}
|
2512 |
|
2513 |
if (isset($item['not_configured_links'])) {
|
2514 |
foreach ($item['not_configured_links'] as $name => $link) {
|
2515 |
if (gettype($link) == 'array') {
|
2516 |
+
$links[] = [$link[0], $name, $link[1]];
|
2517 |
} else {
|
2518 |
+
$links[] = [$link, $name, '_self'];
|
2519 |
}
|
2520 |
}
|
2521 |
}
|
2522 |
} else {
|
2523 |
if (isset($item['enable']) && $active_class == '') {
|
2524 |
$a2_token = $this->set_a2_token($item['slug']);
|
2525 |
+
$links[] = ["?page=$settings_slug&enable_optimization={$item['slug']}&a2_token={$a2_token}", 'Enable', '_self'];
|
2526 |
}
|
2527 |
|
2528 |
if (isset($item['not_configured_links'])) {
|
2529 |
foreach ($item['not_configured_links'] as $name => $link) {
|
2530 |
if (gettype($link) == 'array') {
|
2531 |
+
$links[] = [$link[0], $name, $link[1]];
|
2532 |
} else {
|
2533 |
+
$links[] = [$link, $name, '_self'];
|
2534 |
}
|
2535 |
}
|
2536 |
}
|
2537 |
}
|
2538 |
if (isset($item['kb'])) {
|
2539 |
+
$links[] = [$item['kb'], 'Learn More', '_blank'];
|
2540 |
}
|
2541 |
$link_html = '';
|
2542 |
foreach ($links as $i => $link) {
|
2615 |
$warning_html .= $this->warning_display($warning);
|
2616 |
$num_warnings++;
|
2617 |
}
|
2618 |
+
|
2619 |
break;
|
2620 |
case '<':
|
2621 |
if ($value < $warning['threshold']) {
|
2622 |
$warning_html .= $this->warning_display($warning);
|
2623 |
$num_warnings++;
|
2624 |
}
|
2625 |
+
|
2626 |
break;
|
2627 |
case '=':
|
2628 |
if ($value == $warning['threshold']) {
|
2629 |
$warning_html .= $this->warning_display($warning);
|
2630 |
$num_warnings++;
|
2631 |
}
|
2632 |
+
|
2633 |
break;
|
2634 |
}
|
2635 |
+
|
2636 |
break;
|
2637 |
case 'text':
|
2638 |
switch ($warning['threshold_type']) {
|
2641 |
$warning_html .= $this->warning_display($warning);
|
2642 |
$num_warnings++;
|
2643 |
}
|
2644 |
+
|
2645 |
break;
|
2646 |
case '!=':
|
2647 |
if ($value != $warning['threshold']) {
|
2648 |
$warning_html .= $this->warning_display($warning);
|
2649 |
$num_warnings++;
|
2650 |
}
|
2651 |
+
|
2652 |
break;
|
2653 |
}
|
2654 |
+
|
2655 |
break;
|
2656 |
case 'array_count':
|
2657 |
switch ($warning['threshold_type']) {
|
2660 |
$warning_html .= $this->warning_display($warning);
|
2661 |
$num_warnings++;
|
2662 |
}
|
2663 |
+
|
2664 |
break;
|
2665 |
}
|
2666 |
+
|
2667 |
break;
|
2668 |
}
|
2669 |
}
|
2670 |
+
|
2671 |
break;
|
2672 |
case 'Advanced Warnings':
|
2673 |
foreach ($warning_set as $name => $warning) {
|
2676 |
$num_warnings++;
|
2677 |
}
|
2678 |
}
|
2679 |
+
|
2680 |
break;
|
2681 |
case 'Bad Plugins':
|
2682 |
foreach ($warning_set as $plugin_folder => $warning) {
|
2695 |
}
|
2696 |
}
|
2697 |
|
2698 |
+
return [$warning_html, $num_warnings];
|
2699 |
}
|
2700 |
|
2701 |
/**
|
2872 |
|
2873 |
PHP;
|
2874 |
}
|
2875 |
+
|
2876 |
if ($obj_server) {
|
2877 |
$a2_config .= <<<PHP
|
2878 |
|
2880 |
|
2881 |
PHP;
|
2882 |
}
|
2883 |
+
|
2884 |
$a2_config .= <<<PHP
|
2885 |
// END A2 CONFIG
|
2886 |
PHP;
|
2919 |
public function get_nomods() {
|
2920 |
return get_option('a2_optimized_nomods');
|
2921 |
}
|
2922 |
+
|
2923 |
/**
|
2924 |
* Check if there is a memcached server set
|
2925 |
*
|
2941 |
//make sure it is writable by owner and readable by everybody
|
2942 |
chmod(ABSPATH . '.htaccess', 0644);
|
2943 |
|
2944 |
+
$home_path = explode('/', str_replace(['http://', 'https://'], '', home_url()), 2);
|
2945 |
|
2946 |
if (!isset($home_path[1]) || $home_path[1] == '') {
|
2947 |
$home_path = '/';
|
3022 |
*/
|
3023 |
public function deleteOption($optionName) {
|
3024 |
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
|
3025 |
+
|
3026 |
return delete_option($prefixedOptionName);
|
3027 |
}
|
3028 |
|
3035 |
*/
|
3036 |
public function updateOption($optionName, $value) {
|
3037 |
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
|
3038 |
+
|
3039 |
return update_option($prefixedOptionName, $value);
|
3040 |
}
|
3041 |
|
3211 |
public function getPluginHeaderValue($key) {
|
3212 |
// Read the string from the comment header of the main plugin file
|
3213 |
$data = file_get_contents($this->getPluginDir() . DIRECTORY_SEPARATOR . $this->getMainPluginFileName());
|
3214 |
+
$match = [];
|
3215 |
preg_match('/' . $key . ':\s*(\S+)/', $data, $match);
|
3216 |
if (count($match) >= 1) {
|
3217 |
return $match[1];
|
A2_Optimized_Plugin.php
CHANGED
@@ -16,7 +16,7 @@ include_once('A2_Optimized_OptionsManager.php');
|
|
16 |
class A2_Optimized_Plugin extends A2_Optimized_OptionsManager {
|
17 |
const optionInstalled = '_installed';
|
18 |
const optionVersion = '_version';
|
19 |
-
private $config_pages =
|
20 |
'w3tc_dashboard',
|
21 |
'w3tc_general',
|
22 |
'w3tc_pgcache',
|
@@ -33,15 +33,15 @@ class A2_Optimized_Plugin extends A2_Optimized_OptionsManager {
|
|
33 |
'w3tc_install',
|
34 |
'w3tc_about',
|
35 |
'w3tc_faq'
|
36 |
-
|
37 |
|
38 |
//list of plugins that may conflict, displays a notice on installation of these plugins
|
39 |
-
private $incompatible_plugins =
|
40 |
'wp-super-cache',
|
41 |
'wp-fastest-cache',
|
42 |
'wp-file-cache',
|
43 |
'better-wp-security',
|
44 |
-
|
45 |
|
46 |
public function install() {
|
47 |
// Initialize Plugin Options
|
@@ -73,13 +73,13 @@ class A2_Optimized_Plugin extends A2_Optimized_OptionsManager {
|
|
73 |
|
74 |
public function getOptionMetaData() {
|
75 |
// http://plugin.michael-simpson.com/?page_id=31
|
76 |
-
return
|
77 |
//'_version' => array('Installed Version'), // Leave this one commented-out. Uncomment to test upgrades.
|
78 |
-
'recaptcha' =>
|
79 |
//'ATextInput' => array(__('Enter in some text', 'my-awesome-plugin')),
|
80 |
//'CanSeeSubmitData' => array(__('Can See Submission data', 'my-awesome-plugin'),
|
81 |
// 'Administrator', 'Editor', 'Author', 'Contributor', 'Subscriber', 'Anyone')
|
82 |
-
|
83 |
}
|
84 |
|
85 |
protected function installDatabaseTables() {
|
@@ -104,7 +104,7 @@ class A2_Optimized_Plugin extends A2_Optimized_OptionsManager {
|
|
104 |
public function getPluginHeaderValue($key) {
|
105 |
// Read the string from the comment header of the main plugin file
|
106 |
$data = file_get_contents($this->getPluginDir() . DIRECTORY_SEPARATOR . $this->getMainPluginFileName());
|
107 |
-
$match =
|
108 |
preg_match('/' . $key . ':\s*(\S+)/', $data, $match);
|
109 |
if (count($match) >= 1) {
|
110 |
return $match[1];
|
@@ -157,6 +157,9 @@ class A2_Optimized_Plugin extends A2_Optimized_OptionsManager {
|
|
157 |
} else {
|
158 |
//no file lock :(
|
159 |
}
|
|
|
|
|
|
|
160 |
}
|
161 |
|
162 |
public function upgrade() {
|
@@ -277,13 +280,13 @@ HTML;
|
|
277 |
$result = curl_exec($ch);
|
278 |
curl_close($ch);
|
279 |
}
|
280 |
-
|
281 |
public function addActionsAndFilters() {
|
282 |
-
add_action('permalink_structure_changed',
|
283 |
|
284 |
$date = date('Y-m-d');
|
285 |
if (strpos($_SERVER['REQUEST_URI'], "login-{$date}") > 0) {
|
286 |
-
add_action('template_redirect',
|
287 |
}
|
288 |
|
289 |
add_filter('allow_minor_auto_core_updates', '__return_true');
|
@@ -296,31 +299,36 @@ HTML;
|
|
296 |
*/
|
297 |
|
298 |
if (is_admin()) {
|
299 |
-
add_filter('admin_init',
|
300 |
-
add_action('admin_bar_menu',
|
301 |
-
add_action('admin_menu',
|
302 |
if (defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) {
|
303 |
-
add_action('admin_menu',
|
304 |
}
|
305 |
-
add_action('admin_print_styles',
|
306 |
-
add_action('wp_dashboard_setup',
|
307 |
$a2_plugin_basename = plugin_basename($GLOBALS['A2_Plugin_Dir'] . '/a2-optimized.php');
|
308 |
-
add_filter("plugin_action_links_{$a2_plugin_basename}",
|
309 |
-
register_setting( 'a2opt-cache', 'a2opt-cache',
|
310 |
-
register_setting( 'a2opt-cache', '
|
|
|
|
|
311 |
new A2_Optimized_SiteHealth;
|
|
|
312 |
}
|
313 |
|
|
|
|
|
314 |
if (get_option('A2_Optimized_Plugin_recaptcha', 0) == 1 && !is_admin()) {
|
315 |
-
add_action('woocommerce_login_form',
|
316 |
-
add_action('login_form',
|
317 |
-
add_filter('authenticate',
|
318 |
-
add_action('comment_form_after_fields',
|
319 |
-
add_filter('preprocess_comment',
|
320 |
}
|
321 |
if ($this->is_xmlrpc_request() && get_option('a2_block_xmlrpc')) {
|
322 |
$this->block_xmlrpc_request();
|
323 |
-
add_filter('xmlrpc_methods',
|
324 |
}
|
325 |
}
|
326 |
|
@@ -351,13 +359,13 @@ HTML;
|
|
351 |
wp_add_dashboard_widget(
|
352 |
'a2_optimized', // Widget slug.
|
353 |
"<a href=\"admin.php?page=A2_Optimized_Plugin_admin\"><img src=\"{$logo_url}\" /></a>", // Title.
|
354 |
-
|
355 |
);
|
356 |
|
357 |
wp_add_dashboard_widget(
|
358 |
'a2_optimized_kb', // Widget slug.
|
359 |
'Have any questions? Search the A2 Hosting Knowledge Base for answers.', // Title.
|
360 |
-
|
361 |
);
|
362 |
|
363 |
//force the widget to the top of the dashboard
|
@@ -371,7 +379,7 @@ HTML;
|
|
371 |
|
372 |
$normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
|
373 |
// Backup and delete our new dashboard widget from the end of the array
|
374 |
-
$example_widget_backup =
|
375 |
|
376 |
// Merge the two arrays together so our widget is at the beginning
|
377 |
$sorted_dashboard = array_merge($example_widget_backup, $normal_dashboard);
|
@@ -445,7 +453,7 @@ HTML;
|
|
445 |
public function divi_notice() {
|
446 |
$current_theme = get_template();
|
447 |
$dismiss_url = admin_url('admin.php?a2-page=dismiss_notice&a2-option=a2_notice_diviminify&page=A2_Optimized_Plugin_admin');
|
448 |
-
|
449 |
echo <<<HTML
|
450 |
<div id="divi-minify-notice" class="notice notice-error" >
|
451 |
<p><strong style="color:red">Your theme, {$current_theme}, currently provides HTML/JS/CSS minification. This feature is also enabled by A2 Optimized. This may cause issues with some functionality of your theme.</strong></p>
|
@@ -491,7 +499,7 @@ HTML;
|
|
491 |
if (in_array('easy-hide-login/wp-hide-login.php', $active_plugins)) {
|
492 |
if ($rwl_page = get_option('wpseh_l01gnhdlwp')) {
|
493 |
if ($rwl_page != '') {
|
494 |
-
add_action('admin_notices',
|
495 |
if ($a2_login_page = get_option('a2_login_page')) {
|
496 |
if ($a2_login_page != $rwl_page) {
|
497 |
update_option('a2_login_page', $rwl_page);
|
@@ -503,19 +511,19 @@ HTML;
|
|
503 |
}
|
504 |
}
|
505 |
if (in_array('a2-w3-total-cache/a2-w3-total-cache.php', $active_plugins)) {
|
506 |
-
wp_enqueue_script('a2_functions', plugins_url('/assets/js/functions.js', __FILE__),
|
507 |
}
|
508 |
|
509 |
if (isset($_GET['page']) && in_array($_GET['page'], $this->config_pages) && get_option('a2_notice_configpage') != '1') {
|
510 |
-
add_action('admin_notices',
|
511 |
}
|
512 |
|
513 |
if (get_template() == 'Divi') {
|
514 |
$w3tc = $this->get_w3tc_config();
|
515 |
-
|
516 |
if ($w3tc['minify.html.enable'] || $w3tc['minify.css.enable'] || $w3tc['minify.js.enable']) {
|
517 |
if (get_option('a2_notice_diviminify') != '1') {
|
518 |
-
add_action('admin_notices',
|
519 |
}
|
520 |
}
|
521 |
}
|
@@ -523,25 +531,25 @@ HTML;
|
|
523 |
foreach ($active_plugins as $active_plugin) {
|
524 |
$plugin_folder = explode('/', $active_plugin);
|
525 |
if (in_array($plugin_folder[0], $this->incompatible_plugins) && get_option('a2_notice_incompatible_plugins') != '1') {
|
526 |
-
add_action('admin_notices',
|
527 |
}
|
528 |
// Check for W3 Total Cache and show upgrade notice
|
529 |
if ($plugin_folder[0] == 'w3-total-cache' && !$_GET['a2-page'] && get_option('a2_notice_w3totalcache') != '1') {
|
530 |
-
add_action('admin_notices',
|
531 |
}
|
532 |
// Check for Wordfence and if WAF rules are setup correctly, show notice if not
|
533 |
if ($plugin_folder[0] == 'wordfence' && $this->wordfence_waf_check() === false && get_option['a2_notice_wordfence_waf'] != '1') {
|
534 |
-
add_action('admin_notices',
|
535 |
}
|
536 |
}
|
537 |
|
538 |
if (!(strpos($_SERVER['SCRIPT_FILENAME'], 'plugins.php') === false) && defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) {
|
539 |
if (get_option('a2_notice_editinglocked') != '1') {
|
540 |
-
add_action('admin_notices',
|
541 |
}
|
542 |
} elseif (!(strpos($_SERVER['SCRIPT_FILENAME'], 'plugins.php') === false)) {
|
543 |
if (get_option('a2_notice_editingnotlocked') != '1') {
|
544 |
-
add_action('admin_notices',
|
545 |
}
|
546 |
}
|
547 |
}
|
@@ -564,7 +572,7 @@ HTML;
|
|
564 |
$displayName,
|
565 |
'manage_options',
|
566 |
$this->getSettingsSlug(),
|
567 |
-
|
568 |
null,
|
569 |
3
|
570 |
);
|
@@ -588,17 +596,17 @@ HTML;
|
|
588 |
global $wp_admin_bar;
|
589 |
|
590 |
if (current_user_can('manage_options')) {
|
591 |
-
$wp_admin_bar->add_node(
|
592 |
'id' => 'a2-optimized-admin-bar',
|
593 |
'title' => 'A2 Optimized',
|
594 |
'href' => admin_url('admin.php?page=' . $this->getSettingsSlug())
|
595 |
-
)
|
596 |
}
|
597 |
}
|
598 |
|
599 |
public function addLockedEditor() {
|
600 |
$this->requireExtraPluginFiles();
|
601 |
-
add_theme_page('<span style="color:red !important">Editor Locked</span>', '<span style="color:red !important">Editor Locked</span>', 'manage_options', 'editor-locked',
|
602 |
}
|
603 |
|
604 |
/**
|
@@ -628,7 +636,7 @@ HTML;
|
|
628 |
$displayName,
|
629 |
'manage_options',
|
630 |
$this->getSettingsSlug(),
|
631 |
-
|
632 |
);
|
633 |
}
|
634 |
|
@@ -640,7 +648,7 @@ HTML;
|
|
640 |
$displayName,
|
641 |
'manage_options',
|
642 |
$this->getSettingsSlug(),
|
643 |
-
|
644 |
);
|
645 |
}
|
646 |
|
@@ -652,13 +660,13 @@ HTML;
|
|
652 |
$displayName,
|
653 |
'manage_options',
|
654 |
$this->getSettingsSlug(),
|
655 |
-
|
656 |
);
|
657 |
}
|
658 |
|
659 |
public function incompatible_plugin_notice() {
|
660 |
$active_plugins = get_option('active_plugins');
|
661 |
-
$plugins_arr =
|
662 |
foreach ($active_plugins as $active_plugin) {
|
663 |
$plugin_folder = explode('/', $active_plugin);
|
664 |
if (in_array($plugin_folder[0], $this->incompatible_plugins)) {
|
@@ -690,17 +698,17 @@ HTML;
|
|
690 |
public function is_xmlrpc_request() {
|
691 |
return defined('XMLRPC_REQUEST') && XMLRPC_REQUEST;
|
692 |
}
|
693 |
-
|
694 |
/* Block this xmlrpc request unless other criteria are met */
|
695 |
private function block_xmlrpc_request() {
|
696 |
if ($this->client_is_automattic()) {
|
697 |
return;
|
698 |
}
|
699 |
-
|
700 |
if ($this->clientip_whitelisted()) {
|
701 |
return;
|
702 |
}
|
703 |
-
|
704 |
if (!headers_sent()) {
|
705 |
header('Connection: close');
|
706 |
header('Content-Type: text/xml');
|
@@ -715,7 +723,7 @@ HTML;
|
|
715 |
if ($this->client_is_automattic()) {
|
716 |
return $xml_rpc_methods;
|
717 |
}
|
718 |
-
|
719 |
if ($this->clientip_whitelisted()) {
|
720 |
return $xml_rpc_methods;
|
721 |
}
|
@@ -725,12 +733,12 @@ HTML;
|
|
725 |
|
726 |
return $xml_rpc_methods;
|
727 |
}
|
728 |
-
|
729 |
public function clientip_whitelisted() {
|
730 |
// For future consideration
|
731 |
return false;
|
732 |
}
|
733 |
-
|
734 |
/* Checks if a Automattic plugin is installed
|
735 |
Checks if IP making request if from Automattic
|
736 |
https://jetpack.com/support/hosting-faq/
|
@@ -743,27 +751,27 @@ HTML;
|
|
743 |
&& !is_plugin_active('vaultpress/vaultpress.php')) {
|
744 |
return false;
|
745 |
}
|
746 |
-
|
747 |
$ip_address = $_SERVER['REMOTE_ADDR'];
|
748 |
if ($this->is_ip_in_range(
|
749 |
$ip_address,
|
750 |
-
|
751 |
'122.248.245.244', // Jetpack
|
752 |
'54.217.201.243', // Jetpack
|
753 |
'54.232.116.4', // Jetpack
|
754 |
-
|
755 |
-
|
756 |
//array('192.0.80.0', '192.0.95.255'), // Akismet (covered by VaultPress range)
|
757 |
//array('192.0.96.0', '192.0.111.255'), // Akismet
|
758 |
//array('192.0.112.0', '192.0.127.255'), // Akismet
|
759 |
-
|
760 |
)) {
|
761 |
return true;
|
762 |
}
|
763 |
|
764 |
return false;
|
765 |
}
|
766 |
-
|
767 |
/* Use ip2long to do comparisons */
|
768 |
public function is_ip_in_range($ip_address, $range_array) {
|
769 |
$ip_long = ip2long($ip_address);
|
@@ -783,7 +791,7 @@ HTML;
|
|
783 |
|
784 |
return false;
|
785 |
}
|
786 |
-
|
787 |
/*
|
788 |
* WordFence WAF Functions
|
789 |
*/
|
@@ -794,7 +802,7 @@ HTML;
|
|
794 |
|
795 |
return strpos($htaccess, 'Wordfence WAF');
|
796 |
}
|
797 |
-
|
798 |
public function wordfence_plugin_notice() {
|
799 |
$dismiss_url = admin_url('admin.php?a2-page=dismiss_notice&a2-option=a2_notice_wordfence_waf&page=A2_Optimized_Plugin_admin');
|
800 |
echo <<<HTML
|
16 |
class A2_Optimized_Plugin extends A2_Optimized_OptionsManager {
|
17 |
const optionInstalled = '_installed';
|
18 |
const optionVersion = '_version';
|
19 |
+
private $config_pages = [
|
20 |
'w3tc_dashboard',
|
21 |
'w3tc_general',
|
22 |
'w3tc_pgcache',
|
33 |
'w3tc_install',
|
34 |
'w3tc_about',
|
35 |
'w3tc_faq'
|
36 |
+
];
|
37 |
|
38 |
//list of plugins that may conflict, displays a notice on installation of these plugins
|
39 |
+
private $incompatible_plugins = [
|
40 |
'wp-super-cache',
|
41 |
'wp-fastest-cache',
|
42 |
'wp-file-cache',
|
43 |
'better-wp-security',
|
44 |
+
];
|
45 |
|
46 |
public function install() {
|
47 |
// Initialize Plugin Options
|
73 |
|
74 |
public function getOptionMetaData() {
|
75 |
// http://plugin.michael-simpson.com/?page_id=31
|
76 |
+
return [
|
77 |
//'_version' => array('Installed Version'), // Leave this one commented-out. Uncomment to test upgrades.
|
78 |
+
'recaptcha' => ['reCaptcha'],
|
79 |
//'ATextInput' => array(__('Enter in some text', 'my-awesome-plugin')),
|
80 |
//'CanSeeSubmitData' => array(__('Can See Submission data', 'my-awesome-plugin'),
|
81 |
// 'Administrator', 'Editor', 'Author', 'Contributor', 'Subscriber', 'Anyone')
|
82 |
+
];
|
83 |
}
|
84 |
|
85 |
protected function installDatabaseTables() {
|
104 |
public function getPluginHeaderValue($key) {
|
105 |
// Read the string from the comment header of the main plugin file
|
106 |
$data = file_get_contents($this->getPluginDir() . DIRECTORY_SEPARATOR . $this->getMainPluginFileName());
|
107 |
+
$match = [];
|
108 |
preg_match('/' . $key . ':\s*(\S+)/', $data, $match);
|
109 |
if (count($match) >= 1) {
|
110 |
return $match[1];
|
157 |
} else {
|
158 |
//no file lock :(
|
159 |
}
|
160 |
+
|
161 |
+
// deactivate the scheduled weekly database optimizations
|
162 |
+
wp_clear_scheduled_hook(A2_Optimized_DBOptimizations::EXECUTE_OPTIMIZATIONS_HOOK);
|
163 |
}
|
164 |
|
165 |
public function upgrade() {
|
280 |
$result = curl_exec($ch);
|
281 |
curl_close($ch);
|
282 |
}
|
283 |
+
|
284 |
public function addActionsAndFilters() {
|
285 |
+
add_action('permalink_structure_changed', [&$this, 'permalink_changed']);
|
286 |
|
287 |
$date = date('Y-m-d');
|
288 |
if (strpos($_SERVER['REQUEST_URI'], "login-{$date}") > 0) {
|
289 |
+
add_action('template_redirect', [&$this, 'get_moved_login']);
|
290 |
}
|
291 |
|
292 |
add_filter('allow_minor_auto_core_updates', '__return_true');
|
299 |
*/
|
300 |
|
301 |
if (is_admin()) {
|
302 |
+
add_filter('admin_init', [&$this, 'admin_init']);
|
303 |
+
add_action('admin_bar_menu', [&$this, 'addAdminBar'], 8374);
|
304 |
+
add_action('admin_menu', [&$this, 'addSettingsSubMenuPage']);
|
305 |
if (defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) {
|
306 |
+
add_action('admin_menu', [&$this, 'addLockedEditor'], 100, 100);
|
307 |
}
|
308 |
+
add_action('admin_print_styles', [&$this, 'myStyleSheet']);
|
309 |
+
add_action('wp_dashboard_setup', [&$this, 'dashboard_widget']);
|
310 |
$a2_plugin_basename = plugin_basename($GLOBALS['A2_Plugin_Dir'] . '/a2-optimized.php');
|
311 |
+
add_filter("plugin_action_links_{$a2_plugin_basename}", [&$this, 'plugin_settings_link']);
|
312 |
+
register_setting( 'a2opt-cache', 'a2opt-cache', [ 'A2_Optimized_Cache', 'validate_settings' ] );
|
313 |
+
register_setting( 'a2opt-cache', 'a2_optimized_objectcache_type');
|
314 |
+
register_setting( 'a2opt-cache', 'a2_optimized_memcached_server', ['A2_Optimized_Cache', 'validate_object_cache' ]);
|
315 |
+
register_setting( 'a2opt-cache', 'a2_optimized_redis_server', ['A2_Optimized_Cache', 'validate_object_cache' ]);
|
316 |
new A2_Optimized_SiteHealth;
|
317 |
+
register_setting('a2opt-cache', 'a2_db_optimizations', ['A2_Optimized_DBOptimizations', 'validate_db_optimization_settings']);
|
318 |
}
|
319 |
|
320 |
+
new A2_Optimized_DBOptimizations;
|
321 |
+
|
322 |
if (get_option('A2_Optimized_Plugin_recaptcha', 0) == 1 && !is_admin()) {
|
323 |
+
add_action('woocommerce_login_form', [&$this, 'login_captcha']);
|
324 |
+
add_action('login_form', [&$this, 'login_captcha']);
|
325 |
+
add_filter('authenticate', [&$this, 'captcha_authenticate'], 1, 3);
|
326 |
+
add_action('comment_form_after_fields', [&$this, 'comment_captcha']);
|
327 |
+
add_filter('preprocess_comment', [&$this, 'captcha_comment_authenticate'], 1, 3);
|
328 |
}
|
329 |
if ($this->is_xmlrpc_request() && get_option('a2_block_xmlrpc')) {
|
330 |
$this->block_xmlrpc_request();
|
331 |
+
add_filter('xmlrpc_methods', [&$this, 'remove_xmlrpc_methods']);
|
332 |
}
|
333 |
}
|
334 |
|
359 |
wp_add_dashboard_widget(
|
360 |
'a2_optimized', // Widget slug.
|
361 |
"<a href=\"admin.php?page=A2_Optimized_Plugin_admin\"><img src=\"{$logo_url}\" /></a>", // Title.
|
362 |
+
[&$this, 'a2_dashboard_widget'] // Display function.
|
363 |
);
|
364 |
|
365 |
wp_add_dashboard_widget(
|
366 |
'a2_optimized_kb', // Widget slug.
|
367 |
'Have any questions? Search the A2 Hosting Knowledge Base for answers.', // Title.
|
368 |
+
[&$this, 'kb_dashboard_widget'] // Display function.
|
369 |
);
|
370 |
|
371 |
//force the widget to the top of the dashboard
|
379 |
|
380 |
$normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
|
381 |
// Backup and delete our new dashboard widget from the end of the array
|
382 |
+
$example_widget_backup = ['a2_optimized' => $normal_dashboard['a2_optimized'], 'a2_optimized_kb' => $normal_dashboard['a2_optimized_kb']];
|
383 |
|
384 |
// Merge the two arrays together so our widget is at the beginning
|
385 |
$sorted_dashboard = array_merge($example_widget_backup, $normal_dashboard);
|
453 |
public function divi_notice() {
|
454 |
$current_theme = get_template();
|
455 |
$dismiss_url = admin_url('admin.php?a2-page=dismiss_notice&a2-option=a2_notice_diviminify&page=A2_Optimized_Plugin_admin');
|
456 |
+
|
457 |
echo <<<HTML
|
458 |
<div id="divi-minify-notice" class="notice notice-error" >
|
459 |
<p><strong style="color:red">Your theme, {$current_theme}, currently provides HTML/JS/CSS minification. This feature is also enabled by A2 Optimized. This may cause issues with some functionality of your theme.</strong></p>
|
499 |
if (in_array('easy-hide-login/wp-hide-login.php', $active_plugins)) {
|
500 |
if ($rwl_page = get_option('wpseh_l01gnhdlwp')) {
|
501 |
if ($rwl_page != '') {
|
502 |
+
add_action('admin_notices', [&$this, 'rwl_notice']);
|
503 |
if ($a2_login_page = get_option('a2_login_page')) {
|
504 |
if ($a2_login_page != $rwl_page) {
|
505 |
update_option('a2_login_page', $rwl_page);
|
511 |
}
|
512 |
}
|
513 |
if (in_array('a2-w3-total-cache/a2-w3-total-cache.php', $active_plugins)) {
|
514 |
+
wp_enqueue_script('a2_functions', plugins_url('/assets/js/functions.js', __FILE__), ['jquery']);
|
515 |
}
|
516 |
|
517 |
if (isset($_GET['page']) && in_array($_GET['page'], $this->config_pages) && get_option('a2_notice_configpage') != '1') {
|
518 |
+
add_action('admin_notices', [&$this, 'config_page_notice']);
|
519 |
}
|
520 |
|
521 |
if (get_template() == 'Divi') {
|
522 |
$w3tc = $this->get_w3tc_config();
|
523 |
+
|
524 |
if ($w3tc['minify.html.enable'] || $w3tc['minify.css.enable'] || $w3tc['minify.js.enable']) {
|
525 |
if (get_option('a2_notice_diviminify') != '1') {
|
526 |
+
add_action('admin_notices', [&$this, 'divi_notice']);
|
527 |
}
|
528 |
}
|
529 |
}
|
531 |
foreach ($active_plugins as $active_plugin) {
|
532 |
$plugin_folder = explode('/', $active_plugin);
|
533 |
if (in_array($plugin_folder[0], $this->incompatible_plugins) && get_option('a2_notice_incompatible_plugins') != '1') {
|
534 |
+
add_action('admin_notices', [&$this, 'incompatible_plugin_notice']);
|
535 |
}
|
536 |
// Check for W3 Total Cache and show upgrade notice
|
537 |
if ($plugin_folder[0] == 'w3-total-cache' && !$_GET['a2-page'] && get_option('a2_notice_w3totalcache') != '1') {
|
538 |
+
add_action('admin_notices', [&$this, 'w3totalcache_plugin_notice']);
|
539 |
}
|
540 |
// Check for Wordfence and if WAF rules are setup correctly, show notice if not
|
541 |
if ($plugin_folder[0] == 'wordfence' && $this->wordfence_waf_check() === false && get_option['a2_notice_wordfence_waf'] != '1') {
|
542 |
+
add_action('admin_notices', [&$this, 'wordfence_plugin_notice']);
|
543 |
}
|
544 |
}
|
545 |
|
546 |
if (!(strpos($_SERVER['SCRIPT_FILENAME'], 'plugins.php') === false) && defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) {
|
547 |
if (get_option('a2_notice_editinglocked') != '1') {
|
548 |
+
add_action('admin_notices', [&$this, 'locked_files_notice']);
|
549 |
}
|
550 |
} elseif (!(strpos($_SERVER['SCRIPT_FILENAME'], 'plugins.php') === false)) {
|
551 |
if (get_option('a2_notice_editingnotlocked') != '1') {
|
552 |
+
add_action('admin_notices', [&$this, 'not_locked_files_notice']);
|
553 |
}
|
554 |
}
|
555 |
}
|
572 |
$displayName,
|
573 |
'manage_options',
|
574 |
$this->getSettingsSlug(),
|
575 |
+
[&$this, 'settingsPage'],
|
576 |
null,
|
577 |
3
|
578 |
);
|
596 |
global $wp_admin_bar;
|
597 |
|
598 |
if (current_user_can('manage_options')) {
|
599 |
+
$wp_admin_bar->add_node([
|
600 |
'id' => 'a2-optimized-admin-bar',
|
601 |
'title' => 'A2 Optimized',
|
602 |
'href' => admin_url('admin.php?page=' . $this->getSettingsSlug())
|
603 |
+
]);
|
604 |
}
|
605 |
}
|
606 |
|
607 |
public function addLockedEditor() {
|
608 |
$this->requireExtraPluginFiles();
|
609 |
+
add_theme_page('<span style="color:red !important">Editor Locked</span>', '<span style="color:red !important">Editor Locked</span>', 'manage_options', 'editor-locked', [&$this, 'settingsPage']);
|
610 |
}
|
611 |
|
612 |
/**
|
636 |
$displayName,
|
637 |
'manage_options',
|
638 |
$this->getSettingsSlug(),
|
639 |
+
[&$this, 'settingsPage']
|
640 |
);
|
641 |
}
|
642 |
|
648 |
$displayName,
|
649 |
'manage_options',
|
650 |
$this->getSettingsSlug(),
|
651 |
+
[&$this, 'settingsPage']
|
652 |
);
|
653 |
}
|
654 |
|
660 |
$displayName,
|
661 |
'manage_options',
|
662 |
$this->getSettingsSlug(),
|
663 |
+
[&$this, 'settingsPage']
|
664 |
);
|
665 |
}
|
666 |
|
667 |
public function incompatible_plugin_notice() {
|
668 |
$active_plugins = get_option('active_plugins');
|
669 |
+
$plugins_arr = [];
|
670 |
foreach ($active_plugins as $active_plugin) {
|
671 |
$plugin_folder = explode('/', $active_plugin);
|
672 |
if (in_array($plugin_folder[0], $this->incompatible_plugins)) {
|
698 |
public function is_xmlrpc_request() {
|
699 |
return defined('XMLRPC_REQUEST') && XMLRPC_REQUEST;
|
700 |
}
|
701 |
+
|
702 |
/* Block this xmlrpc request unless other criteria are met */
|
703 |
private function block_xmlrpc_request() {
|
704 |
if ($this->client_is_automattic()) {
|
705 |
return;
|
706 |
}
|
707 |
+
|
708 |
if ($this->clientip_whitelisted()) {
|
709 |
return;
|
710 |
}
|
711 |
+
|
712 |
if (!headers_sent()) {
|
713 |
header('Connection: close');
|
714 |
header('Content-Type: text/xml');
|
723 |
if ($this->client_is_automattic()) {
|
724 |
return $xml_rpc_methods;
|
725 |
}
|
726 |
+
|
727 |
if ($this->clientip_whitelisted()) {
|
728 |
return $xml_rpc_methods;
|
729 |
}
|
733 |
|
734 |
return $xml_rpc_methods;
|
735 |
}
|
736 |
+
|
737 |
public function clientip_whitelisted() {
|
738 |
// For future consideration
|
739 |
return false;
|
740 |
}
|
741 |
+
|
742 |
/* Checks if a Automattic plugin is installed
|
743 |
Checks if IP making request if from Automattic
|
744 |
https://jetpack.com/support/hosting-faq/
|
751 |
&& !is_plugin_active('vaultpress/vaultpress.php')) {
|
752 |
return false;
|
753 |
}
|
754 |
+
|
755 |
$ip_address = $_SERVER['REMOTE_ADDR'];
|
756 |
if ($this->is_ip_in_range(
|
757 |
$ip_address,
|
758 |
+
[
|
759 |
'122.248.245.244', // Jetpack
|
760 |
'54.217.201.243', // Jetpack
|
761 |
'54.232.116.4', // Jetpack
|
762 |
+
['195.234.108.0', '195.234.111.255'], // Jetpack
|
763 |
+
['192.0.64.1', '192.0.127.255'], // VaultPress range
|
764 |
//array('192.0.80.0', '192.0.95.255'), // Akismet (covered by VaultPress range)
|
765 |
//array('192.0.96.0', '192.0.111.255'), // Akismet
|
766 |
//array('192.0.112.0', '192.0.127.255'), // Akismet
|
767 |
+
]
|
768 |
)) {
|
769 |
return true;
|
770 |
}
|
771 |
|
772 |
return false;
|
773 |
}
|
774 |
+
|
775 |
/* Use ip2long to do comparisons */
|
776 |
public function is_ip_in_range($ip_address, $range_array) {
|
777 |
$ip_long = ip2long($ip_address);
|
791 |
|
792 |
return false;
|
793 |
}
|
794 |
+
|
795 |
/*
|
796 |
* WordFence WAF Functions
|
797 |
*/
|
802 |
|
803 |
return strpos($htaccess, 'Wordfence WAF');
|
804 |
}
|
805 |
+
|
806 |
public function wordfence_plugin_notice() {
|
807 |
$dismiss_url = admin_url('admin.php?a2-page=dismiss_notice&a2-option=a2_notice_wordfence_waf&page=A2_Optimized_Plugin_admin');
|
808 |
echo <<<HTML
|
a2-optimized.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/*
|
3 |
Plugin Name: A2 Optimized WP
|
4 |
Plugin URI: https://wordpress.org/plugins/a2-optimized/
|
5 |
-
Version: 2.1.
|
6 |
Author: A2 Hosting
|
7 |
Author URI: https://www.a2hosting.com/
|
8 |
Description: A2 Optimized - WordPress Optimization Plugin
|
@@ -26,10 +26,11 @@ require_once 'A2_Optimized_Cache.php';
|
|
26 |
require_once 'A2_Optimized_CacheEngine.php';
|
27 |
require_once 'A2_Optimized_CacheDisk.php';
|
28 |
require_once 'A2_Optimized_SiteHealth.php';
|
|
|
29 |
|
30 |
//constants
|
31 |
define( 'A2OPT_VERSION', '2.1' );
|
32 |
-
define( 'A2OPT_FULL_VERSION', '2.1.
|
33 |
define( 'A2OPT_MIN_PHP', '5.6' );
|
34 |
define( 'A2OPT_MIN_WP', '5.1' );
|
35 |
define( 'A2OPT_FILE', __FILE__ );
|
@@ -39,7 +40,7 @@ define( 'A2OPT_DIR', __DIR__ );
|
|
39 |
class A2_Optimized {
|
40 |
public function __construct() {
|
41 |
if (version_compare(PHP_VERSION, A2OPT_MIN_PHP) < 0) {
|
42 |
-
add_action('admin_notices',
|
43 |
|
44 |
return;
|
45 |
}
|
@@ -60,10 +61,10 @@ class A2_Optimized {
|
|
60 |
$a2Plugin->addActionsAndFilters();
|
61 |
|
62 |
// Register the Plugin Activation Hook
|
63 |
-
register_activation_hook(__FILE__,
|
64 |
|
65 |
// Register the Plugin Deactivation Hook
|
66 |
-
register_deactivation_hook(__FILE__,
|
67 |
}
|
68 |
|
69 |
public function A2_Optimized_noticePhpVersionWrong() {
|
@@ -82,7 +83,7 @@ class A2_Optimized {
|
|
82 |
if (!$upgrade_notices) {
|
83 |
$response = wp_remote_get( 'https://wp-plugins.a2hosting.com/wp-json/wp/v2/update_notice?notice_plugin=2' );
|
84 |
if ( is_array( $response ) ) {
|
85 |
-
$upgrade_notices =
|
86 |
$body = json_decode($response['body']); // use the content
|
87 |
foreach ($body as $item) {
|
88 |
$upgrade_notices[$item->title->rendered] = 'Version ' . $item->title->rendered . ': ' . strip_tags($item->content->rendered);
|
@@ -97,6 +98,7 @@ class A2_Optimized {
|
|
97 |
if (version_compare($currentPluginMetadata['Version'], $ver) < 0) {
|
98 |
echo '</div><p style="background-color: #d54e21; padding: 10px; color: #f9f9f9; margin-top: 10px" class="update-message notice inline notice-warning notice-alt"><strong>Important Upgrade Notice:</strong><br />';
|
99 |
echo esc_html($notice), '</p><div>';
|
|
|
100 |
break;
|
101 |
}
|
102 |
}
|
@@ -111,14 +113,14 @@ class A2_Optimized {
|
|
111 |
}
|
112 |
|
113 |
if (get_option('a2_cache_enabled') == 1) {
|
114 |
-
add_action( 'plugins_loaded',
|
115 |
}
|
116 |
-
register_deactivation_hook( __FILE__,
|
117 |
-
register_uninstall_hook( __FILE__,
|
118 |
|
119 |
$a2opt_class = new A2_Optimized();
|
120 |
-
add_action('in_plugin_update_message-a2-optimized-wp/a2-optimized.php',
|
121 |
-
add_action( 'wp_enqueue_scripts',
|
122 |
|
123 |
// load WP-CLI command
|
124 |
if ( defined( 'WP_CLI' ) && WP_CLI && class_exists( 'WP_CLI' ) ) {
|
2 |
/*
|
3 |
Plugin Name: A2 Optimized WP
|
4 |
Plugin URI: https://wordpress.org/plugins/a2-optimized/
|
5 |
+
Version: 2.1.4
|
6 |
Author: A2 Hosting
|
7 |
Author URI: https://www.a2hosting.com/
|
8 |
Description: A2 Optimized - WordPress Optimization Plugin
|
26 |
require_once 'A2_Optimized_CacheEngine.php';
|
27 |
require_once 'A2_Optimized_CacheDisk.php';
|
28 |
require_once 'A2_Optimized_SiteHealth.php';
|
29 |
+
require_once 'A2_Optimized_DB_Optimizations.php';
|
30 |
|
31 |
//constants
|
32 |
define( 'A2OPT_VERSION', '2.1' );
|
33 |
+
define( 'A2OPT_FULL_VERSION', '2.1.4' );
|
34 |
define( 'A2OPT_MIN_PHP', '5.6' );
|
35 |
define( 'A2OPT_MIN_WP', '5.1' );
|
36 |
define( 'A2OPT_FILE', __FILE__ );
|
40 |
class A2_Optimized {
|
41 |
public function __construct() {
|
42 |
if (version_compare(PHP_VERSION, A2OPT_MIN_PHP) < 0) {
|
43 |
+
add_action('admin_notices', [&$this,'A2_Optimized_noticePhpVersionWrong']);
|
44 |
|
45 |
return;
|
46 |
}
|
61 |
$a2Plugin->addActionsAndFilters();
|
62 |
|
63 |
// Register the Plugin Activation Hook
|
64 |
+
register_activation_hook(__FILE__, [&$a2Plugin, 'activate']);
|
65 |
|
66 |
// Register the Plugin Deactivation Hook
|
67 |
+
register_deactivation_hook(__FILE__, [&$a2Plugin, 'deactivate']);
|
68 |
}
|
69 |
|
70 |
public function A2_Optimized_noticePhpVersionWrong() {
|
83 |
if (!$upgrade_notices) {
|
84 |
$response = wp_remote_get( 'https://wp-plugins.a2hosting.com/wp-json/wp/v2/update_notice?notice_plugin=2' );
|
85 |
if ( is_array( $response ) ) {
|
86 |
+
$upgrade_notices = [];
|
87 |
$body = json_decode($response['body']); // use the content
|
88 |
foreach ($body as $item) {
|
89 |
$upgrade_notices[$item->title->rendered] = 'Version ' . $item->title->rendered . ': ' . strip_tags($item->content->rendered);
|
98 |
if (version_compare($currentPluginMetadata['Version'], $ver) < 0) {
|
99 |
echo '</div><p style="background-color: #d54e21; padding: 10px; color: #f9f9f9; margin-top: 10px" class="update-message notice inline notice-warning notice-alt"><strong>Important Upgrade Notice:</strong><br />';
|
100 |
echo esc_html($notice), '</p><div>';
|
101 |
+
|
102 |
break;
|
103 |
}
|
104 |
}
|
113 |
}
|
114 |
|
115 |
if (get_option('a2_cache_enabled') == 1) {
|
116 |
+
add_action( 'plugins_loaded', [ 'A2_Optimized_Cache', 'init' ] );
|
117 |
}
|
118 |
+
register_deactivation_hook( __FILE__, [ 'A2_Optimized_Cache', 'on_deactivation' ] );
|
119 |
+
register_uninstall_hook( __FILE__, [ 'A2_Optimized_Cache', 'on_uninstall' ] );
|
120 |
|
121 |
$a2opt_class = new A2_Optimized();
|
122 |
+
add_action('in_plugin_update_message-a2-optimized-wp/a2-optimized.php', [ 'A2_Optimized','showUpgradeNotification'], 10, 2);
|
123 |
+
add_action( 'wp_enqueue_scripts', ['A2_Optimized', 'dequeue_woocommerce_cart_fragments'], 11, 2);
|
124 |
|
125 |
// load WP-CLI command
|
126 |
if ( defined( 'WP_CLI' ) && WP_CLI && class_exists( 'WP_CLI' ) ) {
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: A2BCool, a2hosting, dmatteson, sputala
|
3 |
Tags: Speed, Optimize, Secure, Fast, LiteSpeed, LSCache, A2, Hosting
|
4 |
Requires at least: 5.1
|
5 |
-
Tested up to:
|
6 |
-
Stable tag: 2.1.
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
@@ -39,6 +39,16 @@ A2 Optimized has broken it down into the most valuable optimizations and will au
|
|
39 |
* Can provide significant speed improvements for page loads.
|
40 |
* Reduces bandwidth required to serve web pages.
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
**Deny Direct Access to Configuration Files and Comment Form**:
|
43 |
|
44 |
* Enables WordPress hardening rules in .htaccess to prevent browser access to certain files.
|
@@ -123,6 +133,10 @@ Yes. A2 Optimized works on any host that supports WordPress; however, A2 Hostin
|
|
123 |
|
124 |
== Changelog ==
|
125 |
|
|
|
|
|
|
|
|
|
126 |
= 2.1.3.10 =
|
127 |
* Add information related to A2 Optimized to the Site Health panel.
|
128 |
|
2 |
Contributors: A2BCool, a2hosting, dmatteson, sputala
|
3 |
Tags: Speed, Optimize, Secure, Fast, LiteSpeed, LSCache, A2, Hosting
|
4 |
Requires at least: 5.1
|
5 |
+
Tested up to: 6.0
|
6 |
+
Stable tag: 2.1.4
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
39 |
* Can provide significant speed improvements for page loads.
|
40 |
* Reduces bandwidth required to serve web pages.
|
41 |
|
42 |
+
**Scheduled Database Optimizations**:
|
43 |
+
|
44 |
+
If enabled, will periodically perform the following database operations:
|
45 |
+
* Remove expired transients
|
46 |
+
* Remove Trashed comments
|
47 |
+
* Remove spam comments
|
48 |
+
* Optimize all tables
|
49 |
+
* Remove post revisions (not enabled by default)
|
50 |
+
* Remove trashed posts (not enabled by default)
|
51 |
+
|
52 |
**Deny Direct Access to Configuration Files and Comment Form**:
|
53 |
|
54 |
* Enables WordPress hardening rules in .htaccess to prevent browser access to certain files.
|
133 |
|
134 |
== Changelog ==
|
135 |
|
136 |
+
= 2.1.4 =
|
137 |
+
* Added Scheduled Database Optimizations.
|
138 |
+
* Added support for redis object caching on A2 Hosting.
|
139 |
+
|
140 |
= 2.1.3.10 =
|
141 |
* Add information related to A2 Optimized to the Site Health panel.
|
142 |
|