Changeset 2373503
- Timestamp:
- 09/02/2020 03:07:31 AM (6 years ago)
- Location:
- cynderhost/trunk
- Files:
-
- 2 edited
-
README.txt (modified) (3 diffs)
-
cynderhost.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cynderhost/trunk/README.txt
r2353317 r2373503 3 3 Donate link: https://cynderhost.com 4 4 Tags: cache, performance, cynderhost 5 Requires at least: 3.0.16 Tested up to: 5. 4.27 Stable tag: 5. 4.25 Requires at least: 4.0.1 6 Tested up to: 5.5.0 7 Stable tag: 5.5.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Provides an easy interface to clear the CynderHost CDN cache automatically and manually.11 Provides an easy interface to clear the CynderHost CDN & local cache automatically and manually. 12 12 13 13 == Description == … … 15 15 This plugin is only compatible with functional sites hosted on [CynderHost High Performance](https://cynderhost.com/high-performance-hosting). 16 16 17 This plugin will use the [CynderHost HP API](https://api.cynderhost.com/high-performance/cache/cdn/purge/) to purge the cacheautomatically when a post is published, updated, or delete, and when a plugin is installed. This will also add a button to the admin interface allowing you to purge the cache manually.17 This plugin will use the CynderHost High Performance API to purge the CDN and local caches automatically when a post is published, updated, or delete, and when a plugin is installed. This will also add a button to the admin interface allowing you to purge the cache manually. 18 18 19 An API key is required for this plugin to work, which you can obtain from the hosting panel for your site under "CDN" 19 An API key is required for this plugin to work, which you can obtain from the hosting panel for your site under "CDN" as well as the hostname of your hosting server. 20 20 21 Use of this plugin requires acceptance of CynderHost's [terms of service](https://cynderhost.com/terms-of-service) 22 As well as [privacy policy](https://cynderhost.com/privacy-policy) 21 Use of this plugin requires acceptance of CynderHost's [terms of service](https://cynderhost.com/terms-of-service) as well as [privacy policy](https://cynderhost.com/privacy-policy) 23 22 24 23 … … 30 29 Upload/activate the Plugin 31 30 32 Go to the settings page titled "CynderHost CDN" and insert your api key for the site.31 Go to the settings page titled "CynderHost CDN" and insert your api key & hostname for the site. -
cynderhost/trunk/cynderhost.php
r2354247 r2373503 10 10 * Plugin URI: https://cynderhost.com 11 11 * Description: Provides an easy interface to clear the CynderHost CDN cache, both automatically and programmatically. 12 * Version: 1. 0.512 * Version: 1.1.1 13 13 * Author: CynderHost 14 14 * Author URI: https://profiles.wordpress.org/cynderhost/ … … 39 39 $cynderhost_cdn_settings_options = get_option( 'cynderhost_cdn_settings_option_name' ); // Array of All Options 40 40 $api_key = $cynderhost_cdn_settings_options['api_key_0']; 41 $hostname = $cynderhost_cdn_settings_options['hostname_1']; 41 42 //cache purge endpoint 42 43 $response = wp_remote_post( "https://api.cynderhost.com/high-performance/cache/cdn/purge/", array( … … 57 58 $result = json_decode($response['body'], true)['status']; 58 59 } 60 $response = wp_remote_post( "https://api.cynderhost.com/high-performance/cache/local/purge/", array( 61 'method' => 'POST', 62 'timeout' => 10, 63 'redirection' => 5, 64 'blocking' => $resp, 65 'body' => array( 66 'API' => "$api_key", 67 'HOST' => "$hostname" 68 ) 69 ) 70 ); 71 //Non-standard Error, 5XX, 4XX 72 if ( is_wp_error( $response ) ) { 73 $error_message = $response->get_error_message(); 74 $result = "Something went wrong: $error_message"; 75 } else { 76 $result2 = json_decode($response['body'], true)['status']; 77 $result = ($result2 == "Success. Local server cache has been successfully purged.") ? $result : $result2; 78 } 59 79 $result = $resp ? $result : "Cache purge request sent."; 60 80 return $result; … … 69 89 } 70 90 91 /* 92 * Sets the local cache status via api 93 */ 94 function cynderhost_set_stat($boole, $hostname, $api_key){ 95 $response = wp_remote_post( "https://api.cynderhost.com/high-performance/cache/local/status/", array( 96 'method' => 'POST', 97 'timeout' => 10, 98 'redirection' => 5, 99 'blocking' => false, 100 'body' => array( 101 'API' => "$api_key", 102 'HOST' => "$hostname", 103 "STATUS" => "$boole" 104 ) 105 ) 106 ); 107 return true; 108 } 71 109 /** 72 110 * Displays a notice with cache purge status … … 169 207 register_setting( 170 208 'cynderhost_cdn_settings_option_group', // option_group 171 'cynderhost_cdn_settings_option_name', // option_name 209 'cynderhost_cdn_settings_option_name', 210 // option_name 172 211 array( $this, 'cynderhost_cdn_settings_sanitize' ) // sanitize_callback 173 212 ); 213 174 214 175 215 add_settings_section( … … 187 227 'cynderhost_cdn_settings_setting_section' // section 188 228 ); 229 230 add_settings_field( 231 'hostname_1', // id 232 'Hostname', // title 233 array( $this, 'hostname_1_callback' ), // callback 234 'cynderhost-cdn-settings-admin', // page 235 'cynderhost_cdn_settings_setting_section' // section 236 ); 237 238 add_settings_field( 239 'server_page_cache_3', // id 240 'Server Page Cache', // title 241 array( $this, 'server_page_cache_3_callback' ), // callback 242 'cynderhost-cdn-settings-admin', // page 243 'cynderhost_cdn_settings_setting_section' // section 244 ); 189 245 } 190 246 … … 194 250 $sanitary_values['api_key_0'] = sanitize_text_field( $input['api_key_0'] ); 195 251 } 252 253 if ( isset( $input['hostname_1'] ) ) { 254 $sanitary_values['hostname_1'] = sanitize_text_field( $input['hostname_1'] ); 255 } 256 if ( get_option( 'cynderhost_cdn_settings_option_name')['server_page_cache_3'] != $input['server_page_cache_3']){ 257 cynderhost_set_stat(( isset( $input['server_page_cache_3']) && $input['server_page_cache_3'] === 'server_page_cache_3' ) ? 'active' : "inactive", $sanitary_values['hostname_1'] ,$sanitary_values['api_key_0'] ); 258 } 259 if ( isset( $input['server_page_cache_3'] ) ) { 260 $sanitary_values['server_page_cache_3'] = $input['server_page_cache_3']; 261 } 196 262 do_cache_cynderhost_purge(true); 197 263 return $sanitary_values; … … 203 269 '<input class="regular-text" type="text" name="cynderhost_cdn_settings_option_name[api_key_0]" id="api_key_0" value="%s">', 204 270 isset( $this->cynderhost_cdn_settings_options['api_key_0'] ) ? esc_attr( $this->cynderhost_cdn_settings_options['api_key_0']) : '' 271 ); 272 } 273 274 public function hostname_1_callback() { 275 printf( 276 '<input class="regular-text" type="text" name="cynderhost_cdn_settings_option_name[hostname_1]" id="hostname_1" value="%s"><p>The hostname of your server, derived from the panel url (ie, for proton.cynderhost.com the hostname proton)', 277 isset( $this->cynderhost_cdn_settings_options['hostname_1'] ) ? esc_attr( $this->cynderhost_cdn_settings_options['hostname_1']) : '' 278 ); 279 } 280 281 public function server_page_cache_3_callback() { 282 printf( 283 '<input type="checkbox" name="cynderhost_cdn_settings_option_name[server_page_cache_3]" id="server_page_cache_3" value="server_page_cache_3" %s> <label for="server_page_cache_3">Whether or not to enable the local, serverside page caching. </label>', 284 ( isset( $this->cynderhost_cdn_settings_options['server_page_cache_3'] ) && $this->cynderhost_cdn_settings_options['server_page_cache_3'] === 'server_page_cache_3' ) ? 'checked' : '' 205 285 ); 206 286 }
Note: See TracChangeset
for help on using the changeset viewer.