PluginProbe
ezCache / 1.3.11
ezCache v1.3.11
2.6.5 2.6.4 2.6.2 2.6.3 2.6.1 2.6.0 2.5.6 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5 2.2.1 2.2.2 trunk 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.3 1.3.1 1.3.10 1.3.11 All 49 releases
ezcache / includes / Settings.php

Settings.php in ezCache 1.3.11, at includes/Settings.php

120 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Upress\EzCache;
3
4 class Settings {
5 /** @var object */
6 protected static $settings;
7
8 /**
9 * Get the path to the config file
10 * @return string
11 */
12 protected static function settings_file_path() {
13 return WP_CONTENT_DIR . '/ezcache-config.json';
14 }
15
16 public static function get_default_settings() {
17 return (object) [
18 'no_cache_known_users' => true,
19 'separate_mobile_cache' => true,
20 'cache_lifetime' => 604800,
21 'cache_expiry_interval' => 10800,
22
23 'disable_wp_emoji' => false,
24 'optimize_google_fonts' => false,
25 'minify_html' => false,
26 'minify_html_comments' => true,
27 'minify_inline_js' => false,
28 'minify_inline_css' => false,
29 'minify_js' => false,
30 'combine_head_js' => false,
31 'combine_body_js' => false,
32 'minify_css' => false,
33 'combine_css' => false,
34 'enable_webp_support' => true,
35
36 'no_cache_query_params' => false,
37 'cache_clear_on_post_edit' => true,
38 'bypass_cache' => [
39 'single' => false,
40 'pages' => false,
41 'frontpage' => false,
42 'home' => false,
43 'archives' => false,
44 'tag' => false,
45 'category' => false,
46 'feed' => false,
47 'search' => false,
48 'author' => false,
49 ],
50 'rejected_uri' => "/cart\n/checkout",
51 'rejected_user_agent' => '',
52 'rejected_cookies' => '',
53 ];
54 }
55
56 /**
57 * Get the settings stored in the config file
58 * @return object
59 */
60 public static function get_settings() {
61
62 if ( self::$settings ) {
63 return self::$settings;
64 }
65
66 $file = self::settings_file_path();
67 $default_settings = self::get_default_settings();
68
69 if ( ! file_exists( $file ) || ! $json = json_decode( file_get_contents( $file ) ) ) {
70 self::$settings = $default_settings;
71 file_put_contents( $file, json_encode( self::$settings ) );
72
73 return self::$settings;
74 }
75
76 self::$settings = (object) array_merge( (array) $default_settings, (array) $json );
77 return self::$settings;
78 }
79
80 /**
81 * Merge new settings into the settings file
82 * @param array $new_settings
83 * @return object
84 */
85 public static function set_settings( $new_settings=[] ) {
86 $settings = self::get_settings();
87
88 foreach( $new_settings as $key => $value ) {
89 $settings->{$key} = $value;
90 }
91
92 self::maybe_update_cronjobs( $settings );
93
94 file_put_contents( self::settings_file_path(), json_encode( $settings ) );
95 self::$settings = $settings;
96 return $settings;
97 }
98
99 /**
100 * @param $settings
101 */
102 public static function maybe_update_cronjobs( $settings ) {
103 if ( wp_next_scheduled( 'ezcache_clear_expired_cache' ) ) {
104 wp_clear_scheduled_hook( 'ezcache_clear_expired_cache' );
105 }
106
107 if ( $settings->cache_lifetime > 0 ) {
108 $schedules = wp_get_schedules();
109 foreach( $schedules as $key=>$s ) {
110 if( $s['interval'] == $settings->cache_expiry_interval ) {
111 if ( ! wp_next_scheduled( 'ezcache_clear_expired_cache' ) ) {
112 wp_schedule_event( time(), $key, 'ezcache_clear_expired_cache' );
113 }
114 break;
115 }
116 }
117 }
118 }
119 }
120