| 1 |
<?php |
| 2 |
/** |
| 3 |
* Settings handling. |
| 4 |
* |
| 5 |
* @package XSpeed |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace XSpeed; |
| 9 |
|
| 10 |
defined( 'ABSPATH' ) || exit; |
| 11 |
|
| 12 |
class Settings { |
| 13 |
|
| 14 |
const OPTION_KEY = 'xspeed_options'; |
| 15 |
|
| 16 |
public static function defaults() { |
| 17 |
// Migrated out of this legacy blob (now per-module storage): |
| 18 |
// - minify_html / minify_css / minify_js → xspeed_module_minify |
| 19 |
// - gzip_enabled → xspeed_module_gzip |
| 20 |
// - cache_expiry / excluded_urls → xspeed_module_cache |
| 21 |
// Still here (intentionally, drop-in lifecycle): |
| 22 |
// - cache_enabled (Cache::toggle owns the .htaccess/wp-config edit) |
| 23 |
return array( |
| 24 |
'cache_enabled' => false, |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
public static function get() { |
| 29 |
$saved = get_option( self::OPTION_KEY, array() ); |
| 30 |
return wp_parse_args( $saved, self::defaults() ); |
| 31 |
} |
| 32 |
|
| 33 |
public static function update( array $input ) { |
| 34 |
$current = self::get(); |
| 35 |
$clean = $current; |
| 36 |
|
| 37 |
// Every former field is now in per-module storage: |
| 38 |
// - minify_* → MinifyModule, gzip_enabled → GzipModule, |
| 39 |
// cache_expiry / excluded_urls → CacheModule. |
| 40 |
// Only cache_enabled lives on here, owned by Cache::toggle's |
| 41 |
// drop-in lifecycle. All other writes are silently ignored to |
| 42 |
// keep duplicate sources from re-forming. |
| 43 |
if ( isset( $input['cache_enabled'] ) ) { |
| 44 |
$clean['cache_enabled'] = (bool) $input['cache_enabled']; |
| 45 |
} |
| 46 |
|
| 47 |
update_option( self::OPTION_KEY, $clean ); |
| 48 |
return $clean; |
| 49 |
} |
| 50 |
|
| 51 |
public static function set_defaults() { |
| 52 |
if ( false === get_option( self::OPTION_KEY ) ) { |
| 53 |
add_option( self::OPTION_KEY, self::defaults() ); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
// sanitize_urls() removed — excluded_urls now owned by CacheModule |
| 58 |
// and validated by Settings_Manager's typed schema (list / item_type). |
| 59 |
} |
| 60 |
|