'', 'geoip' => 1, 'country_days' => 30, 'stretch_buttons' => 1, 'hide_additional' => 0, 'title_lines' => 0, 'custom_css' => '', 'uninstall' => 'keep', ); } public static function all() { if ( null === self::$cache ) { $saved = get_option( self::OPTION, array() ); self::$cache = wp_parse_args( is_array( $saved ) ? $saved : array(), self::defaults() ); } return self::$cache; } public static function get( $key ) { $all = self::all(); return isset( $all[ $key ] ) ? $all[ $key ] : null; } public static function flush() { self::$cache = null; } /** Destination country used before the visitor's country is known. */ public static function default_country() { $country = (string) self::get( 'default_country' ); if ( '' === $country && function_exists( 'WC' ) && WC()->countries ) { $country = WC()->countries->get_base_country(); } return $country; } public static function sanitize( $input ) { $d = self::defaults(); $input = is_array( $input ) ? $input : array(); $out = array(); $country = isset( $input['default_country'] ) ? strtoupper( sanitize_text_field( $input['default_country'] ) ) : ''; $out['default_country'] = preg_match( '/^[A-Z]{2}$/', $country ) ? $country : ''; $out['geoip'] = empty( $input['geoip'] ) ? 0 : 1; $out['country_days'] = isset( $input['country_days'] ) ? min( 365, max( 1, absint( $input['country_days'] ) ) ) : $d['country_days']; $out['stretch_buttons'] = empty( $input['stretch_buttons'] ) ? 0 : 1; $out['hide_additional'] = empty( $input['hide_additional'] ) ? 0 : 1; $out['title_lines'] = isset( $input['title_lines'] ) ? min( 3, absint( $input['title_lines'] ) ) : 0; // Custom CSS is only taken in by cPOD Kit Pro (filter below); here the saved value is kept as it is. $saved = get_option( self::OPTION, array() ); $out['custom_css'] = is_array( $saved ) && isset( $saved['custom_css'] ) ? (string) $saved['custom_css'] : ''; $out['uninstall'] = isset( $input['uninstall'] ) && 'delete' === $input['uninstall'] ? 'delete' : 'keep'; /** * Sanitized general settings, before they are saved. * * @param array $out Sanitized settings. * @param array $input Submitted settings. */ $out = (array) apply_filters( 'cpod_settings_sanitize', $out, $input ); self::flush(); return $out; } /** * Accepts "--fs-color-primary", "fs-color-primary" or "var(--fs-color-primary)". * * @param string $value Raw input. * @return string Normalised "--name" or ''. */ public static function sanitize_css_var( $value ) { $value = trim( (string) $value ); if ( preg_match( '/^var\(\s*(--[A-Za-z0-9_-]+)\s*(?:,.*)?\)$/', $value, $m ) ) { $value = $m[1]; } if ( '' !== $value && 0 !== strpos( $value, '--' ) ) { $value = '--' . $value; } return preg_match( '/^--[A-Za-z0-9_-]+$/', $value ) ? $value : ''; } }