false, 'minify_html' => false, 'minify_css' => false, 'minify_js' => false, 'gzip_enabled' => false, 'cache_expiry' => 24, 'excluded_urls' => array(), ); } public static function get() { $saved = get_option( self::OPTION_KEY, array() ); return wp_parse_args( $saved, self::defaults() ); } public static function update( array $input ) { $current = self::get(); $clean = $current; foreach ( array( 'cache_enabled', 'minify_html', 'minify_css', 'minify_js', 'gzip_enabled' ) as $key ) { if ( isset( $input[ $key ] ) ) { $clean[ $key ] = (bool) $input[ $key ]; } } if ( isset( $input['cache_expiry'] ) ) { $expiry = absint( $input['cache_expiry'] ); $clean['cache_expiry'] = max( 1, min( 720, $expiry ) ); } if ( isset( $input['excluded_urls'] ) ) { $clean['excluded_urls'] = self::sanitize_urls( $input['excluded_urls'] ); } update_option( self::OPTION_KEY, $clean ); return $clean; } public static function set_defaults() { if ( false === get_option( self::OPTION_KEY ) ) { add_option( self::OPTION_KEY, self::defaults() ); } } private static function sanitize_urls( $value ) { if ( is_string( $value ) ) { $lines = preg_split( '/\r\n|\r|\n/', $value ); } elseif ( is_array( $value ) ) { $lines = $value; } else { return array(); } $clean = array(); foreach ( $lines as $line ) { $line = trim( sanitize_text_field( $line ) ); if ( '' === $line ) { continue; } $clean[] = $line; } return array_values( array_unique( $clean ) ); } }