PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.0.0
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.0.0
1.3.3 1.3.2 1.3.1 1.3.0 1.2.4 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 All 29 releases
xspeed / includes / class-settings.php

class-settings.php in xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN 1.0.0, at includes/class-settings.php

82 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 return array(
18 'cache_enabled' => false,
19 'minify_html' => false,
20 'minify_css' => false,
21 'minify_js' => false,
22 'gzip_enabled' => false,
23 'cache_expiry' => 24,
24 'excluded_urls' => array(),
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 foreach ( array( 'cache_enabled', 'minify_html', 'minify_css', 'minify_js', 'gzip_enabled' ) as $key ) {
38 if ( isset( $input[ $key ] ) ) {
39 $clean[ $key ] = (bool) $input[ $key ];
40 }
41 }
42
43 if ( isset( $input['cache_expiry'] ) ) {
44 $expiry = absint( $input['cache_expiry'] );
45 $clean['cache_expiry'] = max( 1, min( 720, $expiry ) );
46 }
47
48 if ( isset( $input['excluded_urls'] ) ) {
49 $clean['excluded_urls'] = self::sanitize_urls( $input['excluded_urls'] );
50 }
51
52 update_option( self::OPTION_KEY, $clean );
53 return $clean;
54 }
55
56 public static function set_defaults() {
57 if ( false === get_option( self::OPTION_KEY ) ) {
58 add_option( self::OPTION_KEY, self::defaults() );
59 }
60 }
61
62 private static function sanitize_urls( $value ) {
63 if ( is_string( $value ) ) {
64 $lines = preg_split( '/\r\n|\r|\n/', $value );
65 } elseif ( is_array( $value ) ) {
66 $lines = $value;
67 } else {
68 return array();
69 }
70
71 $clean = array();
72 foreach ( $lines as $line ) {
73 $line = trim( sanitize_text_field( $line ) );
74 if ( '' === $line ) {
75 continue;
76 }
77 $clean[] = $line;
78 }
79 return array_values( array_unique( $clean ) );
80 }
81 }
82