PluginProbe
JCH Optimize / trunk
JCH Optimize vtrunk
6.0.2 6.0.1 trunk 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.10.0 2.2.0 2.2.1 All 58 releases
jch-optimize / src / Controller / CleanCache.php

CleanCache.php in JCH Optimize trunk, at src/Controller/CleanCache.php

66 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * JCH Optimize - Performs several front-end optimizations for fast downloads
5 *
6 * @package jchoptimize/wordpress-platform
7 * @author Samuel Marshall <samuel@jch-optimize.net>
8 * @copyright Copyright (c) 2021 Samuel Marshall / JCH Optimize
9 * @license GNU/GPLv3, or later. See LICENSE file
10 *
11 * If LICENSE file missing, see <http://www.gnu.org/licenses/>.
12 */
13
14 namespace JchOptimize\WordPress\Controller;
15
16 use _JchOptimizeVendor\V91\Joomla\Input\Input;
17 use JchOptimize\Core\Model\CacheMaintainer;
18 use JchOptimize\Core\Mvc\Controller;
19 use JchOptimize\WordPress\Log\WordpressNoticeLogger;
20
21 use function __;
22 use function JchOptimize\WordPress\base64_decode_url;
23 use function time;
24 use function update_option;
25 use function wp_redirect;
26
27 class CleanCache extends Controller
28 {
29 use AuthorizesAdminRequestsTrait;
30
31 public function __construct(private CacheMaintainer $cacheMaintainer, ?Input $input)
32 {
33 parent::__construct($input);
34 }
35
36 public function execute(): bool
37 {
38 $this->authorizeAnyCapability(['manage_options', 'jch_clear_page_cache']);
39 /** @var WordpressNoticeLogger $logger */
40 $logger = $this->logger;
41 /** @var Input $input */
42 $input = $this->getInput();
43
44 if ($this->cacheMaintainer->cleanCache()) {
45 update_option('jch_optimize_cache_last_cleared', time(), false);
46 $logger->success(__('Cache deleted successfully!', 'jch-optimize'));
47
48 $result = true;
49 } else {
50 $logger->error(__('Error cleaning cache!', 'jch-optimize'));
51
52 $result = false;
53 }
54
55 if (($return = (string)$input->get('return')) != '') {
56 $redirect = base64_decode_url($return);
57 } else {
58 $redirect = 'options-general.php?page=jch_optimize';
59 }
60
61 wp_redirect($redirect);
62
63 return $result;
64 }
65 }
66