PluginProbe
atec Cache APCu / 2.3.75
atec Cache APCu v2.3.75
2.3.77 2.1.51 2.1.52 2.1.53 2.1.55 2.1.56 2.1.57 2.1.58 2.1.59 2.1.60 2.1.61 2.1.62 2.1.63 2.1.65 2.1.66 2.1.67 2.1.68 2.1.72 2.1.79 2.1.8 2.1.80 2.1.81 2.1.82 2.1.83 2.1.84 All 105 releases
atec-cache-apcu / atec-cache-apcu.php

atec-cache-apcu.php in atec Cache APCu 2.3.75, at atec-cache-apcu.php

158 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: atec Cache APCu
4 * Plugin URI: https://atecplugins.com/
5 * Description: Super fast APCu-Object-Cache and the only APCu based page-cache plugin available.
6 * Version: 2.3.75
7 * Requires at least: 4.9
8 * Tested up to: 6.9
9 * Tested up to PHP: 8.4.12
10 * Requires PHP: 7.4
11 * Requires CP: 1.7
12 * Premium URI: https://atecplugins.com
13 * Author: Chris Ahrweiler �
14 atecplugins.com
15 * Author URI: https://atec-systems.com/
16 * License: GPL2
17 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
18 * Text Domain: atec-cache-apcu
19 */
20 namespace ATEC;
21
22 defined('ABSPATH') || exit;
23 defined('ATEC_LOADER') || require __DIR__ . '/includes/ATEC/LOADER.php';
24
25 use ATEC\INIT;
26 use ATEC\WPC;
27 use ATEC\WPCA;
28
29 INIT::set_version('wpca', '2.3.75');
30 if (INIT::is_real_admin())
31 {
32 INIT::register_activation_deactivation_hook(__FILE__, 1, 1, 'wpca');
33 add_action('admin_menu', fn() => INIT::menu(__DIR__, 'wpca', 'Cache APCu'));
34
35 add_action('admin_init', function ()
36 {
37 if (!INIT::current_user_can('admin')) return;
38
39 if (INIT::is_plugins_page()) INIT::add_plugin_settings(__FILE__);
40 INIT::maybe_register_settings(__DIR__, 'wpca', true, '&flushWPCA');
41
42 if (WPCA::apcu_enabled())
43 {
44 $o_admin = WPCA::settings('o_cache') && WPCA::settings('o_admin');
45 $p_admin = WPCA::settings('p_cache') && WPCA::settings('p_admin');
46
47 if ($o_admin || $p_admin)
48 {
49 add_action('admin_enqueue_scripts', function () { \ATEC\AJAX::generic_inline('wpca'); });
50 add_action('admin_bar_menu', function($wp_admin_bar) use($o_admin, $p_admin)
51 {
52 if ($o_admin) INIT::admin_bar_button($wp_admin_bar, 'wpca', '🗑️ OC', 'o_cache', 'Flush Oject Cache', 'oc');
53 if ($p_admin) INIT::admin_bar_button($wp_admin_bar, 'wpca', '🗑️ PC', 'p_cache', 'Flush Page Cache', 'pc');
54 }, 999);
55 }
56
57 if (WPCA::settings('o_rest'))
58 {
59 add_action('admin_enqueue_scripts', function ($hook) {
60 $rest_url = add_query_arg('rest_route', '/atec-wpca/v1/worker-probe', site_url('/') );
61 wp_localize_script('atec-wpca-workers', 'ATEC_WPCA_WORKERS', [ 'restUrl' => esc_url_raw($rest_url), 'nonce' => wp_create_nonce('wp_rest'), ]);
62 });
63 }
64 }
65 });
66
67 (function()
68 {
69
70 if (WPCA::apcu_enabled())
71 {
72 $p_cache = WPCA::settings('p_cache');
73 if ($p_cache)
74 {
75 require __DIR__.'/includes/atec-wpca-pcache-tools.php';
76
77 foreach (['after_switch_theme', 'wp_ajax_edit_theme_plugin_file', 'wp_update_nav_menu', 'wp_delete_nav_menu'] as $hook)
78 add_action($hook, function() { \ATEC_WPCA\Tools::delete_page_cache_all(); });
79
80 foreach (['create_category', 'delete_category'] as $hook)
81 add_action($hook, [\ATEC_WPCA\Tools::class, 'on_category_change'], 10, 1);
82
83 add_action('edited_category', [\ATEC_WPCA\Tools::class, 'on_category_edit'], 10, 2);
84
85 foreach (['created_term', 'delete_term'] as $hook)
86 add_action($hook, [\ATEC_WPCA\Tools::class, 'on_tag_change'], 10, 3);
87
88 add_action('edited_terms', [\ATEC_WPCA\Tools::class, 'on_tag_edit'], 10, 3);
89 }
90
91 if ($p_cache || WPCA::settings('o_cache'))
92 {
93 foreach (['activated_plugin', 'deactivated_plugin', 'upgrader_pre_install'] as $hook)
94 {
95 add_action($hook, function() use($p_cache)
96 {
97 WPC::flush_wp_cache_options();
98 if ($p_cache) \ATEC_WPCA\Tools::delete_page_cache_all();
99 });
100 }
101 }
102 }
103
104 })();
105
106 if (defined('ATEC_OC_ACTIVE_APCU') && defined('ATEC_OC_VERSION') && ATEC_OC_VERSION!== '2.0.9')
107 {
108 require(__DIR__.'/includes/atec-wpca-install-ocache.php');
109 \ATEC_WPCA\Install_OCache::init(true);
110 }
111 }
112 elseif (INIT::is_interactive())
113 {
114 if (!defined('ATEC_PC_ACTIVE_APCU') && WPCA::settings('p_cache'))
115 {
116 require(__DIR__.'/includes/atec-wpca-pcache.php');
117 add_action('init', ['\ATEC_WPCA\\PCache', 'init'], -1);
118 }
119 }
120 elseif (INIT::is_ajax())
121 {
122 add_action( 'wp_ajax_atec_wpca_ajax', function ()
123 {
124 if ( ! INIT::current_user_can('admin')) wp_die();
125 \ATEC\AJAX::nonce_check('wpca');
126
127 switch (INIT::_POST('cmd'))
128 {
129 case 'o_cache':
130 wp_cache_flush();
131 break;
132
133 case 'p_cache':
134 if (!class_exists('ATEC_WPCA\\Tools')) require(__DIR__.'/includes/atec-wpca-pcache-tools.php');
135 \ATEC_WPCA\Tools::delete_page_cache_all();
136 break;
137 }
138
139 wp_send_json_success();
140 });
141 }
142
143 if (!INIT::is_cli() && !INIT::is_cron())
144 {
145 if (WPCA::apcu_enabled())
146 {
147 if (WPCA::settings('p_cache')) require __DIR__.'/includes/atec-wpca-pcache-comments.php';
148 if (WPCA::settings('o_rest'))
149 {
150 require_once __DIR__ . '/includes/atec-wpca-rest-endpoint.php';
151 add_action('rest_api_init', ['\ATEC_WPCA\Rest', 'register']);
152 }
153 }
154 }
155
156 if (INIT::is_interactive())
157 { if (defined('ATEC_OC_ACTIVE_APCU') && WPCA::settings('o_stats')) register_shutdown_function([WPCA::class, 'o_cache_stats']); }
158 ?>