option => default */ public static function defaults(): array { return array( 'swatchline_shape' => 'circle', 'swatchline_size' => '36', 'swatchline_label_style' => 'outline', 'swatchline_tooltip' => 'yes', 'swatchline_tooltip_image' => 'yes', 'swatchline_show_selected' => 'yes', 'swatchline_custom_attributes' => 'no', ); } private static function raw( string $option ): string { $defaults = self::defaults(); $value = get_option( $option, $defaults[ $option ] ?? '' ); return is_scalar( $value ) ? (string) $value : (string) ( $defaults[ $option ] ?? '' ); } public static function shape(): string { $shape = self::raw( 'swatchline_shape' ); return in_array( $shape, self::SHAPES, true ) ? $shape : 'circle'; } /** The colour and image swatch size on the product page, in pixels (16–96). */ public static function size(): int { return self::clamp( (int) self::raw( 'swatchline_size' ), 16, 96, 36 ); } public static function label_style(): string { $style = self::raw( 'swatchline_label_style' ); return in_array( $style, self::LABEL_STYLES, true ) ? $style : 'outline'; } public static function tooltip(): bool { return 'no' !== self::raw( 'swatchline_tooltip' ); } public static function tooltip_image(): bool { return self::tooltip() && 'no' !== self::raw( 'swatchline_tooltip_image' ); } public static function show_selected(): bool { return 'no' !== self::raw( 'swatchline_show_selected' ); } /** Whether custom (product-level) attributes show as label swatches rather than dropdowns. */ public static function custom_attributes(): bool { return 'yes' === self::raw( 'swatchline_custom_attributes' ); } public static function clamp( int $value, int $min, int $max, int $fallback ): int { if ( $value <= 0 ) { return $fallback; } return max( $min, min( $max, $value ) ); } }