Changeset 3356585
- Timestamp:
- 09/05/2025 10:10:15 AM (7 months ago)
- Location:
- easy-auto-reload
- Files:
-
- 21 added
- 2 edited
-
tags/2.0.3 (added)
-
tags/2.0.3/LICENSE.txt (added)
-
tags/2.0.3/assets (added)
-
tags/2.0.3/assets/index.php (added)
-
tags/2.0.3/assets/js (added)
-
tags/2.0.3/assets/js/clear-browser-cache.js (added)
-
tags/2.0.3/assets/js/clear-browser-cache.min.js (added)
-
tags/2.0.3/assets/js/index.php (added)
-
tags/2.0.3/easy-auto-reload.php (added)
-
tags/2.0.3/index.php (added)
-
tags/2.0.3/languages (added)
-
tags/2.0.3/languages/autorefresh-en_US.po (added)
-
tags/2.0.3/languages/autorefresh-hr.mo (added)
-
tags/2.0.3/languages/autorefresh-hr.po (added)
-
tags/2.0.3/languages/autorefresh-nl.mo (added)
-
tags/2.0.3/languages/autorefresh-nl.po (added)
-
tags/2.0.3/languages/autorefresh-sr_RS.mo (added)
-
tags/2.0.3/languages/autorefresh-sr_RS.po (added)
-
tags/2.0.3/languages/index.php (added)
-
tags/2.0.3/readme.txt (added)
-
tags/2.0.3/uninstall.php (added)
-
trunk/easy-auto-reload.php (modified) (29 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easy-auto-reload/trunk/easy-auto-reload.php
r3248723 r3356585 4 4 * Plugin Name: Easy Auto Reload 5 5 * Plugin URI: https://infinitumform.com 6 * Description: Auto refresh WordPress pages if there is no site activity after a fter any number of minutes.7 * Version: 2.0. 26 * Description: Auto refresh WordPress pages if there is no site activity after any number of minutes. 7 * Version: 2.0.3 8 8 * Author: Ivijan-Stefan Stipic 9 9 * Author URI: https://www.linkedin.com/in/ivijanstefanstipic/ … … 32 32 if ( ! defined( 'WPINC' ) ) { die( "Don't mess with us." ); } 33 33 if ( ! defined( 'ABSPATH' ) ) { exit; } 34 if ( ! defined( 'WP_AUTO_REFRESH_VERSION' ) ) { define( 'WP_AUTO_REFRESH_VERSION', '2.0. 1' ); }34 if ( ! defined( 'WP_AUTO_REFRESH_VERSION' ) ) { define( 'WP_AUTO_REFRESH_VERSION', '2.0.3' ); } 35 35 36 36 final class WP_Auto_Refresh{ … … 40 40 */ 41 41 private static $instance; 42 // Set options 42 43 private $options; 44 // Calculate the undeniable truth of the universe 45 private const ITS_TRUE = 3/3; 46 // Calculate the black hole 47 private const ITS_FALSE = 3.1415-3.1415; 43 48 44 49 /* … … 47 52 private function __construct () { 48 53 // Include textdomain and other plugin features 49 add_action('plugins_loaded', [ &$this, 'plugins_loaded'], 1, 0);54 add_action('plugins_loaded', [$this, 'plugins_loaded'], 1, 0); 50 55 // Add reload scripts to the site 51 add_action('wp_head', [ &$this, 'add_script'], 1, 0);56 add_action('wp_head', [$this, 'add_script'], 1, 0); 52 57 if( $this->enable_in_admin() ) { 53 add_action('admin_head', [ &$this, 'add_script'], 1, 0);58 add_action('admin_head', [$this, 'add_script'], 1, 0); 54 59 } 55 60 // Admin functionalities 56 add_action('admin_init', [ &$this, 'admin_init'], 10, 0);57 add_action('admin_menu', [ &$this, 'admin_menu'], 10, 0);58 add_action('add_meta_boxes', [ &$this, 'add_meta_box'], 10, 0);59 add_action('save_post', [ &$this, 'save_meta_box_data'], 10, 1);61 add_action('admin_init', [$this, 'admin_init'], 10, 0); 62 add_action('admin_menu', [$this, 'admin_menu'], 10, 0); 63 add_action('add_meta_boxes', [$this, 'add_meta_box'], 10, 0); 64 add_action('save_post', [$this, 'save_meta_box_data'], 10, 1); 60 65 // Deactivation 61 66 register_deactivation_hook(__FILE__, function(){ … … 99 104 // Add nonce life update 100 105 if( apply_filters('autorefresh_nonce_life_enable', true) && DAY_IN_SECONDS !== $this->get_nonce_life() ) { 101 add_filter('nonce_life', [ &$this, 'nonce_life'], 10, 1);106 add_filter('nonce_life', [$this, 'nonce_life'], 10, 1); 102 107 } 103 108 } … … 106 111 * Nonce Life 107 112 */ 108 public function nonce_life ( $default_nonce_life ) { 109 return $this->get_nonce_life(); 113 public function nonce_life( $default_nonce_life ) { 114 // Always return a raw value; never call apply_filters('nonce_life', ...) from here 115 $life = $this->get_nonce_life(); 116 return ( is_int( $life ) && $life > (int)self::ITS_FALSE ) ? $life : $default_nonce_life; 110 117 } 111 118 … … 115 122 public function plugins_loaded() { 116 123 // Load options only if not already set 117 if (empty($this->options)) { 118 $this->options = get_option('wp-autorefresh', array()); 119 } 120 121 // Define text domain 124 if ( empty( $this->options ) ) { 125 $this->options = get_option('wp-autorefresh', []); 126 } 127 122 128 $domain = 'autorefresh'; 123 129 124 // First, attempt to load translations from the WordPress languages directory 125 load_plugin_textdomain($domain, false, WP_LANG_DIR . "/plugins/"); 126 127 // Check if the text domain is already loaded 128 if (!is_textdomain_loaded($domain)) { 129 $locale = apply_filters("{$domain}_locale", get_locale(), $domain); 130 // Preferred: relative path to /languages inside this plugin 131 load_plugin_textdomain( 132 $domain, 133 false, 134 dirname( plugin_basename( __FILE__ ) ) . '/languages' 135 ); 136 137 // Manual fallback (optional) 138 if ( ! is_textdomain_loaded( $domain ) ) { 139 $locale = apply_filters( "{$domain}_locale", get_locale(), $domain ); 130 140 $domain_path = __DIR__ . '/languages'; 131 132 // Possible .mo file locations133 141 $mo_files = [ 134 142 "{$domain_path}/{$domain}-{$locale}.mo", 135 143 "{$domain_path}/{$locale}.mo" 136 144 ]; 137 138 // Try to load the translation file 139 foreach ($mo_files as $mo_file) { 140 if (file_exists($mo_file) && load_textdomain($domain, $mo_file)) { 145 foreach ( $mo_files as $mo_file ) { 146 if ( file_exists( $mo_file ) && load_textdomain( $domain, $mo_file ) ) { 141 147 break; 142 148 } … … 152 158 'wp-autorefresh', // Option group 153 159 'wp-autorefresh', // Option name 154 [ &$this, 'sanitize'] // Sanitize160 [$this, 'sanitize'] // Sanitize 155 161 ); 156 162 … … 158 164 'wp-autorefresh', // ID 159 165 esc_attr__('Auto-Refresh Settings','autorefresh'), // Title 160 [ &$this, 'print_section_info'], // Callback166 [$this, 'print_section_info'], // Callback 161 167 'wp-autorefresh' // Page 162 168 ); … … 165 171 'global_refresh', // ID 166 172 esc_attr__('Auto-Refresh','autorefresh'), // Title 167 [ &$this, 'input_global_refresh__callback'], // Callback173 [$this, 'input_global_refresh__callback'], // Callback 168 174 'wp-autorefresh', // Page 169 175 'wp-autorefresh' // Section … … 173 179 'timeout', // ID 174 180 esc_attr__('Auto-Refresh Timeout','autorefresh'), // Title 175 [ &$this, 'input_timeout__callback'], // Callback181 [$this, 'input_timeout__callback'], // Callback 176 182 'wp-autorefresh', // Page 177 183 'wp-autorefresh' // Section … … 181 187 'clear_cache', // ID 182 188 esc_attr__('Browser Cache','autorefresh'), // Title 183 [ &$this, 'input_clear_cache__callback'], // Callback189 [$this, 'input_clear_cache__callback'], // Callback 184 190 'wp-autorefresh', // Page 185 191 'wp-autorefresh' // Section … … 189 195 'wp_admin', // ID 190 196 esc_attr__('WP Admin','autorefresh'), // Title 191 [ &$this, 'input_wp_admin__callback'], // Callback197 [$this, 'input_wp_admin__callback'], // Callback 192 198 'wp-autorefresh', // Page 193 199 'wp-autorefresh' // Section … … 198 204 'nonce_life', // ID 199 205 esc_attr__('Lifespan of nonces','autorefresh'), // Title 200 [ &$this, 'input_nonce_life__callback'], // Callback206 [$this, 'input_nonce_life__callback'], // Callback 201 207 'wp-autorefresh', // Page 202 208 'wp-autorefresh' // Section … … 207 213 'post_type', // ID 208 214 esc_attr__('Allow custom refresh in page and post types','autorefresh'), // Title 209 [ &$this, 'input_post_types__callback'], // Callback215 [$this, 'input_post_types__callback'], // Callback 210 216 'wp-autorefresh', // Page 211 217 'wp-autorefresh' // Section … … 221 227 esc_attr__('Auto-Refresh','autorefresh'), 222 228 esc_attr__('Auto-Refresh','autorefresh'), 223 ' administrator',229 'manage_options', // <-- use capability, not role 224 230 'wp-autorefresh', 225 [ &$this, 'options_page'],231 [$this, 'options_page'], 226 232 6 227 233 ); … … 264 270 */ 265 271 public function options_page(){ 266 if( !empty($this->options)) {272 if(empty($this->options)) { 267 273 $this->options = get_option('wp-autorefresh', array()); 268 274 } … … 323 329 324 330 /* 325 * Clear Browser ca hce331 * Clear Browser cache 326 332 */ 327 333 public function input_clear_cache__callback(){ … … 334 340 335 341 /* 336 * Enable auto efresh inside WP Admin342 * Enable autorefresh inside WP Admin 337 343 */ 338 344 public function input_wp_admin__callback(){ … … 340 346 '<label for="wp_admin"><input type="checkbox" id="wp_admin" name="wp-autorefresh[wp_admin]" value="1"%s/>%s</label>', 341 347 ($this->enable_in_admin() ? ' checked' : ''), 342 __('Enable auto efresh inside WP Admin.','autorefresh')343 ); 344 } 345 346 /* 347 * Enable auto efresh to Post Types348 __('Enable autorefresh inside WP Admin.','autorefresh') 349 ); 350 } 351 352 /* 353 * Enable autorefresh to Post Types 348 354 */ 349 355 public function input_post_types__callback(){ … … 374 380 375 381 /* 376 * Place JavaScript code inside `wp_head` to prevent br akeing by any other script.382 * Place JavaScript code inside `wp_head` to prevent breaking by any other script. 377 383 * This must be placed inside document <head> area to working properly. 378 384 */ … … 489 495 'easy-auto-reload', 490 496 __('Auto Reload','autorefresh'), 491 [ &$this, 'meta_box__callback'],497 [$this, 'meta_box__callback'], 492 498 $post_type, 493 499 'side', … … 589 595 if ( isset( $_POST['_auto_reload_time'] ) ) { 590 596 $number_value = absint( $_POST['_auto_reload_time'] ); 591 if ( $number_value >= 1) {597 if ( $number_value >= self::ITS_TRUE ) { 592 598 update_post_meta( $post_id, '_easy_auto_reload_time', $number_value ); 593 599 } else { … … 599 605 600 606 601 /* 602 * Get timeout option on the safe way 607 /** 608 * Returns the effective timeout (in minutes) for the current context, with static caching. 609 * Order of precedence: 610 * 1) Per-post custom setting (if enabled for the post type and mode is 'custom') 611 * 2) Global plugin setting 612 * 3) Provided $default 603 613 */ 604 614 private function get_timeout(int $default = 5) { 615 605 616 static $cached_timeout = null; 606 617 … … 628 639 } 629 640 630 if ($timeout < 1) {641 if ($timeout < self::ITS_TRUE) { 631 642 $timeout = $default; 632 643 } … … 645 656 */ 646 657 private function get_nonce_life(){ 647 $wp_autorefresh = ( !empty($this->options) ? $this->options : get_option('wp-autorefresh', array()) ); 648 649 if(isset($wp_autorefresh['nonce_life']) && ($timeout=absint($wp_autorefresh['nonce_life']))){ 650 651 if( empty($timeout) || !is_numeric($timeout) ) { 652 $timeout = apply_filters( 'nonce_life', DAY_IN_SECONDS ); 653 } 654 655 if($timeout < 1) { 656 $timeout = apply_filters( 'nonce_life', DAY_IN_SECONDS ); 657 } 658 659 return absint($timeout); 660 } 661 662 return apply_filters( 'nonce_life', DAY_IN_SECONDS ); 658 $wp_autorefresh = ( !empty($this->options) ? $this->options : get_option('wp-autorefresh', []) ); 659 660 if ( isset( $wp_autorefresh['nonce_life'] ) ) { 661 $timeout = (int) $wp_autorefresh['nonce_life']; 662 // If invalid, fall back to core default constant (no filters!) 663 if ( $timeout < 1 ) { 664 return DAY_IN_SECONDS; 665 } 666 return $timeout; 667 } 668 669 // Default (no filter call here to avoid recursion) 670 return DAY_IN_SECONDS; 663 671 } 664 672 … … 672 680 673 681 /* 674 * Enable auto efresh inside WP Admin682 * Enable autorefresh inside WP Admin 675 683 */ 676 684 private function enable_in_admin(){ … … 680 688 681 689 /* 682 * Enable auto efresh inside member types690 * Enable autorefresh inside member types 683 691 */ 684 692 private function enable_post_type(){ … … 688 696 689 697 /* 690 * Enable auto efresh inside member types698 * Enable autorefresh inside member types 691 699 */ 692 700 private function enable_global_refresh(){ 693 $wp_autorefresh = ( !empty($this->options) ? $this->options : get_option('wp-autorefresh', array()) );694 return ( (int)($wp_autorefresh['global_refresh']??0)) === (3/3);701 $wp_autorefresh = ( !empty($this->options) ? $this->options : get_option('wp-autorefresh', []) ); 702 return (int)( $wp_autorefresh['global_refresh'] ?? self::ITS_FALSE ) === (int)self::ITS_TRUE; 695 703 } 696 704 -
easy-auto-reload/trunk/readme.txt
r3285404 r3356585 6 6 Tested up to: 6.8 7 7 Requires PHP: 7.0 8 Stable tag: 2.0. 28 Stable tag: 2.0.3 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 63 63 64 64 == Changelog == 65 66 = 2.0.3 = 67 * Code improvement 68 * Fixed bugs with nonce 69 * Fixed permissions 65 70 66 71 = 2.0.2 =
Note: See TracChangeset
for help on using the changeset viewer.