Version Description
- First stable version released.
=
Download this release
Release Info
Developer | arubadev |
Plugin | Aruba HiSpeed Cache |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- admin/css/aruba-hispeed-cache-admin.css +36 -0
- admin/index.php +2 -0
- admin/js/aruba-hispeed-cache-admin.js +38 -0
- admin/partials/admin-display.php +24 -0
- admin/partials/admin-general-options.php +79 -0
- admin/partials/admin-notice-purge-completed.php +7 -0
- admin/partials/admin-notice-settings-saved.php +7 -0
- admin/partials/admin-notice-version.php +14 -0
- aruba-hispeed-cache.php +95 -0
- includes/ArubaHiSpeedCacheAdmin.php +470 -0
- includes/ArubaHiSpeedCacheBootstrap.php +196 -0
- includes/ArubaHiSpeedCacheConfigs.php +204 -0
- includes/ArubaHiSpeedCacheLoader.php +124 -0
- includes/ArubaHiSpeedCachePurger.php +180 -0
- includes/ArubaHiSpeedCacheWpPurger.php +514 -0
- includes/ArubaHiSpeedCachei18n.php +53 -0
- includes/index.php +6 -0
- index.php +6 -0
- languages/aruba-hispeed-cache-es_ES.mo +0 -0
- languages/aruba-hispeed-cache-es_ES.po +179 -0
- languages/aruba-hispeed-cache-it_IT.mo +0 -0
- languages/aruba-hispeed-cache-it_IT.po +183 -0
- languages/aruba-hispeed-cache.pot +156 -0
- readme.txt +69 -0
- uninstall.php +25 -0
admin/css/aruba-hispeed-cache-admin.css
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.clearfix {
|
2 |
+
}
|
3 |
+
.clearfix:before,
|
4 |
+
.clearfix:after {
|
5 |
+
content: " ";
|
6 |
+
display: table;
|
7 |
+
}
|
8 |
+
.clearfix:after {
|
9 |
+
clear: both;
|
10 |
+
}
|
11 |
+
|
12 |
+
.form-table th,
|
13 |
+
.form-wrap label {
|
14 |
+
vertical-align: middle;
|
15 |
+
}
|
16 |
+
|
17 |
+
.form-table th {
|
18 |
+
width: 25% !important;
|
19 |
+
}
|
20 |
+
|
21 |
+
.ahsc-options-wrapper tr td label {
|
22 |
+
width: 100%;
|
23 |
+
}
|
24 |
+
|
25 |
+
h2,
|
26 |
+
h3 {
|
27 |
+
color: #1d2327 !important;
|
28 |
+
font-size: 1.3em !important;
|
29 |
+
margin: 1em 0 !important;
|
30 |
+
padding: 8px 12px 8px 0px !important;
|
31 |
+
}
|
32 |
+
|
33 |
+
small::before {
|
34 |
+
content: "\a";
|
35 |
+
white-space: pre;
|
36 |
+
}
|
admin/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence.
|
admin/js/aruba-hispeed-cache-admin.js
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(() => {
|
2 |
+
"use strict";
|
3 |
+
|
4 |
+
const ahsc_show_option = () => {
|
5 |
+
let ahsc_enable_purge = document.querySelector("input#ahsc_enable_purge");
|
6 |
+
|
7 |
+
ahsc_enable_purge.addEventListener("change", (e) => {
|
8 |
+
let form_parts = document.querySelector(
|
9 |
+
"form#post_form > div > div"
|
10 |
+
).children;
|
11 |
+
|
12 |
+
if (
|
13 |
+
form_parts[1].style.display === "none" &&
|
14 |
+
form_parts[2].style.display === "none"
|
15 |
+
) {
|
16 |
+
form_parts[1].style.removeProperty("display");
|
17 |
+
form_parts[2].style.removeProperty("display");
|
18 |
+
} else {
|
19 |
+
form_parts[1].style.display = "none";
|
20 |
+
form_parts[2].style.display = "none";
|
21 |
+
}
|
22 |
+
});
|
23 |
+
};
|
24 |
+
|
25 |
+
document.addEventListener("DOMContentLoaded", function (event) {
|
26 |
+
const purge_btn = document.querySelector("a#purgeall");
|
27 |
+
|
28 |
+
purge_btn.addEventListener("click", (e) => {
|
29 |
+
if (confirm(aruba_hispeed_cache.purge_confirm_string) === true) {
|
30 |
+
// Continue submitting form.
|
31 |
+
} else {
|
32 |
+
e.preventDefault();
|
33 |
+
}
|
34 |
+
});
|
35 |
+
|
36 |
+
ahsc_show_option();
|
37 |
+
});
|
38 |
+
})();
|
admin/partials/admin-display.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
global $pagenow;
|
3 |
+
?>
|
4 |
+
|
5 |
+
<!-- This file should primarily consist of HTML with a little bit of PHP. -->
|
6 |
+
|
7 |
+
<div class="wrap ahsc-wrapper">
|
8 |
+
<h1 class="ahsc-option-title">
|
9 |
+
<?php \esc_html_e('Aruba HiSpeed Cache Settings ', 'aruba-hispeed-cache'); ?>
|
10 |
+
</h1>
|
11 |
+
|
12 |
+
<div id="poststuff">
|
13 |
+
<div id="post-body" class="metabox-holder columns-2">
|
14 |
+
<div id="post-body-content">
|
15 |
+
<?php
|
16 |
+
include ARUBA_HISPEED_CACHE_BASEPATH . 'admin' .AHSC_DS. 'partials' .AHSC_DS. 'admin-general-options.php';
|
17 |
+
?>
|
18 |
+
</div> <!-- End of #post-body-content -->
|
19 |
+
<div id="postbox-container-1" class="postbox-container">
|
20 |
+
<!-- empty sidebar -->
|
21 |
+
</div> <!-- End of #postbox-container-1 -->
|
22 |
+
</div> <!-- End of #post-body -->
|
23 |
+
</div> <!-- End of #poststuff -->
|
24 |
+
</div> <!-- End of .wrap .ahsc-wrapper -->
|
admin/partials/admin-general-options.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @see ArubaHiSpeedCache\includes\_settings_manager function
|
4 |
+
*/
|
5 |
+
$aruba_hispeed_cache_settings = $this->_settings_manager();
|
6 |
+
|
7 |
+
?>
|
8 |
+
|
9 |
+
<form id="post_form" method="post" action="#" name="smart_http_expire_form" class="clearfix">
|
10 |
+
|
11 |
+
<div class="ahsc-options-wrapper">
|
12 |
+
<div class="inside">
|
13 |
+
<table class="form-table ahsc-table">
|
14 |
+
<?php foreach ($this->_form_fields() as $fieldSets_key => $fieldSets_data): ?>
|
15 |
+
<?php if (isset($fieldSets_data['title'])) : ?>
|
16 |
+
</table>
|
17 |
+
<h2 class="title"><?php echo esc_html($fieldSets_data['title']); ?>
|
18 |
+
</h2>
|
19 |
+
<table class="form-table ahsc-table">
|
20 |
+
<?php continue; ?>
|
21 |
+
<?php endif; ?>
|
22 |
+
|
23 |
+
<tr class="<?php echo esc_html($fieldSets_key); ?>">
|
24 |
+
<th scope="row">
|
25 |
+
<?php echo esc_html($fieldSets_data['th']); ?>
|
26 |
+
<small><?php echo (isset($fieldSets_data['small'])) ? esc_html($fieldSets_data['small']) : '' ?></small>
|
27 |
+
</th>
|
28 |
+
<td>
|
29 |
+
<fieldset>
|
30 |
+
<legend class="screen-reader-text">
|
31 |
+
<span><?php echo esc_html($fieldSets_data['legend_text']); ?></span>
|
32 |
+
</legend>
|
33 |
+
<?php foreach ($fieldSets_data['fields'] as $field_key => $field): ?>
|
34 |
+
<label
|
35 |
+
for="<?php echo esc_html($field_key); ?>">
|
36 |
+
<input type="hidden"
|
37 |
+
name="<?php echo esc_html($field['name']); ?>"
|
38 |
+
value="0" />
|
39 |
+
<input
|
40 |
+
type="<?php echo esc_html($field['type']) ?>"
|
41 |
+
value="1"
|
42 |
+
name="<?php echo esc_html($field['name']); ?>"
|
43 |
+
id="<?php esc_html_e($field['id']); ?>"
|
44 |
+
<?php \checked($aruba_hispeed_cache_settings[$field_key], 1); ?>
|
45 |
+
/>
|
46 |
+
<?php _e($field['lable_text']); ?>
|
47 |
+
</label>
|
48 |
+
<?php endforeach; ?>
|
49 |
+
</fieldset>
|
50 |
+
</td>
|
51 |
+
</tr>
|
52 |
+
|
53 |
+
<?php endforeach;?>
|
54 |
+
</table>
|
55 |
+
</div>
|
56 |
+
</div>
|
57 |
+
|
58 |
+
<input type="hidden" name="smart_http_expire_form_nonce"
|
59 |
+
value="<?php _e($this->_generate_settings_form_nonce()); ?>" />
|
60 |
+
|
61 |
+
</form> <!-- End of #post_form -->
|
62 |
+
|
63 |
+
<div class="ahsc-actions-wrapper">
|
64 |
+
<table class="form-table ahst-table">
|
65 |
+
<tr>
|
66 |
+
<th></th>
|
67 |
+
<td>
|
68 |
+
<?php
|
69 |
+
\submit_button(__('Save changes', 'aruba-hispeed-cache'), 'primary', 'smart_http_expire_save', false, array('form' => 'post_form'));
|
70 |
+
?>
|
71 |
+
<a id="purgeall"
|
72 |
+
href="<?php echo \esc_url($this->_generate_purge_nonce()); ?>"
|
73 |
+
class="button button-primary">
|
74 |
+
<?php \esc_html_e('Purge entire cache', 'aruba-hispeed-cache'); ?>
|
75 |
+
</a>
|
76 |
+
</td>
|
77 |
+
</tr>
|
78 |
+
</table>
|
79 |
+
</div>
|
admin/partials/admin-notice-purge-completed.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="updated">
|
2 |
+
<p>
|
3 |
+
<?php
|
4 |
+
\esc_html_e('Purge completed', 'aruba-hispeed-cache');
|
5 |
+
?>
|
6 |
+
</p>
|
7 |
+
</div>
|
admin/partials/admin-notice-settings-saved.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="updated">
|
2 |
+
<p>
|
3 |
+
<?php
|
4 |
+
\esc_html_e('Settings saved.', 'aruba-hispeed-cache');
|
5 |
+
?>
|
6 |
+
</p>
|
7 |
+
</div>
|
admin/partials/admin-notice-version.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="message" class="error">
|
2 |
+
<p>
|
3 |
+
<strong>
|
4 |
+
<?php
|
5 |
+
/**
|
6 |
+
* Printf
|
7 |
+
*/
|
8 |
+
\printf(
|
9 |
+
\esc_html__('Sorry, Aruba HiSpeed Cache requires WordPress %s or higher.', 'aruba-hispeed-cache'),
|
10 |
+
\esc_html($this->config::MINIMUM_WP)
|
11 |
+
); ?>
|
12 |
+
</strong>
|
13 |
+
</p>
|
14 |
+
</div>
|
aruba-hispeed-cache.php
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Aruba HiSpeed Cache
|
4 |
+
*
|
5 |
+
* @category Wordpress-plugin
|
6 |
+
* @package Aruba-HiSpeed-Cache
|
7 |
+
* @author Aruba Developer <hispeedcache.developer@aruba.it>
|
8 |
+
* @license https://www.gnu.org/licenses/gpl-2.0.html GPLv2 or later
|
9 |
+
* @link run_aruba_hispeed_cache
|
10 |
+
*
|
11 |
+
* @wordpress-plugin
|
12 |
+
* Plugin Name: Aruba HiSpeed Cache
|
13 |
+
* Version: 1.0.0
|
14 |
+
* Plugin URI: https://www.aruba.it/magazine/hosting/siti-piu-veloci-con-hispeed-cache.aspx
|
15 |
+
* Description: Purges the cache whenever a post is edited or published.
|
16 |
+
* Author: Aruba.it
|
17 |
+
* Author URI: https://www.aruba.it/
|
18 |
+
* Text Domain: aruba-hispeed-cache
|
19 |
+
* License: GPL v2
|
20 |
+
* Requires at least: 5.7
|
21 |
+
* Tested up to: 6.0
|
22 |
+
* Requires PHP: 7.4
|
23 |
+
*
|
24 |
+
*
|
25 |
+
* This program is free software: you can redistribute it and/or modify
|
26 |
+
* it under the terms of the GNU General Public License as published by
|
27 |
+
* the Free Software Foundation, either version 2 of the License, or
|
28 |
+
* (at your option) any later version.
|
29 |
+
*
|
30 |
+
* This program is distributed in the hope that it will be useful,
|
31 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
32 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
33 |
+
* GNU General Public License for more details.
|
34 |
+
*
|
35 |
+
* You should have received a copy of the GNU General Public License
|
36 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
37 |
+
*/
|
38 |
+
|
39 |
+
declare(strict_types=1);
|
40 |
+
|
41 |
+
namespace ArubaHiSpeedCache;
|
42 |
+
|
43 |
+
use ArubaHiSpeedCache\includes\ArubaHiSpeedCacheConfigs;
|
44 |
+
use ArubaHiSpeedCache\includes\ArubaHiSpeedCacheBootstrap;
|
45 |
+
use ArubaHiSpeedCache\includes\ArubaHiSpeedCache_WP_CLI_Command;
|
46 |
+
|
47 |
+
use \register_activation_hook;
|
48 |
+
use \register_deactivation_hook;
|
49 |
+
use \defined;
|
50 |
+
use \WP_CLI;
|
51 |
+
|
52 |
+
if (!defined('WPINC')) {
|
53 |
+
die;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Require class-aruba-hispeed-cache-config.php to boostrasp the confing of plugin
|
58 |
+
* execution of the method ArubaHiSpeedCache_set_default_constant for the generation
|
59 |
+
* of the environment variables
|
60 |
+
*/
|
61 |
+
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' .DIRECTORY_SEPARATOR. 'ArubaHiSpeedCacheConfigs.php';
|
62 |
+
ArubaHiSpeedCacheConfigs::ArubaHiSpeedCache_set_default_constant(__FILE__);
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Adding methods to "activate" and "deactivate" hooks
|
66 |
+
*/
|
67 |
+
\register_activation_hook(ARUBA_HISPEED_CACHE_FILE, function () {
|
68 |
+
ArubaHiSpeedCacheConfigs::ArubaHiSpeedCache_activate();
|
69 |
+
});
|
70 |
+
|
71 |
+
\register_deactivation_hook(ARUBA_HISPEED_CACHE_FILE, function () {
|
72 |
+
ArubaHiSpeedCacheConfigs::ArubaHiSpeedCache_deactivate();
|
73 |
+
});
|
74 |
+
|
75 |
+
if (!function_exists(__NAMESPACE__ . 'run_aruba_hispeed_cache')) {
|
76 |
+
include_once ARUBA_HISPEED_CACHE_BASEPATH . 'includes' .AHSC_DS. 'ArubaHiSpeedCacheBootstrap.php';
|
77 |
+
|
78 |
+
/**
|
79 |
+
* run_aruba_hispeed_cache
|
80 |
+
*
|
81 |
+
* @return void
|
82 |
+
*/
|
83 |
+
function run_aruba_hispeed_cache()
|
84 |
+
{
|
85 |
+
global $aruba_hispeed_cache;
|
86 |
+
|
87 |
+
$aruba_hispeed_cache = new ArubaHiSpeedCacheBootstrap();
|
88 |
+
$aruba_hispeed_cache->run();
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Runner
|
93 |
+
*/
|
94 |
+
run_aruba_hispeed_cache();
|
95 |
+
}
|
includes/ArubaHiSpeedCacheAdmin.php
ADDED
@@ -0,0 +1,470 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @category Wordpress-plugin
|
4 |
+
* @package Aruba-HiSpeed-Cache
|
5 |
+
* @author Aruba Developer <hispeedcache.developer@aruba.it>
|
6 |
+
* @license https://www.gnu.org/licenses/gpl-2.0.html GPLv2 or later
|
7 |
+
* @link run_aruba_hispeed_cache
|
8 |
+
*/
|
9 |
+
declare(strict_types=1);
|
10 |
+
|
11 |
+
namespace ArubaHiSpeedCache\includes;
|
12 |
+
|
13 |
+
use ArubaHiSpeedCache\includes\ArubaHiSpeedCacheConfigs;
|
14 |
+
use \WP_Admin_Bar;
|
15 |
+
|
16 |
+
use \array_unshift;
|
17 |
+
use \sprintf;
|
18 |
+
|
19 |
+
use \wp_enqueue_style;
|
20 |
+
use \wp_enqueue_script;
|
21 |
+
use \wp_localize_script;
|
22 |
+
use \esc_html__;
|
23 |
+
use \__;
|
24 |
+
use \is_multisite;
|
25 |
+
use \is_network_admin;
|
26 |
+
use \add_submenu_page;
|
27 |
+
use \network_admin_url;
|
28 |
+
use \get_site_option;
|
29 |
+
use \wp_parse_args;
|
30 |
+
use \current_user_can;
|
31 |
+
use \is_admin;
|
32 |
+
use \add_query_arg;
|
33 |
+
use \wp_nonce_url;
|
34 |
+
use \wp_is_post_revision;
|
35 |
+
use \update_site_option;
|
36 |
+
use \wp_die;
|
37 |
+
use \wp_redirect;
|
38 |
+
use \esc_url_raw;
|
39 |
+
use \do_action;
|
40 |
+
use \check_admin_referer;
|
41 |
+
use \user_trailingslashit;
|
42 |
+
use \home_url;
|
43 |
+
use \wp_verify_nonce;
|
44 |
+
use \checked;
|
45 |
+
use \wp_kses;
|
46 |
+
|
47 |
+
if (! \class_exists('ArubaHiSpeedCache\includes\ArubaHiSpeedCacheAdmin')) {
|
48 |
+
|
49 |
+
/**
|
50 |
+
* ArubaHiSpeedCacheAdmin
|
51 |
+
*/
|
52 |
+
class ArubaHiSpeedCacheAdmin
|
53 |
+
{
|
54 |
+
|
55 |
+
/**
|
56 |
+
* $options
|
57 |
+
*
|
58 |
+
* @var array
|
59 |
+
*/
|
60 |
+
public array $options;
|
61 |
+
|
62 |
+
public ArubaHiSpeedCacheConfigs $configs;
|
63 |
+
|
64 |
+
/**
|
65 |
+
* ArubaHiSpeedCacheAdmin\__construct
|
66 |
+
*
|
67 |
+
* @param mixed $name
|
68 |
+
*/
|
69 |
+
public function __construct(ArubaHiSpeedCacheConfigs $configs)
|
70 |
+
{
|
71 |
+
$this->configs = $configs;
|
72 |
+
$this->options = $this->aruba_hispeed_cache_settings();
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Enqueue_styles
|
77 |
+
*
|
78 |
+
* @param string $hook the currente acp hookname
|
79 |
+
* @return void
|
80 |
+
*/
|
81 |
+
public function enqueue_styles(string $hook)
|
82 |
+
{
|
83 |
+
if ('settings_page_aruba-hispeed-cache' !== $hook) {
|
84 |
+
return;
|
85 |
+
}
|
86 |
+
|
87 |
+
\wp_enqueue_style(
|
88 |
+
$this->configs::PLUGIN_NAME,
|
89 |
+
ARUBA_HISPEED_CACHE_BASEURL . 'admin/css/aruba-hispeed-cache-admin.css',
|
90 |
+
array(),
|
91 |
+
$this->configs::PLUGIN_VERSION
|
92 |
+
);
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Enqueue_scripts
|
97 |
+
*
|
98 |
+
* @param string $hook the currente acp hookname
|
99 |
+
* @return void
|
100 |
+
*/
|
101 |
+
public function enqueue_scripts(string $hook)
|
102 |
+
{
|
103 |
+
if ('settings_page_aruba-hispeed-cache' !== $hook) {
|
104 |
+
return;
|
105 |
+
}
|
106 |
+
|
107 |
+
\wp_enqueue_script(
|
108 |
+
$this->configs::PLUGIN_NAME,
|
109 |
+
ARUBA_HISPEED_CACHE_BASEURL . 'admin/js/aruba-hispeed-cache-admin.js',
|
110 |
+
array(),
|
111 |
+
$this->configs::PLUGIN_VERSION
|
112 |
+
);
|
113 |
+
|
114 |
+
\wp_localize_script($this->configs::PLUGIN_NAME, 'aruba_hispeed_cache', [
|
115 |
+
'purge_confirm_string' => \esc_html__('You are about to purge the entire cache. Do you want to continue?', 'aruba-hispeed-cache'),
|
116 |
+
]);
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Aruba_hispeed_cache_admin_menu
|
121 |
+
*
|
122 |
+
* @return void
|
123 |
+
*/
|
124 |
+
public function aruba_hispeed_cache_admin_menu()
|
125 |
+
{
|
126 |
+
if (\is_multisite()) {
|
127 |
+
\add_submenu_page(
|
128 |
+
'settings.php',
|
129 |
+
__('Aruba HiSpeed Cache', 'aruba-hispeed-cache'),
|
130 |
+
__('Aruba HiSpeed Cache', 'aruba-hispeed-cache'),
|
131 |
+
'manage_options',
|
132 |
+
'aruba-hispeed-cache',
|
133 |
+
array( &$this, 'aruba_hispeed_cache_setting_page_cb' )
|
134 |
+
);
|
135 |
+
} else {
|
136 |
+
\add_submenu_page(
|
137 |
+
'options-general.php',
|
138 |
+
__('Aruba HiSpeed Cache', 'aruba-hispeed-cache'),
|
139 |
+
__('Aruba HiSpeed Cache', 'aruba-hispeed-cache'),
|
140 |
+
'manage_options',
|
141 |
+
'aruba-hispeed-cache',
|
142 |
+
array( &$this, 'aruba_hispeed_cache_setting_page_cb' )
|
143 |
+
);
|
144 |
+
}
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Undocumented function
|
149 |
+
*
|
150 |
+
* @return void
|
151 |
+
*/
|
152 |
+
public function aruba_hispeed_cache_setting_page_cb()
|
153 |
+
{
|
154 |
+
include ARUBA_HISPEED_CACHE_BASEPATH . 'admin' .AHSC_DS. 'partials' .AHSC_DS. 'admin-display.php';
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Aruba_hispeed_cache_toolbar_purge_link
|
159 |
+
*
|
160 |
+
* @param WP_Admin_Bar $wp_admin_bar
|
161 |
+
* @return void
|
162 |
+
*/
|
163 |
+
public function aruba_hispeed_cache_toolbar_purge_link(WP_Admin_Bar $wp_admin_bar)
|
164 |
+
{
|
165 |
+
if (! \current_user_can('manage_options')) {
|
166 |
+
return;
|
167 |
+
}
|
168 |
+
|
169 |
+
$aruba_hispeed_cache_urls = 'current-url';
|
170 |
+
$link_title = __('Purge the page cache', 'aruba-hispeed-cache');
|
171 |
+
|
172 |
+
if (\is_admin()) {
|
173 |
+
$aruba_hispeed_cache_urls = 'all';
|
174 |
+
$link_title = __('Purge Cache', 'aruba-hispeed-cache');
|
175 |
+
}
|
176 |
+
|
177 |
+
$purge_url = \add_query_arg(
|
178 |
+
array(
|
179 |
+
'aruba_hispeed_cache_action' => 'purge',
|
180 |
+
'aruba_hispeed_cache_urls' => $aruba_hispeed_cache_urls,
|
181 |
+
)
|
182 |
+
);
|
183 |
+
|
184 |
+
$nonced_url = \wp_nonce_url($purge_url, 'aruba_hispeed_cache-purge_all');
|
185 |
+
|
186 |
+
$wp_admin_bar->add_menu(
|
187 |
+
array(
|
188 |
+
'id' => 'aruba-hispeed-cache-purge-all',
|
189 |
+
'title' => $link_title,
|
190 |
+
'href' => $nonced_url,
|
191 |
+
'meta' => array( 'title' => $link_title ),
|
192 |
+
)
|
193 |
+
);
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Aruba_hispeed_cache_settings
|
198 |
+
*
|
199 |
+
* @return array $data
|
200 |
+
*/
|
201 |
+
public function aruba_hispeed_cache_settings(): array
|
202 |
+
{
|
203 |
+
$options = \get_site_option(ARUBA_HISPEED_CACHE_OPTIONS_NAME);
|
204 |
+
|
205 |
+
$data = \wp_parse_args(
|
206 |
+
$options,
|
207 |
+
$this->configs::ArubaHiSpeedCache_get_default_settings()
|
208 |
+
);
|
209 |
+
|
210 |
+
return $data;
|
211 |
+
}
|
212 |
+
|
213 |
+
/**
|
214 |
+
* Aruba_hispeed_cache_settings_link
|
215 |
+
*
|
216 |
+
* @param array $links
|
217 |
+
* @return array $links
|
218 |
+
*/
|
219 |
+
public function aruba_hispeed_cache_settings_link(array $links): array
|
220 |
+
{
|
221 |
+
$setting_page = (!\is_network_admin()) ? 'options-general.php' : 'settings.php';
|
222 |
+
|
223 |
+
$settings_link = \sprintf(
|
224 |
+
'<a href="%s">%s</a>',
|
225 |
+
\network_admin_url($setting_page . '?page=aruba-hispeed-cache'),
|
226 |
+
\__('Settings', 'aruba-hispeed-cache')
|
227 |
+
);
|
228 |
+
|
229 |
+
\array_unshift($links, $settings_link);
|
230 |
+
|
231 |
+
return $links;
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Display_notices
|
236 |
+
*
|
237 |
+
* @return void
|
238 |
+
*/
|
239 |
+
public function display_notices_settings_saved()
|
240 |
+
{
|
241 |
+
require_once ARUBA_HISPEED_CACHE_BASEPATH . 'admin' .AHSC_DS. 'partials' .AHSC_DS. 'admin-notice-settings-saved.php';
|
242 |
+
}
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Display_notices
|
246 |
+
*
|
247 |
+
* @return void
|
248 |
+
*/
|
249 |
+
public function display_notices_purge_initied()
|
250 |
+
{
|
251 |
+
require_once ARUBA_HISPEED_CACHE_BASEPATH . 'admin' .AHSC_DS. 'partials' .AHSC_DS. 'admin-notice-purge-completed.php';
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* _generate_purge_nonce
|
256 |
+
*
|
257 |
+
* @return wp_nonce_url
|
258 |
+
*/
|
259 |
+
private function _generate_purge_nonce()
|
260 |
+
{
|
261 |
+
$purge_url = \add_query_arg(
|
262 |
+
[
|
263 |
+
'aruba_hispeed_cache_action' => 'purge',
|
264 |
+
'aruba_hispeed_cache_urls' => 'all',
|
265 |
+
]
|
266 |
+
);
|
267 |
+
return \wp_nonce_url($purge_url, 'aruba_hispeed_cache-purge_all');
|
268 |
+
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* private _generate_settings_form_nonce
|
272 |
+
*
|
273 |
+
* @return string wp_create_nonce
|
274 |
+
*/
|
275 |
+
private function _generate_settings_form_nonce()
|
276 |
+
{
|
277 |
+
return \wp_create_nonce('smart-http-expire-form-nonce');
|
278 |
+
}
|
279 |
+
|
280 |
+
/**
|
281 |
+
* private _save_settings
|
282 |
+
*
|
283 |
+
* @return void
|
284 |
+
*/
|
285 |
+
private function _save_settings()
|
286 |
+
{
|
287 |
+
//get the current option stored in db.
|
288 |
+
$current_options = $this->aruba_hispeed_cache_settings();
|
289 |
+
|
290 |
+
//prepare the filter to escape the inputs
|
291 |
+
$form_options = \array_merge($this->configs::OPTIONS, ['is_submit', 'smart_http_expire_save', 'smart_http_expire_form_nonce']);
|
292 |
+
$form_options = \array_fill_keys($form_options, FILTER_SANITIZE_STRING);
|
293 |
+
|
294 |
+
/**
|
295 |
+
* @see https://www.php.net/manual/en/function.filter-input-array.php
|
296 |
+
*/
|
297 |
+
$all_inputs = filter_input_array(INPUT_POST, $form_options, false);
|
298 |
+
|
299 |
+
if (isset($all_inputs['smart_http_expire_save']) &&
|
300 |
+
\wp_verify_nonce($all_inputs['smart_http_expire_form_nonce'], 'smart-http-expire-form-nonce')) {
|
301 |
+
unset($all_inputs['smart_http_expire_save']);
|
302 |
+
unset($all_inputs['smart_http_expire_form_nonce']);
|
303 |
+
unset($all_inputs['is_submit']);
|
304 |
+
|
305 |
+
$new_settings = \wp_parse_args(
|
306 |
+
$all_inputs,
|
307 |
+
$current_options
|
308 |
+
);
|
309 |
+
|
310 |
+
if (\update_site_option(ARUBA_HISPEED_CACHE_OPTIONS_NAME, $new_settings)) {
|
311 |
+
// \add_action('admin_notices', array( &$this, 'display_notices_settings_saved' ));
|
312 |
+
// \add_action('network_admin_notices', array( &$this, 'display_notices_settings_saved' ));
|
313 |
+
$this->display_notices_settings_saved();
|
314 |
+
}
|
315 |
+
}
|
316 |
+
}
|
317 |
+
|
318 |
+
/**
|
319 |
+
* private _settings_manager()
|
320 |
+
*
|
321 |
+
* @return array settings
|
322 |
+
*/
|
323 |
+
private function _settings_manager()
|
324 |
+
{
|
325 |
+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
326 |
+
$this->_save_settings();
|
327 |
+
}
|
328 |
+
return $this->aruba_hispeed_cache_settings();
|
329 |
+
}
|
330 |
+
|
331 |
+
/**
|
332 |
+
* private function _form_fields
|
333 |
+
*
|
334 |
+
* @return array $fieldsSets
|
335 |
+
*/
|
336 |
+
private function _form_fields()
|
337 |
+
{
|
338 |
+
$fieldsSets = [];
|
339 |
+
|
340 |
+
$fieldsSets['ahsc_enable_purge'] = [
|
341 |
+
'th' => \esc_html__('Purging options', 'aruba-hispeed-cache'),
|
342 |
+
'legend_text' => \esc_html__('Purging options', 'aruba-hispeed-cache'),
|
343 |
+
'fields' => [
|
344 |
+
'ahsc_enable_purge' => [
|
345 |
+
'type' => 'checkbox',
|
346 |
+
'id' => 'ahsc_enable_purge',
|
347 |
+
'name' => 'ahsc_enable_purge',
|
348 |
+
'lable_for' => 'ahsc_enable_purge',
|
349 |
+
'lable_text' => \esc_html__('Enable automatic purge', 'aruba-hispeed-cache'),
|
350 |
+
]
|
351 |
+
],
|
352 |
+
];
|
353 |
+
|
354 |
+
/**
|
355 |
+
* @see https://developer.wordpress.org/reference/functions/is_network_admin/
|
356 |
+
* True if inside WordPress network administration pages
|
357 |
+
*
|
358 |
+
* @see https://developer.wordpress.org/reference/functions/is_multisite/
|
359 |
+
* True if Multisite is enabled, false otherwise.
|
360 |
+
*/
|
361 |
+
if (! (!\is_network_admin() && \is_multisite())) {
|
362 |
+
if ($this->aruba_hispeed_cache_settings()['ahsc_enable_purge'] != 0) {
|
363 |
+
|
364 |
+
//infos string
|
365 |
+
$fieldsSets['ahsc_info'] = [
|
366 |
+
'title' => \esc_html__('Automatically purge entire cache when:', 'aruba-hispeed-cache'),
|
367 |
+
];
|
368 |
+
|
369 |
+
//fieldsSets ahsc_purge_homepage
|
370 |
+
$fieldsSets['ahsc_purge_homepage'] = [
|
371 |
+
'th' => \esc_html__('Home page:', 'aruba-hispeed-cache'),
|
372 |
+
'legend_text' => \esc_html__('Home page:', 'aruba-hispeed-cache'),
|
373 |
+
'fields' => [
|
374 |
+
'ahsc_purge_homepage_on_edit' => [
|
375 |
+
'type' => 'checkbox',
|
376 |
+
'id' => 'ahsc_purge_homepage_on_edit',
|
377 |
+
'name' => 'ahsc_purge_homepage_on_edit',
|
378 |
+
'lable_for' => 'ahsc_purge_homepage_on_edit',
|
379 |
+
'lable_text' => \wp_kses(__('a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.', 'aruba-hispeed-cache'), array( 'strong' => array() ))
|
380 |
+
],
|
381 |
+
'ahsc_purge_homepage_on_del' => [
|
382 |
+
'type' => 'checkbox',
|
383 |
+
'id' => 'ahsc_purge_homepage_on_del',
|
384 |
+
'name' => 'ahsc_purge_homepage_on_del',
|
385 |
+
'lable_for' => 'ahsc_purge_homepage_on_del',
|
386 |
+
'lable_text' => wp_kses(__('a <strong>published post</strong> (or page/custom post) is <strong>cancelled</strong>.', 'aruba-hispeed-cache'), array( 'strong' => array() ))
|
387 |
+
],
|
388 |
+
]
|
389 |
+
];
|
390 |
+
|
391 |
+
//fieldsSets ahsc_purge_page
|
392 |
+
$fieldsSets['ahsc_purge_page'] = [
|
393 |
+
'th' => \esc_html__('Post/page/custom post type:', 'aruba-hispeed-cache'),
|
394 |
+
'legend_text' => \esc_html__('Post/page/custom post type:', 'aruba-hispeed-cache'),
|
395 |
+
'fields' => [
|
396 |
+
'ahsc_purge_page_on_mod' => [
|
397 |
+
'type' => 'checkbox',
|
398 |
+
'id' => 'ahsc_purge_page_on_mod',
|
399 |
+
'name' => 'ahsc_purge_page_on_mod',
|
400 |
+
'lable_for' => 'ahsc_purge_page_on_mod',
|
401 |
+
'lable_text' => \wp_kses(__('a <strong>post</strong> is <strong>published</strong>.', 'aruba-hispeed-cache'), array( 'strong' => array() ))
|
402 |
+
],
|
403 |
+
'ahsc_purge_page_on_new_comment' => [
|
404 |
+
'type' => 'checkbox',
|
405 |
+
'id' => 'ahsc_purge_page_on_new_comment',
|
406 |
+
'name' => 'ahsc_purge_page_on_new_comment',
|
407 |
+
'lable_for' => 'ahsc_purge_page_on_new_comment',
|
408 |
+
'lable_text' => \wp_kses(__('a <strong>comment</strong> is <strong>approved/published</strong>.', 'aruba-hispeed-cache'), array( 'strong' => array() ))
|
409 |
+
],
|
410 |
+
'ahsc_purge_page_on_deleted_comment' => [
|
411 |
+
'type' => 'checkbox',
|
412 |
+
'id' => 'ahsc_purge_page_on_deleted_comment',
|
413 |
+
'name' => 'ahsc_purge_page_on_deleted_comment',
|
414 |
+
'lable_for' => 'ahsc_purge_page_on_deleted_comment',
|
415 |
+
'lable_text' => \wp_kses(__('a <strong>comment</strong> is <strong>unapproved/deleted</strong>.', 'aruba-hispeed-cache'), array( 'strong' => array() ))
|
416 |
+
]
|
417 |
+
]
|
418 |
+
];
|
419 |
+
|
420 |
+
//fieldsSets ahsc_purge_archive
|
421 |
+
$fieldsSets['ahsc_purge_archive'] = [
|
422 |
+
'th' => \esc_html__('Archives:', 'aruba-hispeed-cache'),
|
423 |
+
'small' => \esc_html__('(date, category, tag, author, custom taxonomies)', 'aruba-hispeed-cache'),
|
424 |
+
'legend_text' => \esc_html__('Archives:', 'aruba-hispeed-cache'),
|
425 |
+
'fields' => [
|
426 |
+
'ahsc_purge_archive_on_edit' => [
|
427 |
+
'type' => 'checkbox',
|
428 |
+
'id' => 'ahsc_purge_archive_on_edit',
|
429 |
+
'name' => 'ahsc_purge_archive_on_edit',
|
430 |
+
'lable_for' => 'ahsc_purge_archive_on_edit',
|
431 |
+
'lable_text' => \wp_kses(__('a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.', 'aruba-hispeed-cache'), array( 'strong' => array() ))
|
432 |
+
],
|
433 |
+
'ahsc_purge_archive_on_del' => [
|
434 |
+
'type' => 'checkbox',
|
435 |
+
'id' => 'ahsc_purge_archive_on_del',
|
436 |
+
'name' => 'ahsc_purge_archive_on_del',
|
437 |
+
'lable_for' => 'ahsc_purge_archive_on_del',
|
438 |
+
'lable_text' => \wp_kses(__('a <strong>published post</strong> (or page/custom post) is <strong>cancelled</strong>.', 'aruba-hispeed-cache'), array( 'strong' => array() ))
|
439 |
+
]
|
440 |
+
]
|
441 |
+
];
|
442 |
+
|
443 |
+
//fieldsSets ahsc_purge_archive_on_comment
|
444 |
+
$fieldsSets['ahsc_purge_archive_on_comment'] = [
|
445 |
+
'th' => \esc_html__('Comments:', 'aruba-hispeed-cache'),
|
446 |
+
'legend_text' => \esc_html__('Comments:', 'aruba-hispeed-cache'),
|
447 |
+
'fields' => [
|
448 |
+
'ahsc_purge_archive_on_new_comment' => [
|
449 |
+
'type' => 'checkbox',
|
450 |
+
'id' => 'ahsc_purge_archive_on_new_comment',
|
451 |
+
'name' => 'ahsc_purge_archive_on_new_comment',
|
452 |
+
'lable_for' => 'ahsc_purge_archive_on_new_comment',
|
453 |
+
'lable_text' => \wp_kses(__('a <strong>comment</strong> is <strong>approved/published</strong>.', 'aruba-hispeed-cache'), array( 'strong' => array() ))
|
454 |
+
],
|
455 |
+
'ahsc_purge_archive_on_deleted_comment' => [
|
456 |
+
'type' => 'checkbox',
|
457 |
+
'id' => 'ahsc_purge_archive_on_deleted_comment',
|
458 |
+
'name' => 'ahsc_purge_archive_on_deleted_comment',
|
459 |
+
'lable_for' => 'ahsc_purge_archive_on_deleted_comment',
|
460 |
+
'lable_text' => \wp_kses(__('a <strong>comment</strong> is <strong>unapproved/deleted</strong>.', 'aruba-hispeed-cache'), array( 'strong' => array() ))
|
461 |
+
]
|
462 |
+
]
|
463 |
+
];
|
464 |
+
}
|
465 |
+
}
|
466 |
+
|
467 |
+
return $fieldsSets;
|
468 |
+
}
|
469 |
+
}
|
470 |
+
}
|
includes/ArubaHiSpeedCacheBootstrap.php
ADDED
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @category Wordpress-plugin
|
4 |
+
* @package Aruba-HiSpeed-Cache
|
5 |
+
* @author Aruba Developer <hispeedcache.developer@aruba.it>
|
6 |
+
* @license https://www.gnu.org/licenses/gpl-2.0.html GPLv2 or later
|
7 |
+
* @link run_aruba_hispeed_cache
|
8 |
+
*/
|
9 |
+
declare(strict_types=1);
|
10 |
+
|
11 |
+
namespace ArubaHiSpeedCache\includes;
|
12 |
+
|
13 |
+
use ArubaHiSpeedCache\includes\ArubaHiSpeedCacheConfigs;
|
14 |
+
|
15 |
+
use ArubaHiSpeedCache\includes\ArubaHiSpeedCacheAdmin;
|
16 |
+
use ArubaHiSpeedCache\includes\ArubaHiSpeedCachei18n;
|
17 |
+
use ArubaHiSpeedCache\includes\ArubaHiSpeedCacheLoader;
|
18 |
+
use ArubaHiSpeedCache\includes\FastCGIPurger;
|
19 |
+
|
20 |
+
use \version_compare;
|
21 |
+
use \esc_html__;
|
22 |
+
use \esc_html;
|
23 |
+
use \is_multisite;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Aruba_HiSpeed_Cache
|
27 |
+
*/
|
28 |
+
class ArubaHiSpeedCacheBootstrap
|
29 |
+
{
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Undocumented variable
|
33 |
+
*
|
34 |
+
* @var [type]
|
35 |
+
*/
|
36 |
+
protected $loader;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Configs
|
40 |
+
*
|
41 |
+
* @var [type]
|
42 |
+
*/
|
43 |
+
protected $config;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Undocumented function
|
47 |
+
*/
|
48 |
+
public function __construct()
|
49 |
+
{
|
50 |
+
$this->config = $this->getConfigs();
|
51 |
+
|
52 |
+
if (! $this->required_wp_version()) {
|
53 |
+
return;
|
54 |
+
}
|
55 |
+
|
56 |
+
$this->_load_dependencies();
|
57 |
+
$this->_set_locale();
|
58 |
+
$this->_define_admin_hooks();
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Load_dependencies
|
63 |
+
*
|
64 |
+
* @see ArubaHiSpeedCache_get_dependencies
|
65 |
+
* @return void
|
66 |
+
*/
|
67 |
+
private function _load_dependencies()
|
68 |
+
{
|
69 |
+
require_once \plugin_dir_path(ARUBA_HISPEED_CACHE_FILE) . 'includes' .AHSC_DS. 'ArubaHiSpeedCacheLoader.php';
|
70 |
+
require_once \plugin_dir_path(ARUBA_HISPEED_CACHE_FILE) . 'includes' .AHSC_DS. 'ArubaHiSpeedCachei18n.php';
|
71 |
+
require_once \plugin_dir_path(ARUBA_HISPEED_CACHE_FILE) . 'includes' .AHSC_DS. 'ArubaHiSpeedCacheAdmin.php';
|
72 |
+
require_once \plugin_dir_path(ARUBA_HISPEED_CACHE_FILE) . 'includes' .AHSC_DS. 'ArubaHiSpeedCachePurger.php';
|
73 |
+
require_once \plugin_dir_path(ARUBA_HISPEED_CACHE_FILE) . 'includes' .AHSC_DS. 'ArubaHiSpeedCacheWpPurger.php';
|
74 |
+
|
75 |
+
$this->loader = new ArubaHiSpeedCacheLoader();
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Set_locale
|
80 |
+
*
|
81 |
+
* @return void
|
82 |
+
*/
|
83 |
+
private function _set_locale()
|
84 |
+
{
|
85 |
+
$plugin_i18n = new ArubaHiSpeedCachei18n($this->config::PLUGIN_NAME, ARUBA_HISPEED_CACHE_BASENAME);
|
86 |
+
|
87 |
+
$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Define_admin_hooks
|
92 |
+
*
|
93 |
+
* @return void
|
94 |
+
*/
|
95 |
+
private function _define_admin_hooks()
|
96 |
+
{
|
97 |
+
global $aruba_hispeed_cache_admin, $aruba_hispeed_cache_purger;
|
98 |
+
|
99 |
+
$aruba_hispeed_cache_admin = new ArubaHiSpeedCacheAdmin($this->config);
|
100 |
+
$aruba_hispeed_cache_purger = new ArubaHiSpeedCacheWpPurger($this->config, $aruba_hispeed_cache_admin);
|
101 |
+
|
102 |
+
$this->loader->add_action('admin_enqueue_scripts', $aruba_hispeed_cache_admin, 'enqueue_styles');
|
103 |
+
$this->loader->add_action('admin_enqueue_scripts', $aruba_hispeed_cache_admin, 'enqueue_scripts');
|
104 |
+
|
105 |
+
if (\is_multisite()) {
|
106 |
+
$this->loader->add_action('network_admin_menu', $aruba_hispeed_cache_admin, 'aruba_hispeed_cache_admin_menu');
|
107 |
+
$this->loader->add_filter('network_admin_plugin_action_links_' . ARUBA_HISPEED_CACHE_BASENAME, $aruba_hispeed_cache_admin, 'aruba_hispeed_cache_settings_link');
|
108 |
+
} else {
|
109 |
+
$this->loader->add_action('admin_menu', $aruba_hispeed_cache_admin, 'aruba_hispeed_cache_admin_menu');
|
110 |
+
$this->loader->add_filter('plugin_action_links_' . ARUBA_HISPEED_CACHE_BASENAME, $aruba_hispeed_cache_admin, 'aruba_hispeed_cache_settings_link');
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* I check if the 'ahsc_enable_purge' option is activated and in this case I add the hooks
|
115 |
+
*/
|
116 |
+
if (! empty($aruba_hispeed_cache_admin->options['ahsc_enable_purge']) && ARUBA_HISPEED_CACHE_PLUGIN) {
|
117 |
+
$this->loader->add_action('admin_bar_menu', $aruba_hispeed_cache_admin, 'aruba_hispeed_cache_toolbar_purge_link', 100);
|
118 |
+
|
119 |
+
// Add actions to purge.
|
120 |
+
$this->loader->add_action('wp_insert_comment', $aruba_hispeed_cache_purger, 'ahsc_wp_insert_comment', 200, 2);
|
121 |
+
$this->loader->add_action('transition_comment_status', $aruba_hispeed_cache_purger, 'ahsc_transition_comment_status', 200, 3);
|
122 |
+
|
123 |
+
$this->loader->add_action('transition_post_status', $aruba_hispeed_cache_purger, 'ahsc_transition_post_status', 20, 3);
|
124 |
+
|
125 |
+
$this->loader->add_action('edit_term', $aruba_hispeed_cache_purger, 'ahsc_edit_term', 20, 3);
|
126 |
+
$this->loader->add_action('delete_term', $aruba_hispeed_cache_purger, 'ahsc_delete_term', 20, 5);
|
127 |
+
|
128 |
+
$this->loader->add_action('check_ajax_referer', $aruba_hispeed_cache_purger, 'ahsc_check_ajax_referer', 20);
|
129 |
+
}
|
130 |
+
|
131 |
+
$this->loader->add_action('admin_bar_init', $aruba_hispeed_cache_purger, 'ahsc_admin_bar_init');
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Run
|
136 |
+
*
|
137 |
+
* Wrap for the Aruba_HiSpeed_Cache_Loader/run method
|
138 |
+
*
|
139 |
+
* @see Aruba_HiSpeed_Cache_Loader/run
|
140 |
+
* @return void
|
141 |
+
*/
|
142 |
+
public function run()
|
143 |
+
{
|
144 |
+
$this->loader->run();
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Get_loader
|
149 |
+
*
|
150 |
+
* @return ArubaHiSpeedCache\Aruba_HiSpeed_Cache_Loader
|
151 |
+
*/
|
152 |
+
public function get_loader()
|
153 |
+
{
|
154 |
+
return $this->loader;
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Undocumented function
|
159 |
+
*
|
160 |
+
* @return void
|
161 |
+
*/
|
162 |
+
private function getConfigs()
|
163 |
+
{
|
164 |
+
return ArubaHiSpeedCacheConfigs::ArubaHiSpeedCache_getConfigs();
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Required_wp_version
|
169 |
+
* Checking the currently installed version and the minimum required version.
|
170 |
+
*
|
171 |
+
* @return bool
|
172 |
+
*/
|
173 |
+
public function required_wp_version(): bool
|
174 |
+
{
|
175 |
+
global $wp_version;
|
176 |
+
|
177 |
+
if (!\version_compare($wp_version, $this->config::MINIMUM_WP, '>=')) {
|
178 |
+
\add_action('admin_notices', array( &$this, 'display_notices' ));
|
179 |
+
\add_action('network_admin_notices', array( &$this, 'display_notices' ));
|
180 |
+
return false;
|
181 |
+
}
|
182 |
+
|
183 |
+
return true;
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Display_notices
|
188 |
+
* Adds the error message in case the function required_wp_version returns false
|
189 |
+
*
|
190 |
+
* @return void
|
191 |
+
*/
|
192 |
+
public function display_notices()
|
193 |
+
{
|
194 |
+
include_once ARUBA_HISPEED_CACHE_BASEPATH . 'admin' .AHSC_DS. 'partials' .AHSC_DS. 'admin-notice-version.php';
|
195 |
+
}
|
196 |
+
}
|
includes/ArubaHiSpeedCacheConfigs.php
ADDED
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @category Wordpress-plugin
|
4 |
+
* @package Aruba-HiSpeed-Cache
|
5 |
+
* @author Aruba Developer <hispeedcache.developer@aruba.it>
|
6 |
+
* @license https://www.gnu.org/licenses/gpl-2.0.html GPLv2 or later
|
7 |
+
* @link run_aruba_hispeed_cache
|
8 |
+
*/
|
9 |
+
declare(strict_types=1);
|
10 |
+
|
11 |
+
namespace ArubaHiSpeedCache\includes;
|
12 |
+
|
13 |
+
use defined;
|
14 |
+
use define;
|
15 |
+
use plugin_dir_path;
|
16 |
+
use current_user_can;
|
17 |
+
use update_site_option;
|
18 |
+
use get_role;
|
19 |
+
|
20 |
+
if (! \class_exists('ArubaHiSpeedCache\includes\ArubaHiSpeedCacheConfigs')) {
|
21 |
+
/**
|
22 |
+
* ArubaHiSpeedCacheConfigs
|
23 |
+
*/
|
24 |
+
|
25 |
+
class ArubaHiSpeedCacheConfigs
|
26 |
+
{
|
27 |
+
/**
|
28 |
+
* USER_CAP array
|
29 |
+
*/
|
30 |
+
const USER_CAP = [
|
31 |
+
'Aruba Hispeed Cache | Config',
|
32 |
+
'Aruba Hispeed Cache | Purge cache'
|
33 |
+
];
|
34 |
+
|
35 |
+
/**
|
36 |
+
* PLUGIN_NAME string
|
37 |
+
*/
|
38 |
+
const PLUGIN_NAME = 'aruba-hispeed-cache';
|
39 |
+
|
40 |
+
/**
|
41 |
+
* PLUGIN_VERSION string
|
42 |
+
*/
|
43 |
+
const PLUGIN_VERSION = '1.0.0';
|
44 |
+
|
45 |
+
/**
|
46 |
+
* MINIMUM_WP string
|
47 |
+
*/
|
48 |
+
const MINIMUM_WP = '5.7';
|
49 |
+
|
50 |
+
/**
|
51 |
+
* OPTIONS array
|
52 |
+
*/
|
53 |
+
const OPTIONS = [
|
54 |
+
'ahsc_enable_purge',
|
55 |
+
'ahsc_purge_homepage_on_edit',
|
56 |
+
'ahsc_purge_homepage_on_del',
|
57 |
+
'ahsc_purge_archive_on_edit',
|
58 |
+
'ahsc_purge_archive_on_del',
|
59 |
+
'ahsc_purge_archive_on_new_comment',
|
60 |
+
'ahsc_purge_archive_on_deleted_comment',
|
61 |
+
'ahsc_purge_page_on_mod',
|
62 |
+
'ahsc_purge_page_on_new_comment',
|
63 |
+
'ahsc_purge_page_on_deleted_comment'
|
64 |
+
];
|
65 |
+
|
66 |
+
/**
|
67 |
+
* PURGE_HOST string
|
68 |
+
* The host colled to purge the cache
|
69 |
+
*/
|
70 |
+
const PURGE_HOST = '127.0.0.1';
|
71 |
+
|
72 |
+
/**
|
73 |
+
* PURGE_PORT string
|
74 |
+
* the port of host.
|
75 |
+
*/
|
76 |
+
const PURGE_PORT = '8889';
|
77 |
+
|
78 |
+
/**
|
79 |
+
* PURGE_TIME_OUT int
|
80 |
+
*/
|
81 |
+
const PURGE_TIME_OUT = 5;
|
82 |
+
|
83 |
+
/**
|
84 |
+
* ArubaHiSpeedCache_set_default_constant
|
85 |
+
*
|
86 |
+
* @param string $file __FILE__ for the root directory of Aruba HiSpeed Cache .
|
87 |
+
* @param string $prefix
|
88 |
+
* @return void
|
89 |
+
*/
|
90 |
+
public static function ArubaHiSpeedCache_set_default_constant(string $file, string $prefix = '')
|
91 |
+
{
|
92 |
+
$plugin_dir_path = \plugin_dir_path($file);
|
93 |
+
|
94 |
+
$default_constants = [
|
95 |
+
'ARUBA_HISPEED_CACHE_PLUGIN' => true,
|
96 |
+
'ARUBA_HISPEED_CACHE_FILE' => $file,
|
97 |
+
'ARUBA_HISPEED_CACHE_BASEPATH' => $plugin_dir_path,
|
98 |
+
'ARUBA_HISPEED_CACHE_BASEURL' => \plugin_dir_url($file),
|
99 |
+
'ARUBA_HISPEED_CACHE_BASENAME' => \plugin_basename($file),
|
100 |
+
'ARUBA_HISPEED_CACHE_OPTIONS_NAME' => 'aruba_hispeed_cache_options',
|
101 |
+
'HOME_URL' => \get_home_url(null, '/'),
|
102 |
+
'AHSC_DS' => DIRECTORY_SEPARATOR,
|
103 |
+
];
|
104 |
+
|
105 |
+
foreach ($default_constants as $name => $value) {
|
106 |
+
if (! \defined($name)) {
|
107 |
+
\define($name, $value);
|
108 |
+
}
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* ArubaHiSpeedCache_activate
|
114 |
+
*
|
115 |
+
* @return void
|
116 |
+
*/
|
117 |
+
public static function ArubaHiSpeedCache_activate()
|
118 |
+
{
|
119 |
+
if (! \current_user_can('activate_plugins')) {
|
120 |
+
return;
|
121 |
+
}
|
122 |
+
|
123 |
+
$role = \get_role('administrator');
|
124 |
+
|
125 |
+
if (empty($role)) {
|
126 |
+
\update_site_option(
|
127 |
+
'wp_aruba_hispeed_cache_init_check',
|
128 |
+
__('Sorry, you need to be an administrator to use Aruba HiSpeed Cache.', 'aruba-hispeed-cache')
|
129 |
+
);
|
130 |
+
return;
|
131 |
+
}
|
132 |
+
|
133 |
+
//add the user cap to admin user
|
134 |
+
foreach (self::USER_CAP as $cap) {
|
135 |
+
$role->add_cap($cap);
|
136 |
+
}
|
137 |
+
|
138 |
+
//get the option
|
139 |
+
$options = \get_site_option(ARUBA_HISPEED_CACHE_OPTIONS_NAME);
|
140 |
+
|
141 |
+
if (! $options) {
|
142 |
+
$options = self::ArubaHiSpeedCache_get_default_settings();
|
143 |
+
}
|
144 |
+
|
145 |
+
\update_site_option(ARUBA_HISPEED_CACHE_OPTIONS_NAME, $options);
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* ArubaHiSpeedCache_get_dependencies
|
150 |
+
*
|
151 |
+
* @return array list of files
|
152 |
+
*/
|
153 |
+
// public static function ArubaHiSpeedCache_get_dependencies(string $plugin_dir_path = '')
|
154 |
+
// {
|
155 |
+
// return [
|
156 |
+
// $plugin_dir_path . 'includes' .AHSC_DS. 'ArubaHiSpeedCacheLoader.php',
|
157 |
+
// $plugin_dir_path . 'includes' .AHSC_DS. 'ArubaHiSpeedCachei18n.php',
|
158 |
+
// $plugin_dir_path . 'includes' .AHSC_DS. 'ArubaHiSpeedCacheAdmin.php',
|
159 |
+
// $plugin_dir_path . 'includes' .AHSC_DS. 'ArubaHiSpeedCachePurger.php',
|
160 |
+
// $plugin_dir_path . 'includes' .AHSC_DS. 'ArubaHiSpeedCacheWpPurger.php'
|
161 |
+
// ];
|
162 |
+
// }
|
163 |
+
|
164 |
+
/**
|
165 |
+
* ArubaHiSpeedCache_deactivate
|
166 |
+
*
|
167 |
+
* @return void
|
168 |
+
*/
|
169 |
+
public static function ArubaHiSpeedCache_deactivate()
|
170 |
+
{
|
171 |
+
if (! \current_user_can('activate_plugins')) {
|
172 |
+
return;
|
173 |
+
}
|
174 |
+
|
175 |
+
$role = \get_role('administrator');
|
176 |
+
|
177 |
+
foreach (self::USER_CAP as $cap) {
|
178 |
+
$role->remove_cap($cap);
|
179 |
+
}
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* ArubaHiSpeedCache_get_default_settings
|
184 |
+
*
|
185 |
+
* @return array $default_settings
|
186 |
+
*/
|
187 |
+
public static function ArubaHiSpeedCache_get_default_settings()
|
188 |
+
{
|
189 |
+
$dafault_value = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
|
190 |
+
|
191 |
+
return \array_combine(self::OPTIONS, $dafault_value);
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* ArubaHiSpeedCache_getConfigs
|
196 |
+
*
|
197 |
+
* @return object self
|
198 |
+
*/
|
199 |
+
public static function ArubaHiSpeedCache_getConfigs()
|
200 |
+
{
|
201 |
+
return new self;
|
202 |
+
}
|
203 |
+
}
|
204 |
+
}
|
includes/ArubaHiSpeedCacheLoader.php
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @category Wordpress-plugin
|
4 |
+
* @package Aruba-HiSpeed-Cache
|
5 |
+
* @author Aruba Developer <hispeedcache.developer@aruba.it>
|
6 |
+
* @license https://www.gnu.org/licenses/gpl-2.0.html GPLv2 or later
|
7 |
+
* @link run_aruba_hispeed_cache
|
8 |
+
*/
|
9 |
+
declare(strict_types=1);
|
10 |
+
|
11 |
+
namespace ArubaHiSpeedCache\includes;
|
12 |
+
|
13 |
+
use \Exception;
|
14 |
+
use \Throwable;
|
15 |
+
use \add_action;
|
16 |
+
use \add_filter;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Undocumented class
|
20 |
+
*/
|
21 |
+
class ArubaHiSpeedCacheLoader
|
22 |
+
{
|
23 |
+
/**
|
24 |
+
* Actions
|
25 |
+
*
|
26 |
+
* @var array
|
27 |
+
*/
|
28 |
+
protected $actions = [];
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Filters
|
32 |
+
*
|
33 |
+
* @var array
|
34 |
+
*/
|
35 |
+
protected $filters = [];
|
36 |
+
|
37 |
+
// public function __construct()
|
38 |
+
// {}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Add_action
|
42 |
+
* Wrap for the wp method add_action
|
43 |
+
*
|
44 |
+
* @see https://developer.wordpress.org/reference/functions/add_action/
|
45 |
+
*
|
46 |
+
* @param string $hook
|
47 |
+
* @param object $component
|
48 |
+
* @param string $callback
|
49 |
+
* @param integer $priority
|
50 |
+
* @param integer $accepted_args
|
51 |
+
* @return void
|
52 |
+
*/
|
53 |
+
public function add_action(string $hook, object $component, string $callback, int $priority = 10, int $accepted_args = 1)
|
54 |
+
{
|
55 |
+
$this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args);
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Add_filter
|
60 |
+
*
|
61 |
+
* Wrap for the wp method add_filter
|
62 |
+
*
|
63 |
+
* @see https://developer.wordpress.org/reference/functions/add_filter/
|
64 |
+
*
|
65 |
+
* @param string $hook
|
66 |
+
* @param object $component
|
67 |
+
* @param string $callback
|
68 |
+
* @param integer $priority
|
69 |
+
* @param integer $accepted_args
|
70 |
+
* @return void
|
71 |
+
*/
|
72 |
+
public function add_filter(string $hook, object $component, string $callback, int $priority = 10, int $accepted_args = 1)
|
73 |
+
{
|
74 |
+
$this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args);
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Add
|
79 |
+
*
|
80 |
+
* Helper method for populating arrays filters and actions
|
81 |
+
*
|
82 |
+
* @param string $hooks
|
83 |
+
* @param string $hook
|
84 |
+
* @param object $component
|
85 |
+
* @param string $callback
|
86 |
+
* @param integer $priority
|
87 |
+
* @param integer $accepted_args
|
88 |
+
* @return array
|
89 |
+
*/
|
90 |
+
private function add(array $hooks, string $hook, object $component, string $callback, int $priority, int $accepted_args): array
|
91 |
+
{
|
92 |
+
$hooks[] = array(
|
93 |
+
'hook' => $hook,
|
94 |
+
'component' => $component,
|
95 |
+
'callback' => $callback,
|
96 |
+
'priority' => $priority,
|
97 |
+
'accepted_args' => $accepted_args,
|
98 |
+
);
|
99 |
+
|
100 |
+
return $hooks;
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Run
|
105 |
+
*
|
106 |
+
* Runner method for queuing actions and filters
|
107 |
+
*
|
108 |
+
* @return void
|
109 |
+
*/
|
110 |
+
public function run()
|
111 |
+
{
|
112 |
+
if (!empty($this->filters)) {
|
113 |
+
foreach ($this->filters as $hook) {
|
114 |
+
\add_filter($hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args']);
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
if (!empty($this->actions)) {
|
119 |
+
foreach ($this->actions as $hook) {
|
120 |
+
\add_action($hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args']);
|
121 |
+
}
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
includes/ArubaHiSpeedCachePurger.php
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|