PluginProbe
atec Cache APCu / 2.3.74
atec Cache APCu v2.3.74
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.74, at atec-cache-apcu.php

169 lines 5.3 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.74
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.74');
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)
53 {
54 if (method_exists(\ATEC\INIT::class, 'admin_bar_button')) INIT::admin_bar_button($wp_admin_bar, 'wpca', '🗑️ OC', 'o_cache', 'Flush Oject Cache', 'oc');
55 // OUTDATED: 250706 | CLEANUP: remove
56 else $wp_admin_bar->add_node( [ 'id' => 'atec-wpca-oc', 'title' => '🗑️ OC', 'href' => '#', 'meta' => [ 'onclick' => 'atec_wpca_ajax_cb("o_cache")', 'title' => 'Flush OC'],]);
57 }
58
59 if ($p_admin)
60 {
61 if (method_exists(\ATEC\INIT::class, 'admin_bar_button')) INIT::admin_bar_button($wp_admin_bar, 'wpca', '🗑️ PC', 'p_cache', 'Flush Page Cache', 'pc');
62 // OUTDATED: 250706 | CLEANUP: remove
63 else $wp_admin_bar->add_node( [ 'id' => 'atec-wpca-pc', 'title' => '🗑️ PC', 'href' => '#', 'meta' => [ 'onclick' => 'atec_wpca_ajax_cb("p_cache")', 'title' => 'Flush PC'],]);
64 }
65 }, 999);
66 }
67
68 if (WPCA::settings('o_rest'))
69 {
70 add_action('admin_enqueue_scripts', function ($hook) {
71 $rest_url = add_query_arg('rest_route', '/atec-wpca/v1/worker-probe', site_url('/') );
72 wp_localize_script('atec-wpca-workers', 'ATEC_WPCA_WORKERS', [ 'restUrl' => esc_url_raw($rest_url), 'nonce' => wp_create_nonce('wp_rest'), ]);
73 });
74 }
75 }
76 });
77
78 (function()
79 {
80
81 if (WPCA::apcu_enabled())
82 {
83 $p_cache = WPCA::settings('p_cache');
84 if ($p_cache)
85 {
86 require __DIR__.'/includes/atec-wpca-pcache-tools.php';
87
88 foreach (['after_switch_theme', 'wp_ajax_edit_theme_plugin_file', 'wp_update_nav_menu', 'wp_delete_nav_menu'] as $hook)
89 add_action($hook, function() { \ATEC_WPCA\Tools::delete_page_cache_all(); });
90
91 foreach (['create_category', 'delete_category'] as $hook)
92 add_action($hook, [\ATEC_WPCA\Tools::class, 'on_category_change'], 10, 1);
93
94 add_action('edited_category', [\ATEC_WPCA\Tools::class, 'on_category_edit'], 10, 2);
95
96 foreach (['created_term', 'delete_term'] as $hook)
97 add_action($hook, [\ATEC_WPCA\Tools::class, 'on_tag_change'], 10, 3);
98
99 add_action('edited_terms', [\ATEC_WPCA\Tools::class, 'on_tag_edit'], 10, 3);
100 }
101
102 if ($p_cache || WPCA::settings('o_cache'))
103 {
104 foreach (['activated_plugin', 'deactivated_plugin', 'upgrader_pre_install'] as $hook)
105 {
106 add_action($hook, function() use($p_cache)
107 {
108 WPC::flush_wp_cache_options();
109 if ($p_cache) \ATEC_WPCA\Tools::delete_page_cache_all();
110 });
111 }
112 }
113 }
114
115 })();
116
117 if (defined('ATEC_OC_ACTIVE_APCU') && defined('ATEC_OC_VERSION') && ATEC_OC_VERSION!== '2.0.8')
118 {
119 require(__DIR__.'/includes/atec-wpca-install-ocache.php');
120 \ATEC_WPCA\Install_OCache::init(true);
121 }
122 }
123 elseif (INIT::is_interactive())
124 {
125 if (!defined('ATEC_PC_ACTIVE_APCU') && WPCA::settings('p_cache'))
126 {
127 require(__DIR__.'/includes/atec-wpca-pcache.php');
128 add_action('init', ['\ATEC_WPCA\\PCache', 'init'], -1);
129 }
130 }
131 elseif (INIT::is_ajax())
132 {
133 add_action( 'wp_ajax_atec_wpca_ajax', function ()
134 {
135 if ( ! INIT::current_user_can('admin')) wp_die();
136 \ATEC\AJAX::nonce_check('wpca');
137
138 switch (INIT::_POST('cmd'))
139 {
140 case 'o_cache':
141 wp_cache_flush();
142 break;
143
144 case 'p_cache':
145 if (!class_exists('ATEC_WPCA\\Tools')) require(__DIR__.'/includes/atec-wpca-pcache-tools.php');
146 \ATEC_WPCA\Tools::delete_page_cache_all();
147 break;
148 }
149
150 wp_send_json_success();
151 });
152 }
153
154 if (!INIT::is_cli() && !INIT::is_cron())
155 {
156 if (WPCA::apcu_enabled())
157 {
158 if (WPCA::settings('p_cache')) require __DIR__.'/includes/atec-wpca-pcache-comments.php';
159 if (WPCA::settings('o_rest'))
160 {
161 require_once __DIR__ . '/includes/atec-wpca-rest-endpoint.php';
162 add_action('rest_api_init', ['\ATEC_WPCA\Rest', 'register']);
163 }
164 }
165 }
166
167 if (INIT::is_interactive())
168 { if (defined('ATEC_OC_ACTIVE_APCU') && WPCA::settings('o_stats')) register_shutdown_function([WPCA::class, 'o_cache_stats']); }
169 ?>