| @@ -49,8 +49,9 @@ | ||
| 49 | 49 | $enabled = false; |
| 50 | 50 | $disabled = false; |
| 51 | 51 | $return = empty($validation) ? array() : $validation; |
| 52 | 52 | $previous_settings = WPO_Cache_Config::instance()->get(); |
| 53 | + $settings_changed = false; | |
| 53 | 54 | |
| 54 | 55 | // Attempt to change current status if required |
| 55 | 56 | if (isset($previous_settings['enable_page_caching']) && (bool) $previous_settings['enable_page_caching'] !== (bool) $data['cache-settings']['enable_page_caching']) { |
| 56 | 57 | // Disable cache. |
| @@ -102,10 +103,9 @@ | ||
| 102 | 103 | } |
| 103 | 104 | // Override enabled setting value |
| 104 | 105 | $data['cache-settings']['enable_page_caching'] = ($enabled && !is_wp_error($enabled)) || ($previous_settings['enable_page_caching'] && is_wp_error($disabled)); |
| 105 | 106 | } else { |
| 106 | - $data['cache-settings']['enable_page_caching'] = $previous_settings['enable_page_caching']; | |
| 107 | - $enabled = $previous_settings['enable_page_caching']; | |
| 107 | + $enabled = isset($data['cache-settings']['enable_page_caching']) ? (bool) $data['cache-settings']['enable_page_caching'] : false; | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | $data['cache-settings']['use_webp_images'] = (bool) WP_Optimize()->get_options()->get_option('webp_conversion'); |
| 111 | 111 | |
| @@ -112,9 +112,14 @@ | ||
| 112 | 112 | $skip_if_no_file_yet = !$enabled || is_wp_error($enabled); |
| 113 | 113 | $save_settings_result = WPO_Cache_Config::instance()->update($data['cache-settings'], $skip_if_no_file_yet); |
| 114 | 114 | |
| 115 | 115 | if ($save_settings_result && !is_wp_error($save_settings_result)) { |
| 116 | - WP_Optimize_Page_Cache_Preloader::instance()->cache_settings_updated($data['cache-settings'], $previous_settings); | |
| 116 | + $settings_changed = !WP_Optimize_Utils::array_contains($data['cache-settings'], $previous_settings); | |
| 117 | + | |
| 118 | + if ($settings_changed) { | |
| 119 | + WP_Optimize_Page_Cache_Preloader::instance()->cache_settings_updated($data['cache-settings'], $previous_settings); | |
| 120 | + WPO_Page_Cache::instance()->cache_settings_updated($data['cache-settings']); | |
| 121 | + } | |
| 117 | 122 | $return['result'] = $save_settings_result; |
| 118 | 123 | } else { |
| 119 | 124 | // Saving the settings returned an error |
| 120 | 125 | if (is_wp_error($save_settings_result)) { |
| @@ -138,9 +143,8 @@ | ||
| 138 | 143 | 'enable_user_caching', |
| 139 | 144 | 'enable_per_role_cache', |
| 140 | 145 | 'enable_user_specific_cache', |
| 141 | 146 | 'enable_rest_caching', |
| 142 | - 'show_avatars', | |
| 143 | 147 | 'host_gravatars_locally', |
| 144 | 148 | 'cache_exception_urls', |
| 145 | 149 | 'cache_ignore_query_variables', |
| 146 | 150 | 'cache_exception_cookies', |
| @@ -158,9 +162,9 @@ | ||
| 158 | 162 | $cache->purge(); |
| 159 | 163 | } |
| 160 | 164 | } |
| 161 | 165 | // $disable can either be boolean or WP_Error |
| 162 | - if (!is_wp_error($disabled) && $disabled) { | |
| 166 | + if (!is_wp_error($disabled) && $disabled && $settings_changed) { | |
| 163 | 167 | WPO_Page_Cache::instance()->prune_cache_logs(); |
| 164 | 168 | wp_clear_scheduled_hook('wpo_prune_cache_logs'); |
| 165 | 169 | } |
| 166 | 170 | |