'button_bg', 'label' => __( 'Buy button background', '7labs-debug-branding-for-commerce7' ), 'theme_key' => 'theme_primary', 'brand_key' => 'primary_button_bg', 'type' => 'color', ), array( 'id' => 'button_text', 'label' => __( 'Button text color', '7labs-debug-branding-for-commerce7' ), 'theme_key' => 'theme_button_text', 'brand_key' => 'primary_button_text_color', 'type' => 'color', ), array( 'id' => 'body_text', 'label' => __( 'Body / widget text', '7labs-debug-branding-for-commerce7' ), 'theme_key' => 'theme_text', 'brand_key' => 'text_color', 'type' => 'color', ), array( 'id' => 'link', 'label' => __( 'Link color', '7labs-debug-branding-for-commerce7' ), 'theme_key' => 'theme_link', 'brand_key' => 'link_color', 'type' => 'color', ), array( 'id' => 'heading_font', 'label' => __( 'Heading font', '7labs-debug-branding-for-commerce7' ), 'theme_key' => 'theme_heading_font', 'brand_key' => 'heading_font_family', 'type' => 'font', ), array( 'id' => 'body_font', 'label' => __( 'Body font', '7labs-debug-branding-for-commerce7' ), 'theme_key' => 'theme_body_font', 'brand_key' => 'font_family', 'type' => 'font', ), array( 'id' => 'radius', 'label' => __( 'Button border radius', '7labs-debug-branding-for-commerce7' ), 'theme_key' => 'theme_button_radius', 'brand_key' => 'button_border_radius', 'type' => 'size', ), ); } /** * Run comparisons. * * @return array */ public function get_conflicts() { $settings = C7DBT_Settings::get(); $brand = $settings['brand']; $conflicts = array(); // Auto-fill theme refs from Elementor if empty. $el = ( new C7DBT_Brand_Kit() )->read_elementor_kit(); if ( empty( $settings['theme_primary'] ) && ! empty( $el['primary'] ) ) { $settings['theme_primary'] = $el['primary']; } if ( empty( $settings['theme_text'] ) && ! empty( $el['text'] ) ) { $settings['theme_text'] = $el['text']; } foreach ( $this->pairs() as $pair ) { $theme_val = isset( $settings[ $pair['theme_key'] ] ) ? (string) $settings[ $pair['theme_key'] ] : ''; $brand_val = isset( $brand[ $pair['brand_key'] ] ) ? (string) $brand[ $pair['brand_key'] ] : ''; $status = 'unknown'; $detail = ''; if ( '' === $theme_val && '' === $brand_val ) { $status = 'unknown'; $detail = __( 'Set theme reference and C7 values to compare.', '7labs-debug-branding-for-commerce7' ); } elseif ( '' === $theme_val ) { $status = 'unknown'; $detail = __( 'Theme reference missing — enter it under Visual Match.', '7labs-debug-branding-for-commerce7' ); } elseif ( '' === $brand_val ) { $status = 'mismatch'; $detail = __( 'C7 override not set — widgets may use default Commerce7 styles.', '7labs-debug-branding-for-commerce7' ); } elseif ( 'color' === $pair['type'] ) { if ( C7DBT_Helpers::colors_match( $theme_val, $brand_val ) ) { $status = 'match'; $detail = __( 'Matched.', '7labs-debug-branding-for-commerce7' ); } else { $status = 'mismatch'; $detail = __( 'Colors differ — shop buttons may look off-brand.', '7labs-debug-branding-for-commerce7' ); } } else { // Font / size: normalize loosely. $t = strtolower( preg_replace( '/\s+/', '', $theme_val ) ); $b = strtolower( preg_replace( '/\s+/', '', $brand_val ) ); $b = trim( $b, '",\'' ); if ( $t === $b || false !== strpos( $b, $t ) || false !== strpos( $t, $b ) ) { $status = 'match'; $detail = __( 'Matched.', '7labs-debug-branding-for-commerce7' ); } else { $status = 'mismatch'; $detail = __( 'Values differ from your theme reference.', '7labs-debug-branding-for-commerce7' ); } } $conflicts[] = array( 'id' => $pair['id'], 'label' => $pair['label'], 'theme' => $theme_val, 'c7' => $brand_val, 'status' => $status, 'detail' => $detail, 'theme_key' => $pair['theme_key'], 'brand_key' => $pair['brand_key'], ); } // Contrast check on button bg vs text. $bg = ! empty( $brand['primary_button_bg'] ) ? $brand['primary_button_bg'] : ( $settings['theme_primary'] ?? '' ); $text = ! empty( $brand['primary_button_text_color'] ) ? $brand['primary_button_text_color'] : ( $settings['theme_button_text'] ?? '' ); if ( $bg && $text ) { $ratio = C7DBT_Helpers::contrast_ratio( $bg, $text ); if ( null !== $ratio && $ratio < 4.5 ) { $conflicts[] = array( 'id' => 'contrast', 'label' => __( 'Button contrast', '7labs-debug-branding-for-commerce7' ), 'theme' => $bg, 'c7' => $text, 'status' => 'mismatch', 'detail' => sprintf( /* translators: %s: contrast ratio */ __( 'Low contrast (%.2f:1). Aim for at least 4.5:1 for readable button text.', '7labs-debug-branding-for-commerce7' ), $ratio ), 'theme_key' => '', 'brand_key' => '', ); } elseif ( null !== $ratio ) { $conflicts[] = array( 'id' => 'contrast', 'label' => __( 'Button contrast', '7labs-debug-branding-for-commerce7' ), 'theme' => $bg, 'c7' => $text, 'status' => 'match', 'detail' => sprintf( /* translators: %s: contrast ratio */ __( 'Contrast OK (%.2f:1).', '7labs-debug-branding-for-commerce7' ), $ratio ), 'theme_key' => '', 'brand_key' => '', ); } } return $conflicts; } /** * Dashboard status. * * @return array */ public function status() { $items = $this->get_conflicts(); $mismatches = array_filter( $items, static function ( $i ) { return 'mismatch' === $i['status']; } ); $count = count( $mismatches ); if ( $count > 0 ) { return array( 'status' => 'warn', 'label' => __( 'Visual mismatches', '7labs-debug-branding-for-commerce7' ), 'detail' => sprintf( /* translators: %d: count */ _n( '%d style conflict with your theme.', '%d style conflicts with your theme.', $count, '7labs-debug-branding-for-commerce7' ), $count ), 'count' => $count, ); } return array( 'status' => 'ok', 'label' => __( 'Visual match looks good', '7labs-debug-branding-for-commerce7' ), 'detail' => __( 'No button/text/font mismatches detected (based on your theme references).', '7labs-debug-branding-for-commerce7' ), 'count' => 0, ); } }