PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 0.3.3
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v0.3.3
1.7.1 1.7.0 1.6.0 1.5.2 trunk 0.1 0.2.0 0.2.1 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 1.0 1.1 1.2 1.3.1 1.4.0 1.4.1 1.5.0 1.5.1 All 26 releases
flywp / includes / Admin / Fastcgi_Cache.php

Fastcgi_Cache.php in FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel 0.3.3, at includes/Admin/Fastcgi_Cache.php

140 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FlyWP\Admin;
4
5 use FlyWP\Admin;
6
7 class Fastcgi_Cache {
8
9 /**
10 * Class constructor.
11 */
12 public function __construct() {
13 add_action( 'load-' . Admin::SCREEN_NAME, [ $this, 'save_settings' ] );
14 add_action( 'load-' . Admin::SCREEN_NAME, [ $this, 'handle_cleanup' ] );
15 add_action( 'load-' . Admin::SCREEN_NAME, [ $this, 'handle_enable_disable' ] );
16 }
17
18 /**
19 * Get enable/disable url.
20 *
21 * @param string $action
22 *
23 * @return string
24 */
25 public function enable_disable_url( $action = 'enable' ) {
26 return wp_nonce_url(
27 add_query_arg(
28 [
29 'flywp-action' => 'toggle-fastcgi-cache',
30 'type' => $action,
31 ],
32 flywp()->admin->page_url()
33 ),
34 'fly-fastcgi-toggle-cache'
35 );
36 }
37
38 /**
39 * Handle cache cleanup.
40 *
41 * @return void
42 */
43 public function handle_cleanup() {
44 if ( ! isset( $_GET['flywp-action'] ) || 'purge-fastcgi-cache' !== $_GET['flywp-action'] ) {
45 return;
46 }
47
48 if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( $_GET['_wpnonce'], 'fly-fastcgi-purge-cache' ) ) {
49 return;
50 }
51
52 if ( ! current_user_can( 'manage_options' ) ) {
53 return;
54 }
55
56 $page_id = isset( $_GET['page_id'] ) ? absint( $_GET['page_id'] ) : 0;
57
58 if ( $page_id ) {
59 flywp()->fastcgi->purge_cache_by_url( get_permalink( $page_id ) );
60 } else {
61 flywp()->fastcgi->clear_cache();
62 }
63
64 wp_safe_redirect( admin_url( 'index.php?page=flywp&fly-notice=fastcgi-purged' ) );
65 exit;
66 }
67
68 /**
69 * Save cache settings.
70 *
71 * @return void
72 */
73 public function save_settings() {
74 if ( ! isset( $_POST['flywp-fastcgi-nonce'] ) ) {
75 return;
76 }
77
78 if ( ! wp_verify_nonce( $_POST['flywp-fastcgi-nonce'], 'flywp-fastcgi-nonce' ) ) {
79 return;
80 }
81
82 if ( ! current_user_can( 'manage_options' ) ) {
83 return;
84 }
85
86 $settings = [];
87 $keys = [
88 'home-purge-created' => 'home_created',
89 'home-purge-deleted' => 'home_deleted',
90 // 'single-post-created' => 'single_modified',
91 // 'single-post-comment' => 'single_comment',
92 ];
93
94 foreach ( $keys as $form_key => $settings_key ) {
95 $settings[ $settings_key ] = isset( $_POST[ $form_key ] ) ? true : false;
96 }
97
98 $old_settings = flywp()->fastcgi->settings();
99 $settings = array_merge( $old_settings, $settings );
100
101 update_option( flywp()->fastcgi::SETTINGS_KEY, $settings );
102
103 wp_safe_redirect( admin_url( 'index.php?page=flywp&fly-notice=fastcgi-saved' ) );
104 exit;
105 }
106
107 /**
108 * Handle enable/disable.
109 *
110 * @return void
111 */
112 public function handle_enable_disable() {
113 if ( ! isset( $_GET['flywp-action'] ) || 'toggle-fastcgi-cache' !== $_GET['flywp-action'] ) {
114 return;
115 }
116
117 if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( $_GET['_wpnonce'], 'fly-fastcgi-toggle-cache' ) ) {
118 return;
119 }
120
121 if ( ! current_user_can( 'manage_options' ) ) {
122 return;
123 }
124
125 $valid_types = [ 'enable', 'disable' ];
126 $type = isset( $_GET['type'] ) && in_array( $_GET['type'], $valid_types ) ? $_GET['type'] : 'enable';
127
128 $settings = flywp()->fastcgi->settings();
129 $settings['enabled'] = $type === 'enable' ? true : false;
130 $notice = $type === 'enable' ? 'fastcgi-enabled' : 'fastcgi-disabled';
131
132 $reponse = flywp()->flyapi->cache_toggle( $type );
133
134 update_option( flywp()->fastcgi::SETTINGS_KEY, $settings );
135
136 wp_safe_redirect( admin_url( 'index.php?page=flywp&fly-notice=' . $notice ) );
137 exit;
138 }
139 }
140