'Rey', 'verified_against' => 'rey-core 3.3.0', 'active' => array( __CLASS__, 'is_active' ), 'surfaces' => array( 'swatches' => array( 'filter_priority' => 2100, 'present' => array( __CLASS__, 'swatches_present' ), 'suppress' => array( __CLASS__, 'suppress_swatches' ), 'style_map' => self::swatch_style_map(), 'import_types' => array( __CLASS__, 'swatch_types' ), 'dequeue_styles' => array(), 'dequeue_scripts' => array( self::SWATCH_ASSET_HANDLE ), ), ), ); } public static function is_active() { return defined( 'REY_CORE_VERSION' ); } public static function swatches_present() { return AIEO_Theme_Adapters::count_callbacks_by_class( 'woocommerce_dropdown_variation_attribute_options_html', self::SWATCH_CLASS_PREFIX ) > 0; } public static function suppress_swatches() { $hooks = array( 'woocommerce_dropdown_variation_attribute_options_html', 'woocommerce_dropdown_variation_attribute_options_args', 'woocommerce_ajax_variation_threshold', ); $removed = 0; foreach ( $hooks as $hook ) { $removed += AIEO_Theme_Adapters::remove_callbacks_by_class( $hook, self::SWATCH_CLASS_PREFIX ); } add_action( 'wp_enqueue_scripts', static function () { wp_dequeue_script( self::SWATCH_ASSET_HANDLE ); }, 99 ); do_action( 'aieo_theme_adapter_rey_swatches_suppressed', $removed ); } public static function swatch_style_map() { return array( 'outer' => 'rey-swatches', 'wrapper' => 'rey-swatchList', 'wrapper_type' => '--type-%s', 'item' => 'rey-swatchList-item rey-swatchList-item--regular', 'item_type' => '--type-%s', 'item_content' => 'rey-swatchList-itemContent', 'selected' => 'is-active', ); } public static function swatch_types() { $map = array( 'rey_color' => 'color', 'rey_image' => 'image', 'rey_button' => 'button', 'rey_large_button' => 'button', 'rey_radio' => 'button', ); $out = array(); $stored = get_option( self::SWATCH_OPTION, array() ); if ( is_array( $stored ) ) { foreach ( $stored as $taxonomy => $config ) { $type = isset( $config['attribute_type'] ) ? (string) $config['attribute_type'] : ''; if ( isset( $map[ $type ] ) ) { $out[ (string) $taxonomy ] = $map[ $type ]; } } } global $wpdb; $rows = $wpdb->get_results( "SELECT attribute_name, attribute_type FROM {$wpdb->prefix}woocommerce_attribute_taxonomies", ARRAY_A ); foreach ( (array) $rows as $row ) { $type = isset( $row['attribute_type'] ) ? (string) $row['attribute_type'] : ''; if ( isset( $map[ $type ] ) ) { $out[ 'pa_' . (string) $row['attribute_name'] ] = $map[ $type ]; } } return $out; } }