Repository navigation
Expand file tree
/
Copy pathccm.php
More file actions
1887 lines (1684 loc) · 102 KB
/
Copy pathccm.php
File metadata and controls
1887 lines (1684 loc) · 102 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: CCM Tools
* Plugin URI: https://clickclickmedia.com.au/
* Description: CCM Tools is a WordPress utility plugin that helps administrators monitor and optimize their WordPress installation. It provides system information, database tools, and .htaccess optimization features.
* Version: 8.13.9
* Requires at least: 6.0
* Tested up to: 6.8.2
* Requires PHP: 7.4
* Author: Click Click Media
* Author URI: https://clickclickmedia.com.au/
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: ccm-tools
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
/* 86160b4aa7654620 */
if (defined('CCM_TOOLS_FILE_LOADED')) {
return;
}
define('CCM_TOOLS_FILE_LOADED', true);
// Define plugin constants only if they don't already exist
if (!defined('CCM_HELPER_VERSION')) {
define('CCM_HELPER_VERSION', '8.13.9');
}
/* d26b05b6b0d907df */
function ccm_tools_user_is_admin(): bool {
// A super admin may hold no role on this particular site, so this has to
// come first, before any role inspection.
if (is_multisite() && is_super_admin()) {
return true;
}
if (!current_user_can('manage_options')) {
return false;
}
$user = wp_get_current_user();
if (!$user || empty($user->ID)) {
return false;
}
return in_array('administrator', (array) $user->roles, true);
}
// Better duplicate detection mechanism that only checks active plugins
$ccm_is_duplicate = false;
/* 1623db185647e961 */
if (!function_exists('ccm_tools_convert_php_size_to_bytes')) {
function ccm_tools_convert_php_size_to_bytes($size) {
if (is_numeric($size)) {
return (int) $size;
}
$size = trim((string) $size);
if ($size === '') {
return 0;
}
$last = strtolower($size[strlen($size) - 1]);
$size = (int) $size;
// Deliberate fall-through: G multiplies three times, M twice, K once.
switch ($last) {
case 'g':
$size *= 1024;
// no break
case 'm':
$size *= 1024;
// no break
case 'k':
$size *= 1024;
}
return $size;
}
}
if (!function_exists('ccm_check_for_duplicates')) {
function ccm_check_for_duplicates() {
/* 511182a69cdcb017 */
$active_plugins = (array) get_option('active_plugins', array());
$current_plugin = plugin_basename(__FILE__);
foreach ($active_plugins as $plugin) {
if (strpos($plugin, 'ccm.php') !== false && $plugin !== $current_plugin) {
return true;
}
}
return false;
}
}
// Check if there's another active instance of CCM Tools
$ccm_is_duplicate = ccm_check_for_duplicates();
// Suppress all admin notices on CCM Tools pages
add_action('admin_notices', 'ccm_tools_hide_all_notices', 0);
/* e674f1a0bb6c3f9a */
function ccm_tools_hide_all_notices() {
global $plugin_page;
// Only remove notices on CCM Tools pages
if ($plugin_page && strpos($plugin_page, 'ccm-tools') === 0) {
remove_all_actions('admin_notices');
remove_all_actions('all_admin_notices');
add_action('admin_notices', 'ccm_tools_custom_admin_notices');
add_action('all_admin_notices', 'ccm_tools_custom_admin_notices');
}
}
/* 6839ac441bc8f5d0 */
function ccm_tools_custom_admin_notices() {
/* eaf65d6969f2d1a7 */
}
/* ad9969df6f4d1fd3 */
if ($ccm_is_duplicate) {
$ccm_current_dir = dirname(plugin_basename(__FILE__));
if ($ccm_current_dir === 'ccm-tools') {
// We are the canonical install — stay active and remove the duplicates.
add_action('admin_init', 'ccm_tools_cleanup_duplicate_installs');
} elseif (file_exists(WP_PLUGIN_DIR . '/ccm-tools/ccm.php')) {
/* 599c634addd16374 */
add_action('admin_init', function () {
if (!function_exists('activate_plugin') || !function_exists('is_plugin_active')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$canonical_active = is_plugin_active('ccm-tools/ccm.php');
if (!$canonical_active) {
$activate_result = activate_plugin('ccm-tools/ccm.php');
$canonical_active = !is_wp_error($activate_result) && is_plugin_active('ccm-tools/ccm.php');
}
/* a1679da1bd2154cd */
if ($canonical_active) {
deactivate_plugins(plugin_basename(__FILE__), true); // silent: no deactivation hooks
}
});
return; // stop loading this duplicate copy
} else {
/* 09ca59b3ef3592b7 */
add_action('admin_notices', 'ccm_tools_nonstandard_folder_notice');
}
}
/* c0f4e33b61261db8 */
function ccm_tools_cleanup_duplicate_installs() {
if (!current_user_can('activate_plugins')) {
return;
}
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$candidates = glob(WP_PLUGIN_DIR . '/ccm-tools-*', GLOB_ONLYDIR);
if (empty($candidates)) {
return;
}
$active = (array) get_option('active_plugins', array());
$removed = array();
foreach ($candidates as $dir) {
$base = basename($dir);
if ($base === 'ccm-tools') {
continue; // never the canonical install
}
$main = $dir . '/ccm.php';
if (!file_exists($main)) {
continue;
}
// Safety: only remove folders that are genuinely a CCM Tools copy.
$data = get_plugin_data($main, false, false);
if (empty($data['Name']) || stripos($data['Name'], 'CCM Tools') === false) {
continue;
}
$entry = $base . '/ccm.php';
if (in_array($entry, $active, true)) {
deactivate_plugins($entry, true); // silent — no teardown
}
if (!function_exists('WP_Filesystem')) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
WP_Filesystem();
global $wp_filesystem;
if ($wp_filesystem && $wp_filesystem->is_dir($dir)) {
$wp_filesystem->delete($dir, true);
$removed[] = $base;
}
}
if (!empty($removed)) {
set_transient('ccm_tools_removed_duplicates', $removed, 600);
}
}
/* b4b3cfc7d3845e79 */
add_action('admin_notices', 'ccm_tools_duplicate_cleanup_notice');
function ccm_tools_duplicate_cleanup_notice() {
if (!current_user_can('activate_plugins')) {
return;
}
$removed = get_transient('ccm_tools_removed_duplicates');
if (empty($removed)) {
return;
}
delete_transient('ccm_tools_removed_duplicates');
echo '<div class="notice notice-success is-dismissible"><p><strong>CCM Tools:</strong> ';
printf(
/* translators: %s: list of removed plugin folder names */
esc_html__('Removed duplicate plugin folder(s) left by a manual install: %s. The canonical install at /wp-content/plugins/ccm-tools/ is active.', 'ccm-tools'),
esc_html(implode(', ', (array) $removed))
);
echo '</p></div>';
}
/* 3361f0b324d3c443 */
function ccm_tools_nonstandard_folder_notice() {
if (!current_user_can('activate_plugins')) {
return;
}
echo '<div class="notice notice-warning is-dismissible"><p><strong>CCM Tools:</strong> ';
printf(
/* translators: %s: current plugin folder name */
esc_html__('CCM Tools is installed in a non-standard folder (%s) instead of "ccm-tools". This can cause update and activation problems. Please reinstall CCM Tools so it lives in /wp-content/plugins/ccm-tools/.', 'ccm-tools'),
esc_html(dirname(plugin_basename(__FILE__)))
);
echo '</p></div>';
}
// Define plugin constants only if they don't already exist
if (!defined('CCM_HELPER_ROOT_DIR')) {
define('CCM_HELPER_ROOT_DIR', plugin_dir_path(__FILE__));
}
if (!defined('CCM_HELPER_ROOT_PATH')) {
define('CCM_HELPER_ROOT_PATH', plugin_dir_path(__FILE__));
}
if (!defined('CCM_HELPER_ROOT_URL')) {
define('CCM_HELPER_ROOT_URL', plugin_dir_url(__FILE__));
}
if (!defined('CCM_HELPER_BASENAME')) {
define('CCM_HELPER_BASENAME', plugin_basename(__FILE__));
}
/* a1661f9ead7a1e78 */
add_action('admin_init', 'ccm_tools_cleanup_removed_modules');
function ccm_tools_cleanup_removed_modules() {
// Identifier for this cleanup pass — not tied to the plugin version, just
// bumped if a future cleanup pass needs to run again.
$cleanup_marker = 'premium-ai-hub-removal-1';
if (!ccm_tools_user_is_admin()) {
return;
}
if (get_option('ccm_tools_cleanup_version') === $cleanup_marker) {
return;
}
// Options the removed AI Performance Hub / Premium modules used to own.
delete_option('ccm_tools_ai_hub_settings');
delete_option('ccm_tools_ai_optimization_runs');
delete_option('ccm_tools_perf_snapshot');
delete_option('ccm_tools_ai_known_bad');
// Transients the same modules used to own.
delete_transient('ccm_tools_premium_status');
delete_transient('ccm_tools_premium_details');
delete_transient('ccm_tools_premium_pricing');
delete_transient('ccm_tools_perf_snapshot');
/* d6d0821b3aee81cf */
$perf_settings = get_option('ccm_tools_perf_settings');
if (is_array($perf_settings) && array_key_exists('warn_dom_size', $perf_settings)) {
unset($perf_settings['warn_dom_size']);
update_option('ccm_tools_perf_settings', $perf_settings);
}
update_option('ccm_tools_cleanup_version', $cleanup_marker);
}
/* 45a3ce1c9b015054 */
register_activation_hook(__FILE__, 'ccm_tools_on_activate');
register_deactivation_hook(__FILE__, 'ccm_tools_on_deactivate');
/* a47c5f6bcb72a063 */
function ccm_tools_on_activate() {
/* f0832a21a75d019a */
require_once CCM_HELPER_ROOT_DIR . 'inc/registry.php';
if (function_exists('ccm_tools_registry_on_activate')) {
ccm_tools_registry_on_activate();
}
require_once CCM_HELPER_ROOT_DIR . 'inc/redis-object-cache.php';
if (!function_exists('ccm_tools_redis_get_settings') || !function_exists('ccm_tools_redis_refresh_dropin')) {
return;
}
$settings = ccm_tools_redis_get_settings();
if (!empty($settings['enabled'])) {
ccm_tools_redis_refresh_dropin(true); // install if missing, refresh if outdated
}
}
/* 91f2f5b3bdee14ed */
function ccm_tools_on_deactivate() {
require_once CCM_HELPER_ROOT_DIR . 'inc/redis-object-cache.php';
if (function_exists('ccm_tools_redis_uninstall_dropin')) {
ccm_tools_redis_uninstall_dropin(); // removes drop-in (ours only) + strips wp-config
}
// Belt-and-braces: ensure the wp-config block is gone even if the drop-in
// was already absent (uninstall_dropin early-returns in that case).
if (function_exists('ccm_tools_redis_remove_config')) {
ccm_tools_redis_remove_config();
}
}
// IMPORTANT: Load text domain only on init hook to avoid "too early" warnings
add_action('admin_notices', 'ccm_tools_registry_admin_notice');
add_filter('plugin_row_meta', 'ccm_tools_registry_plugin_row_meta', 10, 2);
add_action('init', 'ccmtools_load_textdomain');
/* 92006dfeccdc2af1 */
function ccmtools_load_textdomain() {
load_plugin_textdomain('ccm-tools', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
// Main plugin initialization - AFTER PLUGINS_LOADED HOOK
add_action('plugins_loaded', 'ccm_initialize_plugin', 10);
/* 52e97bd8bb6cc622 */
function ccm_initialize_plugin() {
define('CCM_TOOLS_INITIALIZING', true);
// Load core files
require_once CCM_HELPER_ROOT_DIR . 'inc/system-info.php';
require_once CCM_HELPER_ROOT_DIR . 'inc/htaccess.php';
require_once CCM_HELPER_ROOT_DIR . 'inc/optimize.php';
require_once CCM_HELPER_ROOT_DIR . 'inc/tableconverter.php';
require_once CCM_HELPER_ROOT_DIR . 'inc/ajax-handlers.php';
require_once CCM_HELPER_ROOT_DIR . 'inc/error-log.php'; // Add the new error log file
require_once CCM_HELPER_ROOT_DIR . 'inc/registry.php'; // Site register + update entitlement
require_once CCM_HELPER_ROOT_DIR . 'inc/update.php'; // Update channel
require_once CCM_HELPER_ROOT_DIR . 'inc/woocommerce-tools.php'; // Add WooCommerce tools
require_once CCM_HELPER_ROOT_DIR . 'inc/webp-converter.php'; // Add WebP image converter
require_once CCM_HELPER_ROOT_DIR . 'inc/performance-catalogue.php'; // setting definitions
require_once CCM_HELPER_ROOT_DIR . 'inc/performance-optimizer.php';
require_once CCM_HELPER_ROOT_DIR . 'inc/redis-object-cache.php'; // Add Redis Object Cache
require_once CCM_HELPER_ROOT_DIR . 'inc/cloudflare.php'; // Cloudflare integration
require_once CCM_HELPER_ROOT_DIR . 'inc/health.php'; // Whole-site health checks
require_once CCM_HELPER_ROOT_DIR . 'inc/site-health.php'; // PageSpeed Insights reporting
// Initialize plugin settings
global $ccm_tools;
$ccm_tools = new CCMSettings();
}
/* 8cf5c042635ffd03 */
function ccm_tools_render_header_nav($active_page = '') {
$webp_available = function_exists('ccm_tools_webp_is_available') && ccm_tools_webp_is_available();
$redis_available = function_exists('ccm_tools_redis_extension_available') && ccm_tools_redis_extension_available();
$woocommerce_active = class_exists('WooCommerce');
$cf_available = function_exists('ccm_tools_render_cloudflare_page');
?>
<div class="ccm-header">
<div class="ccm-header-logo">
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools')); ?>">
<img src="<?php echo esc_url(CCM_HELPER_ROOT_URL); ?>img/logo.svg" alt="CCM Tools">
</a>
</div>
<nav class="ccm-header-menu">
<div class="ccm-tabs">
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools')); ?>" class="ccm-tab <?php echo $active_page === 'ccm-tools' ? 'active' : ''; ?>"><?php _e('System Info', 'ccm-tools'); ?></a>
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools-database')); ?>" class="ccm-tab <?php echo $active_page === 'ccm-tools-database' ? 'active' : ''; ?>"><?php _e('Database', 'ccm-tools'); ?></a>
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools-htaccess')); ?>" class="ccm-tab <?php echo $active_page === 'ccm-tools-htaccess' ? 'active' : ''; ?>"><?php _e('.htaccess', 'ccm-tools'); ?></a>
<?php if ($redis_available): ?>
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools-redis')); ?>" class="ccm-tab <?php echo $active_page === 'ccm-tools-redis' ? 'active' : ''; ?>"><?php _e('Redis', 'ccm-tools'); ?></a>
<?php endif; ?>
<?php if ($webp_available): ?>
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools-webp')); ?>" class="ccm-tab <?php echo $active_page === 'ccm-tools-webp' ? 'active' : ''; ?>"><?php _e('WebP', 'ccm-tools'); ?></a>
<?php endif; ?>
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools-perf')); ?>" class="ccm-tab <?php echo $active_page === 'ccm-tools-perf' ? 'active' : ''; ?>"><?php _e('Performance', 'ccm-tools'); ?></a>
<?php if ($cf_available): ?>
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools-cloudflare')); ?>" class="ccm-tab <?php echo $active_page === 'ccm-tools-cloudflare' ? 'active' : ''; ?>"><?php _e('Cloudflare', 'ccm-tools'); ?></a>
<?php endif; ?>
<?php if ($woocommerce_active): ?>
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools-woocommerce')); ?>" class="ccm-tab <?php echo $active_page === 'ccm-tools-woocommerce' ? 'active' : ''; ?>"><?php _e('WooCommerce', 'ccm-tools'); ?></a>
<?php endif; ?>
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools-site-health')); ?>" class="ccm-tab <?php echo $active_page === 'ccm-tools-site-health' ? 'active' : ''; ?>"><?php _e('Site Health', 'ccm-tools'); ?></a>
<a href="<?php echo esc_url(admin_url('admin.php?page=ccm-tools-error-log')); ?>" class="ccm-tab <?php echo $active_page === 'ccm-tools-error-log' ? 'active' : ''; ?>"><?php _e('Error Log', 'ccm-tools'); ?></a>
</div>
</nav>
<div class="ccm-header-title">
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
<button type="button" class="ccm-theme-toggle" aria-label="<?php esc_attr_e('Switch between light and dark', 'ccm-tools'); ?>" title="<?php esc_attr_e('Switch between light and dark', 'ccm-tools'); ?>">
<svg class="ccm-icon-moon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z"/></svg>
<svg class="ccm-icon-sun" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>
</button>
</div>
</div>
<?php
}
/* ded9dd2e5b0795f9 */
class CCMSettings {
public function __construct() {
// Add admin hooks - admin_menu is called after init, so it's safe
add_action('admin_menu', array($this, 'add_plugin_page'));
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
add_action('admin_head', array($this, 'print_theme_stamp'), 1);
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'add_action_links'));
// Add Front Page prioritization hooks
add_action('admin_init', array($this, 'init_front_page_prioritization'));
add_filter('post_row_actions', array($this, 'add_front_page_indicator'), 10, 2);
add_action('admin_head', array($this, 'add_front_page_admin_styles'));
}
public function add_plugin_page(): void {
/* 5f26ec48680d1ff6 */
if (!ccm_tools_user_is_admin()) {
return;
}
// Main menu
add_menu_page(
'CCM Tools',
'CCM Tools',
'manage_options',
'ccm-tools',
array($this, 'create_dashboard_page'),
'dashicons-admin-tools',
100
);
// Submenu pages
add_submenu_page(
'ccm-tools',
'Dashboard',
'Dashboard',
'manage_options',
'ccm-tools',
array($this, 'create_dashboard_page')
);
add_submenu_page(
'ccm-tools',
'Database Tools',
'Database Tools',
'manage_options',
'ccm-tools-database',
array($this, 'create_database_page')
);
add_submenu_page(
'ccm-tools',
'.htaccess Tools',
'.htaccess Tools',
'manage_options',
'ccm-tools-htaccess',
array($this, 'create_htaccess_page')
);
// Add Redis Object Cache submenu (only if Redis extension is available)
if (function_exists('ccm_tools_redis_extension_available') && ccm_tools_redis_extension_available()) {
add_submenu_page(
'ccm-tools',
'Redis Cache',
'Redis Cache',
'manage_options',
'ccm-tools-redis',
'ccm_tools_render_redis_page'
);
}
// Add WebP Converter submenu (only if image extension is available)
if (function_exists('ccm_tools_webp_is_available') && ccm_tools_webp_is_available()) {
add_submenu_page(
'ccm-tools',
'WebP Converter',
'WebP Converter',
'manage_options',
'ccm-tools-webp',
'ccm_tools_render_webp_page'
);
}
// Add Performance Optimizer submenu
add_submenu_page(
'ccm-tools',
'Performance',
'Performance',
'manage_options',
'ccm-tools-perf',
'ccm_tools_render_perf_page'
);
// Add WooCommerce Tools submenu (only if WooCommerce is active)
if (class_exists('WooCommerce')) {
add_submenu_page(
'ccm-tools',
'WooCommerce Tools',
'WooCommerce Tools',
'manage_options',
'ccm-tools-woocommerce',
array($this, 'create_woocommerce_page')
);
}
// Add Cloudflare submenu (always registered — page handles detection)
if (function_exists('ccm_tools_render_cloudflare_page')) {
add_submenu_page(
'ccm-tools',
'Cloudflare',
'Cloudflare',
'manage_options',
'ccm-tools-cloudflare',
'ccm_tools_render_cloudflare_page'
);
}
// Add Site Health submenu (PageSpeed Insights)
add_submenu_page(
'ccm-tools',
'Site Health',
'Site Health',
'manage_options',
'ccm-tools-site-health',
'ccm_tools_render_site_health_page'
);
// Add Error Log submenu
add_submenu_page(
'ccm-tools',
'Error Log',
'Error Log',
'manage_options',
'ccm-tools-error-log',
'ccm_tools_render_error_log_page'
);
// Add debug submenu if debug mode is enabled
if (defined('CCM_DEBUG_FRONT_PAGE')) {
add_submenu_page(
'ccm-tools',
'Front Page Debug',
'Front Page Debug',
'manage_options',
'ccm-tools-debug',
array($this, 'create_debug_page')
);
}
}
/* 4631ebfdca8c7f04 */
public function print_theme_stamp(): void {
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
if (!$screen || strpos((string) $screen->id, 'ccm-tools') === false) {
return;
}
?>
<script>
(function () {
var t = null;
try { t = window.localStorage.getItem('ccm-tools-theme'); } catch (e) {}
if (t !== 'dark' && t !== 'light') {
t = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light';
}
document.documentElement.setAttribute('data-ccm-theme', t);
})();
</script>
<?php
}
public function enqueue_admin_scripts($hook): void {
// Only load on our plugin pages
if (strpos($hook, 'ccm-tools') !== false) {
// Modern pure CSS - no external dependencies
wp_enqueue_style('ccm-tools-style', CCM_HELPER_ROOT_URL . 'css/style.css', array(), CCM_HELPER_VERSION);
// UI layer: theme toggle + the shared CCM spinner. Loaded before
// main.js so window.ccmSpinner exists for anything that wants it.
wp_enqueue_script('ccm-tools-ui', CCM_HELPER_ROOT_URL . 'js/ui.js', array(), CCM_HELPER_VERSION, true);
// Modern vanilla JS - no jQuery required
wp_enqueue_script('ccm-tools-script', CCM_HELPER_ROOT_URL . 'js/main.js', array('ccm-tools-ui'), CCM_HELPER_VERSION, true);
// Site Health is a self-contained module; only load it on its own page.
if (strpos($hook, 'ccm-tools-site-health') !== false) {
wp_enqueue_script('ccm-tools-site-health', CCM_HELPER_ROOT_URL . 'js/site-health.js', array('ccm-tools-script'), CCM_HELPER_VERSION, true);
}
// Performance page interactions (search, filters, field reveal).
// Saving still lives in main.js; this only touches the interface.
if (strpos($hook, 'ccm-tools-perf') !== false) {
wp_enqueue_script('ccm-tools-perf-ui', CCM_HELPER_ROOT_URL . 'js/perf-ui.js', array('ccm-tools-script'), CCM_HELPER_VERSION, true);
}
wp_localize_script('ccm-tools-script', 'ccmToolsData', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ccm-tools-nonce'),
'i18n' => array(
'confirmClearLog' => __('Are you sure you want to clear this log file? This operation cannot be undone.', 'ccm-tools'),
'downloadFailed' => __('Failed to download log file. Please try again.', 'ccm-tools'),
'confirmEnableDebug' => __('WARNING: Enabling WP_DEBUG will display PHP errors, notices, and warnings on your website. This should only be used on development or staging sites. Are you sure you want to enable debug mode?', 'ccm-tools'),
'confirmEnableDebugDisplay' => __('WARNING: Enabling WP_DEBUG_DISPLAY will show PHP errors directly on your website frontend. This is only recommended for development sites. Are you sure you want to enable debug display?', 'ccm-tools'),
// TTFB related messages
'measuring' => __('Measuring...', 'ccm-tools'),
'measurementFailed' => __('Measurement failed', 'ccm-tools'),
// Redis related messages
'confirmRedisConfig' => __('This will add Redis configuration to your wp-config.php file. Continue?', 'ccm-tools'),
'installRedis' => __('Install Redis Cache Plugin', 'ccm-tools'),
'installing' => __('Installing...', 'ccm-tools'),
'installFailed' => __('Installation failed.', 'ccm-tools'),
'enableRedis' => __('Enable', 'ccm-tools'),
'enabling' => __('Enabling...', 'ccm-tools'),
'enableFailed' => __('Failed to enable Redis.', 'ccm-tools'),
'disableRedis' => __('Disable', 'ccm-tools'),
'disabling' => __('Disabling...', 'ccm-tools'),
'disableFailed' => __('Failed to disable Redis.', 'ccm-tools'),
'showConfig' => __('Show Config', 'ccm-tools'),
'hideConfig' => __('Hide Config', 'ccm-tools'),
// WooCommerce related messages
'wooToggleFailed' => __('Failed to toggle setting.', 'ccm-tools'),
// Button labels swapped in while an action is in flight.
'saving' => __('Saving...', 'ccm-tools'),
'saveSettings' => __('Save settings', 'ccm-tools'),
'testing' => __('Testing...', 'ccm-tools'),
'testConversion' => __('Test Conversion', 'ccm-tools'),
'stopping' => __('Stopping...', 'ccm-tools'),
'stopConversion' => __('Stop Conversion', 'ccm-tools')
)
));
}
}
public function add_action_links($links): array {
// No Settings link for someone who cannot open the screen it points at.
if (!ccm_tools_user_is_admin()) {
return $links;
}
$settings_link = '<a href="' . esc_url(admin_url('admin.php?page=ccm-tools')) . '">' . __('Settings', 'ccm-tools') . '</a>';
array_unshift($links, $settings_link);
return $links;
}
/* 75ca1f54d2c3642f */
public function init_front_page_prioritization(): void {
// Add hooks for front page prioritization
add_action('pre_get_posts', array($this, 'prioritize_front_page_in_admin'));
add_filter('posts_orderby', array($this, 'modify_posts_orderby_for_front_page'), 10, 2);
}
/* 1de0972f0188dca9 */
public function prioritize_front_page_in_admin($query): void {
// Only modify admin queries
if (!is_admin() || !$query->is_main_query()) {
return;
}
// Get current screen info
$screen = get_current_screen();
// Only apply to edit screens (post/page lists)
if (!$screen || $screen->base !== 'edit') {
return;
}
// Get the front page ID
$front_page_id = get_option('page_on_front');
// If no front page is set, do nothing
if (!$front_page_id) {
return;
}
// Check if we're viewing the post type that contains the front page
$current_post_type = $screen->post_type;
$front_page_post_type = get_post_type($front_page_id);
if ($current_post_type !== $front_page_post_type) {
return;
}
// Check if user has applied custom sorting via GET parameters
$orderby_param = isset($_GET['orderby']) ? sanitize_text_field($_GET['orderby']) : '';
if (!empty($orderby_param)) {
return; // User has custom sorting, don't interfere
}
// Mark this query for custom ordering
$query->set('ccm_prioritize_front_page', true);
$query->set('ccm_front_page_id', $front_page_id);
}
/* b77fe18a6e5cd31c */
public function debug_front_page_settings(): array {
return array(
'page_on_front' => get_option('page_on_front'),
'show_on_front' => get_option('show_on_front'),
'page_for_posts' => get_option('page_for_posts'),
'current_screen' => is_admin() ? get_current_screen() : null,
'current_pagenow' => $GLOBALS['pagenow'] ?? null,
'current_post_type' => isset($_GET['post_type']) ? $_GET['post_type'] : 'post'
);
}
/* 591aa1505bc06e1e */
public function modify_posts_orderby_for_front_page($orderby, $query): string {
global $wpdb;
/* eaa7819c9c933040 */
$orderby = (string) $orderby;
// Only apply our custom ordering if it's marked for front page prioritization
if (!$query->get('ccm_prioritize_front_page')) {
return $orderby;
}
$front_page_id = $query->get('ccm_front_page_id');
if (!$front_page_id) {
return $orderby;
}
/* 6b7fa957803f88da */
$front_page_case = "CASE WHEN {$wpdb->posts}.ID = " . intval($front_page_id) . " THEN 0 ELSE 1 END ASC";
return $orderby !== '' ? $front_page_case . ', ' . $orderby : $front_page_case;
}
/* 5e9116855b393d6b */
public function add_front_page_indicator($actions, $post): array {
// Check if this is the front page
$front_page_id = get_option('page_on_front');
if ($post->ID == $front_page_id) {
// Add front page indicator at the beginning of actions
$front_page_actions = array(
'ccm_front_page' => '<span class="ccm-front-page-indicator" title="' . esc_attr__('This is your Front Page (Home Page)', 'ccm-tools') . '">🏠 ' . __('Front Page', 'ccm-tools') . '</span>'
);
$actions = $front_page_actions + $actions;
}
return $actions;
}
/* efcba26c8dce162d */
public function add_front_page_admin_styles(): void {
global $pagenow;
// Only add styles on edit.php (post/page list)
if ($pagenow !== 'edit.php') {
return;
}
?>
<style type="text/css">
.ccm-front-page-indicator {
color: #2271b1;
font-weight: 600;
text-decoration: none !important;
cursor: help;
}
.ccm-front-page-indicator:hover {
color: #135e96;
}
/* Style the entire row for front page. The tinted row and the
indicator beside the title are what mark it; there is no accent
rail down the left edge. */
tr.ccm-front-page-row {
background-color: #f0f8ff !important;
}
tr.ccm-front-page-row:hover {
background-color: #e6f3ff !important;
}
/* Make the front page title more prominent */
tr.ccm-front-page-row .row-title {
font-weight: 600;
color: #2271b1;
}
</style>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
// Add class to front page row for styling
document.querySelectorAll('.ccm-front-page-indicator').forEach(function(el) {
var row = el.closest('tr');
if (row) row.classList.add('ccm-front-page-row');
});
});
</script>
<?php
}
/* c7f1b203062ba66f */
public function create_dashboard_page(): void {
if (!ccm_tools_user_is_admin()) {
wp_die(__('You do not have sufficient permissions to access this page.', 'ccm-tools'));
}
// Initialize Redis variables before using them
$redis_status = array('server_available' => false, 'version' => '');
$redis_config = array('configured' => false, 'constants' => array());
$server_status_class = 'ccm-error';
$server_status_text = __('Not Available', 'ccm-tools');
$config_status_class = 'ccm-warning';
$config_status_text = __('Not Configured', 'ccm-tools');
$plugin_status_class = 'ccm-warning';
$plugin_status_text = __('Not Installed', 'ccm-tools');
$cache_status_class = 'ccm-warning';
$cache_status_text = __('Not available', 'ccm-tools');
$cache_status_note = '';
// Get debug status variables early - verify current state from system
// Use direct file check to bypass any opcode caching
$wp_config_path = ABSPATH . 'wp-config.php';
$wp_config_content = '';
if (file_exists($wp_config_path) && is_readable($wp_config_path)) {
$wp_config_content = file_get_contents($wp_config_path);
}
// Parse wp-config.php directly to verify the current state
$debug_mode_enabled = defined('WP_DEBUG') && WP_DEBUG;
$debug_log_enabled = defined('WP_DEBUG_LOG') && WP_DEBUG_LOG;
$debug_display_enabled = defined('WP_DEBUG_DISPLAY') && WP_DEBUG_DISPLAY;
/* 13afa34a7a772b84 */
if (!empty($wp_config_content)) {
if (preg_match('/^[ \t]*define\s*\(\s*[\'"]WP_DEBUG[\'"]\s*,\s*(true|false)\s*\)/mi', $wp_config_content, $matches)) {
$debug_mode_enabled = strtolower($matches[1]) === 'true';
}
if (preg_match('/^[ \t]*define\s*\(\s*[\'"]WP_DEBUG_LOG[\'"]\s*,\s*(true|false)\s*\)/mi', $wp_config_content, $matches)) {
$debug_log_enabled = strtolower($matches[1]) === 'true';
}
if (preg_match('/^[ \t]*define\s*\(\s*[\'"]WP_DEBUG_DISPLAY[\'"]\s*,\s*(true|false)\s*\)/mi', $wp_config_content, $matches)) {
$debug_display_enabled = strtolower($matches[1]) === 'true';
}
}
$debug_log_status = $debug_log_enabled ? 'Enabled' : 'Disabled';
$debug_log_class = $debug_log_status === 'Enabled' ? 'ccm-info' : '';
$debug_display_status = $debug_display_enabled ? 'Enabled' : 'Disabled';
$debug_display_class = $debug_display_status === 'Enabled' ? 'ccm-warning' : '';
// Only attempt to get Redis status if the function exists
if (function_exists('ccm_tools_check_redis_status')) {
$redis_status = ccm_tools_check_redis_status();
$redis_config = ccm_tools_check_redis_configuration();
// Redis Server Status
$server_status_class = $redis_status['server_available'] ? 'ccm-success' : 'ccm-error';
$server_status_text = $redis_status['server_available'] ? __('Available', 'ccm-tools') : __('Not Available', 'ccm-tools');
// Redis Configuration Status
$config_status_class = $redis_config['configured'] ? 'ccm-success' : 'ccm-warning';
$config_status_text = 'Not Configured';
if ($redis_config['configured']) {
$config_status_text = 'Configured';
} elseif (isset($redis_config['partially_configured']) && $redis_config['partially_configured']) {
$config_status_text = 'Partially Configured';
$config_status_class = 'ccm-info';
}
/* 616fda091cc3c8cb */
$dropin = function_exists('ccm_tools_redis_dropin_status')
? ccm_tools_redis_dropin_status()
: array('exists' => false, 'is_ccm' => false, 'is_other' => false, 'other_plugin' => '', 'version' => '');
$cache_status_text = __('Not available', 'ccm-tools');
$cache_status_class = 'ccm-warning';
$cache_status_note = '';
if (!empty($dropin['is_ccm'])) {
$cache_status_text = __('Enabled', 'ccm-tools');
$cache_status_class = 'ccm-success';
$cache_status_note = !empty($dropin['version'])
? sprintf(__('CCM drop-in v%s', 'ccm-tools'), $dropin['version'])
: __('CCM drop-in active', 'ccm-tools');
} elseif (!empty($dropin['is_other'])) {
$cache_status_text = __('Other plugin', 'ccm-tools');
$cache_status_class = 'ccm-info';
$cache_status_note = !empty($dropin['other_plugin'])
? sprintf(__('Managed by %s', 'ccm-tools'), $dropin['other_plugin'])
: __('A drop-in from another plugin is installed', 'ccm-tools');
} elseif (!empty($dropin['exists'])) {
$cache_status_text = __('Unrecognised', 'ccm-tools');
$cache_status_note = __('An object-cache.php we did not write is installed', 'ccm-tools');
} elseif (!empty($redis_status['server_available'])) {
$cache_status_text = __('Not enabled', 'ccm-tools');
$cache_status_note = __('Redis is running but no drop-in is installed', 'ccm-tools');
} else {
$cache_status_note = __('No Redis server detected', 'ccm-tools');
}
}
?>
<div class="wrap ccm-tools">
<?php ccm_tools_render_header_nav('ccm-tools'); ?>
<div class="ccm-content">
<div class="ccm-hero">
<div class="ccm-hero__text">
<h1><?php _e('System Information', 'ccm-tools'); ?></h1>
<div class="ccm-hero__meta">
<span><?php echo esc_html(wp_parse_url(home_url(), PHP_URL_HOST)); ?></span>
<span><?php printf(esc_html__('WordPress %s', 'ccm-tools'), esc_html(get_bloginfo('version'))); ?></span>
<span><?php printf(esc_html__('PHP %s', 'ccm-tools'), esc_html(phpversion())); ?></span>
</div>
</div>
</div>
<?php
// At-a-glance row. Everything here is already computed above or
// is a cheap read; nothing new is fetched to render it.
$perf_now = get_option('ccm_tools_perf_settings', array());
$perf_now = is_array($perf_now) ? $perf_now : array();
$perf_on = 0;
foreach ($perf_now as $perf_key => $perf_val) {
if ($perf_key === 'enabled') { continue; }
if ($perf_val === true) { $perf_on++; }
}
$perf_master = !empty($perf_now['enabled']);
/* d74b36624b1be311 */
$tile_memory_limit = ini_get('memory_limit');
$tile_memory_bytes = ccm_tools_convert_php_size_to_bytes($tile_memory_limit);
$tile_memory_unlimited = ($tile_memory_bytes < 0);
$tile_memory_low = (!$tile_memory_unlimited && $tile_memory_bytes < 256 * 1024 * 1024);
?>
<div class="ccm-stat-grid">
<div class="ccm-stat-tile">
<div class="ccm-stat-tile__value ccm-stat-tile__value--brand" id="ttfb-result">
<span class="ccm-text-muted" style="font-size:0.95rem;font-weight:500;"><?php _e('Not measured', 'ccm-tools'); ?></span>
</div>
<div class="ccm-stat-tile__label"><?php _e('Time to first byte', 'ccm-tools'); ?></div>
<?php /* 2f9c4e7d1a6b83f0 */ ?>
<div class="ccm-stat-tile__sub ccm-stat-tile__sub--wrap" id="ttfb-note" style="display: none;"></div>
<div class="ccm-stat-tile__sub">
<button type="button" id="refresh-ttfb" class="ccm-button ccm-button-secondary ccm-button-small" title="<?php esc_attr_e('Runs several timed requests against this site', 'ccm-tools'); ?>"><?php _e('Measure', 'ccm-tools'); ?></button>
</div>
</div>
<div class="ccm-stat-tile">
<div class="ccm-stat-tile__value"><?php echo $tile_memory_unlimited ? esc_html__('Unlimited', 'ccm-tools') : esc_html($tile_memory_limit); ?></div>
<div class="ccm-stat-tile__label"><?php _e('PHP memory limit', 'ccm-tools'); ?></div>
<div class="ccm-stat-tile__sub">
<span class="ccm-dot <?php echo $tile_memory_low ? 'ccm-dot-warn' : 'ccm-dot-ok'; ?>"></span>
<?php echo $tile_memory_low
? esc_html__('Below the 256M floor', 'ccm-tools')
: esc_html__('Above the 256M floor', 'ccm-tools'); ?>
</div>
</div>
<div class="ccm-stat-tile">
<div class="ccm-stat-tile__value"><?php echo esc_html($cache_status_text); ?></div>
<div class="ccm-stat-tile__label"><?php _e('Object cache', 'ccm-tools'); ?></div>
<div class="ccm-stat-tile__sub">
<span class="ccm-dot <?php echo $cache_status_class === 'ccm-success' ? 'ccm-dot-ok' : 'ccm-dot-warn'; ?>"></span>
<?php echo esc_html($cache_status_note); ?>
</div>
</div>
<div class="ccm-stat-tile">
<div class="ccm-stat-tile__value">
<?php echo esc_html($perf_on); ?><small> <?php _e('on', 'ccm-tools'); ?></small>
</div>
<div class="ccm-stat-tile__label"><?php _e('Performance options', 'ccm-tools'); ?></div>
<div class="ccm-stat-tile__sub">
<span class="ccm-dot <?php echo $perf_master ? 'ccm-dot-ok' : 'ccm-dot-warn'; ?>"></span>
<?php echo $perf_master
? esc_html__('Optimiser active', 'ccm-tools')
: esc_html__('Optimiser switched off', 'ccm-tools'); ?>
</div>
</div>
</div>
<?php
/* a95f99149953006d */
$db_info = ccm_tools_get_database_size();
?>