1, 'popups' => 1, 'woocommerce' => 1, 'dynamic_tags' => 1, 'header_method' => 'auto', 'pro_priority' => 'buildify', 'popup_stats' => 1, 'stats_retention' => 180, 'purge_cache' => 1, 'delete_data' => 0, ); } /** * All settings merged with defaults. * * @return array */ 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; } /** * Single value. * * @param string $key Setting key. * @param mixed $fallback Fallback value. * @return mixed */ public static function get( $key, $fallback = null ) { $all = self::all(); return array_key_exists( $key, $all ) ? $all[ $key ] : $fallback; } /** * Whether a checkbox setting is on. * * @param string $key Setting key. * @return bool */ public static function is_on( $key ) { return ! empty( self::get( $key ) ); } /** * Clears the in-memory cache. */ public static function flush() { self::$cache = null; } /** * Sanitizes the submitted settings. * * @param mixed $input Raw input. * @return array */ public static function sanitize( $input ) { $input = is_array( $input ) ? $input : array(); $defaults = self::defaults(); $clean = array(); foreach ( array( 'theme_builder', 'popups', 'woocommerce', 'dynamic_tags', 'popup_stats', 'purge_cache', 'delete_data' ) as $key ) { $clean[ $key ] = empty( $input[ $key ] ) ? 0 : 1; } $clean['header_method'] = isset( $input['header_method'] ) && in_array( $input['header_method'], array( 'auto', 'universal' ), true ) ? $input['header_method'] : $defaults['header_method']; $clean['pro_priority'] = isset( $input['pro_priority'] ) && in_array( $input['pro_priority'], array( 'buildify', 'elementor_pro' ), true ) ? $input['pro_priority'] : $defaults['pro_priority']; $retention = isset( $input['stats_retention'] ) ? absint( $input['stats_retention'] ) : $defaults['stats_retention']; $clean['stats_retention'] = min( 3650, max( 7, $retention ) ); self::flush(); return $clean; } }