true, 'qa_mode' => 3, 'qa_private' => true, 'qa_place' => 'panel', 'qa_rate_limit' => 20, 'reviews_enabled' => true, 'reviews_eligibility' => 'completed', 'reviews_min_percent' => 50, 'reviews_approval' => true, 'waitlist_guests' => true, ); public const ELIGIBILITY = array( 'enrolled', 'progress', 'completed' ); public const QA_PLACES = array( 'panel', 'corner', 'end' ); public static function all(): array { $stored = get_option( self::OPTION, array() ); return self::sanitize( is_array( $stored ) ? $stored : array() ); } public static function get( string $key ) { return array_key_exists( $key, self::DEFAULTS ) ? self::all()[ $key ] : null; } public static function update( array $values ): array { $new = self::sanitize( array_merge( self::all(), $values ) ); update_option( self::OPTION, $new, true ); return $new; } public static function sanitize( array $values ): array { $out = array(); foreach ( self::DEFAULTS as $key => $default ) { $value = $values[ $key ] ?? $default; if ( is_bool( $default ) ) { $bool = filter_var( $value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ); $out[ $key ] = null === $bool ? $default : $bool; } elseif ( is_int( $default ) ) { $out[ $key ] = is_numeric( $value ) ? max( 0, (int) $value ) : $default; } else { $out[ $key ] = is_string( $value ) && in_array( $value, 'qa_place' === $key ? self::QA_PLACES : self::ELIGIBILITY, true ) ? $value : $default; } } $out['qa_mode'] = $out['qa_mode'] >= 1 && $out['qa_mode'] <= 5 ? $out['qa_mode'] : self::DEFAULTS['qa_mode']; $out['qa_rate_limit'] = min( 1000, $out['qa_rate_limit'] ); $out['reviews_min_percent'] = max( 1, min( 100, $out['reviews_min_percent'] ) ); return $out; } }