| @@ -410,10 +410,10 @@ | ||
| 410 | 410 | <?php endif; ?> |
| 411 | 411 | |
| 412 | 412 | <div class="mxchat-agents-banner"> |
| 413 | 413 | <p> |
| 414 | - <strong><?php echo esc_html__('The MxChat Add-Ons Platform', 'mxchat'); ?></strong><?php echo esc_html__(' is here! Pro users get unlimited access to our growing collection of powerful add-ons. ', 'mxchat'); ?><a href="<?php echo admin_url('admin.php?page=mxchat-addons'); ?>"><?php echo esc_html__('Explore all add-ons', 'mxchat'); ?></a><?php echo esc_html__(' including Forms Builder, Theme Customizer, Content Moderation, and more – all included with your lifetime Pro license!', 'mxchat'); ?> | |
| 415 | - </p> | |
| 414 | + <?php echo esc_html__('Pro users get exclusive access to', 'mxchat'); ?> <a href="https://mxchat.ai/agents/" target="_blank"><?php echo esc_html__('MxChat AI Agents', 'mxchat'); ?></a> <?php echo esc_html__('– our groundbreaking platform to test, refine, and deploy your chatbot with confidence. Take your AI assistant to the next level!', 'mxchat'); ?> | |
| 415 | + </p> | |
| 416 | 416 | </div> |
| 417 | 417 | |
| 418 | 418 | <h2 class="mxchat-nav-tab-wrapper"> |
| 419 | 419 | <a href="#chatbot" class="mxchat-nav-tab mxchat-nav-tab-active" data-tab="chatbot"><?php echo esc_html__('Chatbot', 'mxchat'); ?></a> |
| @@ -428,8 +428,15 @@ | ||
| 428 | 428 | </div> |
| 429 | 429 | |
| 430 | 430 | <div id="embed" class="mxchat-tab-content"> |
| 431 | 431 | <div class="mxchat-autosave-section"> |
| 432 | + <div class="mxchat-settings-section"> | |
| 433 | + <h2><?php echo esc_html__('WooCommerce Settings', 'mxchat'); ?></h2> | |
| 434 | + <table class="form-table"> | |
| 435 | + <?php do_settings_fields('mxchat-embed', 'mxchat_woocommerce_section'); ?> | |
| 436 | + </table> | |
| 437 | + </div> | |
| 438 | + <div class="section-divider"></div> | |
| 432 | 439 | |
| 433 | 440 | <div class="mxchat-settings-section"> |
| 434 | 441 | <h2><?php echo esc_html__('Loops Settings', 'mxchat'); ?></h2> |
| 435 | 442 | <table class="form-table"> |
| @@ -2199,9 +2206,8 @@ | ||
| 2199 | 2206 | $wpdb->delete($table_name, array('source_url' => $source_url), array('%s')); |
| 2200 | 2207 | } |
| 2201 | 2208 | } |
| 2202 | 2209 | |
| 2203 | - | |
| 2204 | 2210 | /** |
| 2205 | 2211 | * Delete vectors from Pinecone by source URL |
| 2206 | 2212 | * |
| 2207 | 2213 | * @param array $urls Array of source URLs to delete |
| @@ -2657,123 +2663,83 @@ | ||
| 2657 | 2663 | <th><?php esc_html_e('Similarity Threshold', 'mxchat'); ?></th> |
| 2658 | 2664 | <th><?php esc_html_e('Actions', 'mxchat'); ?></th> |
| 2659 | 2665 | </tr> |
| 2660 | 2666 | </thead> |
| 2661 | - <tbody> | |
| 2662 | - <?php if ($intents) : | |
| 2663 | - foreach ($intents as $intent) : | |
| 2664 | - $callback_function = $intent->callback_function; | |
| 2665 | - $callback_label = isset($available_callbacks[$callback_function]['label']) | |
| 2666 | - ? $available_callbacks[$callback_function]['label'] | |
| 2667 | - : $callback_function; | |
| 2668 | - $threshold_value = isset($intent->similarity_threshold) | |
| 2669 | - ? round($intent->similarity_threshold * 100) | |
| 2670 | - : 85; | |
| 2671 | - | |
| 2672 | - // Check if this is a form intent (its intent_label starts with "Form ") | |
| 2673 | - $is_form_intent = strpos($intent->intent_label, 'Form ') === 0; | |
| 2674 | - ?> | |
| 2675 | - <tr<?php echo $is_form_intent ? ' class="mxchat-form-intent"' : ''; ?>> | |
| 2676 | - <td> | |
| 2677 | - <?php | |
| 2678 | - if ($is_form_intent) { | |
| 2679 | - // Attempt to extract the form ID from the intent_label. | |
| 2680 | - preg_match('/Form (\d+)/', $intent->intent_label, $matches); | |
| 2681 | - $form_id = isset($matches[1]) ? intval($matches[1]) : 0; | |
| 2682 | - if ($form_id) { | |
| 2683 | - global $wpdb; | |
| 2684 | - $forms_table = $wpdb->prefix . 'mxchat_forms'; | |
| 2685 | - $form = $wpdb->get_row($wpdb->prepare("SELECT title FROM $forms_table WHERE id = %d", $form_id)); | |
| 2686 | - if ($form && !empty($form->title)) { | |
| 2687 | - echo esc_html($form->title); | |
| 2688 | - } else { | |
| 2689 | - echo esc_html($intent->intent_label); | |
| 2690 | - } | |
| 2691 | - } else { | |
| 2692 | - echo esc_html($intent->intent_label); | |
| 2693 | - } | |
| 2694 | - echo ' <span class="mxchat-badge">Form Intent</span>'; | |
| 2695 | - } else { | |
| 2696 | - echo esc_html($intent->intent_label); | |
| 2697 | - } | |
| 2698 | - ?> | |
| 2699 | - </td> | |
| 2700 | - <td class="mxchat-content-cell"> | |
| 2701 | - <?php echo esc_html($intent->phrases); ?> | |
| 2702 | - </td> | |
| 2703 | - <td><?php echo esc_html($callback_label); ?></td> | |
| 2704 | - <td> | |
| 2705 | - <!-- Similarity threshold adjustment (shown for all intents) --> | |
| 2706 | - <form method="post" | |
| 2707 | - action="<?php echo esc_url(admin_url('admin-post.php')); ?>" | |
| 2708 | - class="mxchat-threshold-form"> | |
| 2709 | - <?php wp_nonce_field('mxchat_update_intent_threshold_nonce'); ?> | |
| 2710 | - <input type="hidden" name="action" | |
| 2711 | - value="mxchat_update_intent_threshold"> | |
| 2712 | - <input type="hidden" name="intent_id" | |
| 2713 | - value="<?php echo esc_attr($intent->id); ?>"> | |
| 2714 | - <div class="mxchat-slider-group"> | |
| 2715 | - <input type="range" | |
| 2716 | - name="intent_threshold" | |
| 2717 | - id="intent_threshold_<?php echo esc_attr($intent->id); ?>" | |
| 2718 | - min="70" | |
| 2719 | - max="95" | |
| 2720 | - value="<?php echo esc_attr($threshold_value); ?>" | |
| 2721 | - class="mxchat-intent-slider" | |
| 2722 | - oninput="document.getElementById('threshold_output_<?php echo esc_attr($intent->id); ?>').value = this.value + '%'"> | |
| 2723 | - <output id="threshold_output_<?php echo esc_attr($intent->id); ?>" | |
| 2724 | - class="mxchat-intent-output"> | |
| 2725 | - <?php echo esc_html($threshold_value); ?>% | |
| 2726 | - </output> | |
| 2727 | - </div> | |
| 2728 | - <button type="submit" class="mxchat-button-icon"> | |
| 2729 | - <span class="dashicons dashicons-saved"></span> | |
| 2730 | - </button> | |
| 2731 | - </form> | |
| 2732 | - </td> | |
| 2733 | - <td class="mxchat-actions-cell"> | |
| 2734 | - <?php if (!$is_form_intent) : ?> | |
| 2735 | - <!-- Standard intents: allow edit and delete --> | |
| 2736 | - <button type="button" | |
| 2737 | - class="mxchat-button-icon mxchat-edit-button" | |
| 2738 | - data-intent-id="<?php echo esc_attr($intent->id); ?>" | |
| 2739 | - data-phrases="<?php echo esc_attr($intent->phrases); ?>"> | |
| 2740 | - <span class="dashicons dashicons-edit"></span> | |
| 2741 | - </button> | |
| 2742 | - <form method="post" | |
| 2743 | - action="<?php echo esc_url(admin_url('admin-post.php')); ?>" | |
| 2744 | - class="mxchat-delete-form" | |
| 2745 | - onsubmit="return confirm('<?php esc_attr_e('Are you sure you want to delete this intent?', 'mxchat'); ?>');"> | |
| 2746 | - <?php wp_nonce_field('mxchat_delete_intent_nonce'); ?> | |
| 2747 | - <input type="hidden" name="action" value="mxchat_delete_intent"> | |
| 2748 | - <input type="hidden" name="intent_id" | |
| 2749 | - value="<?php echo esc_attr($intent->id); ?>"> | |
| 2750 | - <button type="submit" class="mxchat-button-icon"> | |
| 2751 | - <span class="dashicons dashicons-trash"></span> | |
| 2752 | - </button> | |
| 2753 | - </form> | |
| 2754 | - <?php else : ?> | |
| 2755 | - <!-- Form intents: show manage in forms button --> | |
| 2756 | - <?php | |
| 2757 | - preg_match('/Form (\d+)/', $intent->intent_label, $matches); | |
| 2758 | - $form_id = isset($matches[1]) ? $matches[1] : ''; | |
| 2759 | - ?> | |
| 2760 | - <a href="<?php echo esc_url(admin_url('admin.php?page=mxchat-forms&action=edit&form_id=' . $form_id)); ?>" | |
| 2761 | - class="mxchat-button-secondary"> | |
| 2762 | - <?php esc_html_e('Manage in Forms', 'mxchat'); ?> | |
| 2763 | - </a> | |
| 2764 | - <?php endif; ?> | |
| 2765 | - </td> | |
| 2766 | - </tr> | |
| 2767 | - <?php endforeach; | |
| 2768 | - else : ?> | |
| 2667 | + <tbody> | |
| 2668 | + <?php if ($intents) : | |
| 2669 | + foreach ($intents as $intent) : | |
| 2670 | + $callback_function = $intent->callback_function; | |
| 2671 | + $callback_label = isset($available_callbacks[$callback_function]['label']) | |
| 2672 | + ? $available_callbacks[$callback_function]['label'] | |
| 2673 | + : $callback_function; | |
| 2674 | + $threshold_value = isset($intent->similarity_threshold) | |
| 2675 | + ? round($intent->similarity_threshold * 100) | |
| 2676 | + : 85; | |
| 2677 | + ?> | |
| 2769 | 2678 | <tr> |
| 2770 | - <td colspan="5" class="mxchat-no-records"> | |
| 2771 | - <?php esc_html_e('No intents found.', 'mxchat'); ?> | |
| 2679 | + <td><?php echo esc_html($intent->intent_label); ?></td> | |
| 2680 | + <td class="mxchat-content-cell"> | |
| 2681 | + <?php echo esc_html($intent->phrases); ?> | |
| 2772 | 2682 | </td> |
| 2683 | + <td><?php echo esc_html($callback_label); ?></td> | |
| 2684 | + <td> | |
| 2685 | + <form method="post" | |
| 2686 | + action="<?php echo esc_url(admin_url('admin-post.php')); ?>" | |
| 2687 | + class="mxchat-threshold-form"> | |
| 2688 | + <?php wp_nonce_field('mxchat_update_intent_threshold_nonce'); ?> | |
| 2689 | + <input type="hidden" name="action" | |
| 2690 | + value="mxchat_update_intent_threshold"> | |
| 2691 | + <input type="hidden" name="intent_id" | |
| 2692 | + value="<?php echo esc_attr($intent->id); ?>"> | |
| 2693 | + <div class="mxchat-slider-group"> | |
| 2694 | + <input type="range" | |
| 2695 | + name="intent_threshold" | |
| 2696 | + id="intent_threshold_<?php echo esc_attr($intent->id); ?>" | |
| 2697 | + min="70" | |
| 2698 | + max="95" | |
| 2699 | + value="<?php echo esc_attr($threshold_value); ?>" | |
| 2700 | + class="mxchat-intent-slider" | |
| 2701 | + oninput="document.getElementById('threshold_output_<?php echo esc_attr($intent->id); ?>').value = this.value + '%'"> | |
| 2702 | + <output id="threshold_output_<?php echo esc_attr($intent->id); ?>" | |
| 2703 | + class="mxchat-intent-output"> | |
| 2704 | + <?php echo esc_html($threshold_value); ?>% | |
| 2705 | + </output> | |
| 2706 | + </div> | |
| 2707 | + <button type="submit" class="mxchat-button-icon"> | |
| 2708 | + <span class="dashicons dashicons-saved"></span> | |
| 2709 | + </button> | |
| 2710 | + </form> | |
| 2711 | + </td> | |
| 2712 | + <td class="mxchat-actions-cell"> | |
| 2713 | + <button type="button" | |
| 2714 | + class="mxchat-button-icon mxchat-edit-button" | |
| 2715 | + data-intent-id="<?php echo esc_attr($intent->id); ?>" | |
| 2716 | + data-phrases="<?php echo esc_attr($intent->phrases); ?>"> | |
| 2717 | + <span class="dashicons dashicons-edit"></span> | |
| 2718 | + </button> | |
| 2719 | + <form method="post" | |
| 2720 | + action="<?php echo esc_url(admin_url('admin-post.php')); ?>" | |
| 2721 | + class="mxchat-delete-form" | |
| 2722 | + onsubmit="return confirm('<?php esc_attr_e('Are you sure you want to delete this intent?', 'mxchat'); ?>');"> | |
| 2723 | + <?php wp_nonce_field('mxchat_delete_intent_nonce'); ?> | |
| 2724 | + <input type="hidden" name="action" value="mxchat_delete_intent"> | |
| 2725 | + <input type="hidden" name="intent_id" | |
| 2726 | + value="<?php echo esc_attr($intent->id); ?>"> | |
| 2727 | + <button type="submit" class="mxchat-button-icon"> | |
| 2728 | + <span class="dashicons dashicons-trash"></span> | |
| 2729 | + </button> | |
| 2730 | + </form> | |
| 2731 | + </td> | |
| 2773 | 2732 | </tr> |
| 2774 | - <?php endif; ?> | |
| 2775 | - </tbody> | |
| 2733 | + <?php endforeach; | |
| 2734 | + else : ?> | |
| 2735 | + <tr> | |
| 2736 | + <td colspan="5" class="mxchat-no-records"> | |
| 2737 | + <?php esc_html_e('No intents found.', 'mxchat'); ?> | |
| 2738 | + </td> | |
| 2739 | + </tr> | |
| 2740 | + <?php endif; ?> | |
| 2741 | + </tbody> | |
| 2776 | 2742 | </table> |
| 2777 | 2743 | </div> |
| 2778 | 2744 | |
| 2779 | 2745 | <?php if ($total_pages > 1) : ?> |
| @@ -3035,8 +3001,18 @@ | ||
| 3035 | 3001 | 'label' => __('Email Capture', 'mxchat'), |
| 3036 | 3002 | 'pro_only' => false, |
| 3037 | 3003 | 'group' => __('Customer Engagement', 'mxchat'), |
| 3038 | 3004 | ], |
| 3005 | + 'mxchat_handle_product_inquiry' => [ | |
| 3006 | + 'label' => __('Show Product Card', 'mxchat'), | |
| 3007 | + 'pro_only' => true, | |
| 3008 | + 'group' => __('WooCommerce Features', 'mxchat'), | |
| 3009 | + ], | |
| 3010 | + 'mxchat_handle_order_history' => [ | |
| 3011 | + 'label' => __('Order History', 'mxchat'), | |
| 3012 | + 'pro_only' => true, | |
| 3013 | + 'group' => __('WooCommerce Features', 'mxchat'), | |
| 3014 | + ], | |
| 3039 | 3015 | 'mxchat_generate_image' => [ |
| 3040 | 3016 | 'label' => __('Generate Image', 'mxchat'), |
| 3041 | 3017 | 'pro_only' => true, |
| 3042 | 3018 | 'group' => __('Other Features', 'mxchat'), |
| @@ -3050,13 +3026,28 @@ | ||
| 3050 | 3026 | 'label' => __('Brave Image Search', 'mxchat'), |
| 3051 | 3027 | 'pro_only' => false, |
| 3052 | 3028 | 'group' => __('Search Features', 'mxchat'), |
| 3053 | 3029 | ], |
| 3030 | + 'mxchat_handle_add_to_cart_intent' => [ | |
| 3031 | + 'label' => __('Add to Cart', 'mxchat'), | |
| 3032 | + 'pro_only' => true, | |
| 3033 | + 'group' => __('WooCommerce Features', 'mxchat'), | |
| 3034 | + ], | |
| 3035 | + 'mxchat_handle_checkout_intent' => [ | |
| 3036 | + 'label' => __('Proceed to Checkout', 'mxchat'), | |
| 3037 | + 'pro_only' => true, | |
| 3038 | + 'group' => __('WooCommerce Features', 'mxchat'), | |
| 3039 | + ], | |
| 3054 | 3040 | 'mxchat_handle_pdf_discussion' => [ |
| 3055 | 3041 | 'label' => __('Chat with PDF', 'mxchat'), |
| 3056 | 3042 | 'pro_only' => true, |
| 3057 | 3043 | 'group' => __('Other Features', 'mxchat'), |
| 3058 | 3044 | ], |
| 3045 | + 'mxchat_handle_product_recommendations' => [ | |
| 3046 | + 'label' => __('Product Recommendations', 'mxchat'), | |
| 3047 | + 'pro_only' => true, | |
| 3048 | + 'group' => __('WooCommerce Features', 'mxchat'), | |
| 3049 | + ], | |
| 3059 | 3050 | 'mxchat_live_agent_handover' => [ |
| 3060 | 3051 | 'label' => __('Live Agent', 'mxchat'), |
| 3061 | 3052 | 'pro_only' => true, |
| 3062 | 3053 | 'group' => __('Customer Engagement', 'mxchat'), |
| @@ -3067,11 +3058,8 @@ | ||
| 3067 | 3058 | 'group' => __('Customer Engagement', 'mxchat'), |
| 3068 | 3059 | ], |
| 3069 | 3060 | ]; |
| 3070 | 3061 | |
| 3071 | - // Allow other plugins to add their callbacks | |
| 3072 | - $callbacks = apply_filters('mxchat_available_callbacks', $callbacks); | |
| 3073 | - | |
| 3074 | 3062 | // Return grouped structure if requested |
| 3075 | 3063 | if ($grouped) { |
| 3076 | 3064 | $grouped_callbacks = []; |
| 3077 | 3065 | foreach ($callbacks as $key => $data) { |
| @@ -3082,12 +3070,14 @@ | ||
| 3082 | 3070 | ]; |
| 3083 | 3071 | } |
| 3084 | 3072 | return $grouped_callbacks; |
| 3085 | 3073 | } |
| 3074 | + | |
| 3086 | 3075 | return $callbacks; |
| 3087 | 3076 | } |
| 3088 | 3077 | |
| 3089 | 3078 | |
| 3079 | + | |
| 3090 | 3080 | private function mxchat_average_vectors($vectors) { |
| 3091 | 3081 | $vector_length = count($vectors[0]); |
| 3092 | 3082 | $sum_vector = array_fill(0, $vector_length, 0); |
| 3093 | 3083 | |
| @@ -3365,8 +3355,15 @@ | ||
| 3365 | 3355 | 'mxchat-chatbot', |
| 3366 | 3356 | 'mxchat_chatbot_section' |
| 3367 | 3357 | ); |
| 3368 | 3358 | |
| 3359 | + // WooCommerce Settings Section | |
| 3360 | + add_settings_section( | |
| 3361 | + 'mxchat_woocommerce_section', | |
| 3362 | + esc_html__('WooCommerce Settings', 'mxchat'), | |
| 3363 | + null, | |
| 3364 | + 'mxchat-embed' | |
| 3365 | + ); | |
| 3369 | 3366 | |
| 3370 | 3367 | // Loops Settings Section |
| 3371 | 3368 | add_settings_section( |
| 3372 | 3369 | 'mxchat_loops_section', |
| @@ -3374,8 +3371,33 @@ | ||
| 3374 | 3371 | null, |
| 3375 | 3372 | 'mxchat-embed' |
| 3376 | 3373 | ); |
| 3377 | 3374 | |
| 3375 | + // WooCommerce Settings Fields | |
| 3376 | + add_settings_field( | |
| 3377 | + 'enable_woocommerce_integration', | |
| 3378 | + esc_html__('Automatically Embed Products', 'mxchat'), | |
| 3379 | + array($this, 'mxchat_enable_woocommerce_integration_callback'), | |
| 3380 | + 'mxchat-embed', | |
| 3381 | + 'mxchat_woocommerce_section' | |
| 3382 | + ); | |
| 3383 | + | |
| 3384 | + add_settings_field( | |
| 3385 | + 'woocommerce_consumer_key', | |
| 3386 | + esc_html__('WooCommerce Consumer Key', 'mxchat'), | |
| 3387 | + array($this, 'mxchat_woocommerce_consumer_key_callback'), | |
| 3388 | + 'mxchat-embed', | |
| 3389 | + 'mxchat_woocommerce_section' | |
| 3390 | + ); | |
| 3391 | + | |
| 3392 | + add_settings_field( | |
| 3393 | + 'woocommerce_consumer_secret', | |
| 3394 | + esc_html__('WooCommerce Consumer Secret', 'mxchat'), | |
| 3395 | + array($this, 'mxchat_woocommerce_consumer_secret_callback'), | |
| 3396 | + 'mxchat-embed', | |
| 3397 | + 'mxchat_woocommerce_section' | |
| 3398 | + ); | |
| 3399 | + | |
| 3378 | 3400 | // Loops Settings Fields |
| 3379 | 3401 | add_settings_field( |
| 3380 | 3402 | 'loops_api_key', |
| 3381 | 3403 | esc_html__('Loops API Key', 'mxchat'), |
| @@ -3821,8 +3843,52 @@ | ||
| 3821 | 3843 | echo '</div>'; |
| 3822 | 3844 | } |
| 3823 | 3845 | |
| 3824 | 3846 | |
| 3847 | +public function mxchat_enable_woocommerce_integration_callback() { | |
| 3848 | + // Load from mxchat_options array | |
| 3849 | + $options = get_option('mxchat_options', []); | |
| 3850 | + | |
| 3851 | + // Get WooCommerce integration status with backwards compatibility | |
| 3852 | + $woo_integration = isset($options['enable_woocommerce_integration']) | |
| 3853 | + ? $options['enable_woocommerce_integration'] | |
| 3854 | + : ''; | |
| 3855 | + | |
| 3856 | + // Support both old ('1') and new ('on') values | |
| 3857 | + $checked = ($woo_integration === 'on' || $woo_integration === '1') ? 'checked' : ''; | |
| 3858 | + | |
| 3859 | + // Check if the feature is activated (paid feature) | |
| 3860 | + $disabled = $this->is_activated ? '' : 'disabled'; | |
| 3861 | + $class = $this->is_activated ? 'pro-feature-wrapper active' : 'pro-feature-wrapper inactive'; | |
| 3862 | + | |
| 3863 | + echo '<div class="' . esc_attr($class) . '">'; | |
| 3864 | + | |
| 3865 | + echo '<label class="toggle-switch">'; | |
| 3866 | + echo sprintf( | |
| 3867 | + '<input type="checkbox" id="enable_woocommerce_integration" name="enable_woocommerce_integration" value="on" %s %s />', | |
| 3868 | + esc_attr($checked), | |
| 3869 | + esc_attr($disabled) | |
| 3870 | + ); | |
| 3871 | + echo '<span class="slider"></span>'; | |
| 3872 | + echo '</label>'; | |
| 3873 | + | |
| 3874 | + echo '<p class="description">' . esc_html__('Automatically syncs new product additions, updates, and removals to the knowledge base. For existing products, submit your product sitemap in the Knowledge Base section to add them initially.', 'mxchat') . '</p>'; | |
| 3875 | + | |
| 3876 | + // Pro feature overlay for non-activated users | |
| 3877 | + if (!$this->is_activated) { | |
| 3878 | + echo '<div class="pro-feature-overlay">'; | |
| 3879 | + echo '<a href="https://mxchat.ai/" target="_blank">'; | |
| 3880 | + echo '<img src="' . esc_url(plugin_dir_url(__FILE__) . '../images/pro-only-dark.png') . '" alt="' . esc_attr__('Pro Only', 'mxchat') . '" />'; | |
| 3881 | + echo '</a>'; | |
| 3882 | + echo '</div>'; | |
| 3883 | + } | |
| 3884 | + | |
| 3885 | + echo '</div>'; | |
| 3886 | +} | |
| 3887 | + | |
| 3888 | + | |
| 3889 | + | |
| 3890 | + | |
| 3825 | 3891 | private function mxchat_add_option_field($id, $title, $callback = '') { |
| 3826 | 3892 | add_settings_field( |
| 3827 | 3893 | $id, |
| 3828 | 3894 | __($title, 'mxchat'), |
| @@ -3869,15 +3935,15 @@ | ||
| 3869 | 3935 | echo '</div>'; |
| 3870 | 3936 | } |
| 3871 | 3937 | public function claude_api_key_callback() { |
| 3872 | 3938 | // Check if the feature is activated (paid feature) |
| 3873 | - $disabled = $this->is_activated ? '' : 'disabled'; | |
| 3874 | - $class = $this->is_activated ? 'pro-feature-wrapper active' : 'pro-feature-wrapper inactive'; | |
| 3875 | - | |
| 3876 | - // Retrieve the Claude API key value directly like the others | |
| 3939 | + $disabled = $this->is_activated ? '' : 'disabled'; // Disable input if not activated | |
| 3940 | + $class = $this->is_activated ? 'pro-feature-wrapper active' : 'pro-feature-wrapper inactive'; // CSS class to style the wrapper based on activation status | |
| 3941 | + | |
| 3942 | + // Retrieve the Claude API key value | |
| 3877 | 3943 | $claudeApiKey = isset($this->options['claude_api_key']) ? esc_attr($this->options['claude_api_key']) : ''; |
| 3878 | - | |
| 3879 | - // Use direct name field like the other working API keys | |
| 3944 | + | |
| 3945 | + // Render the input field for the Claude API key | |
| 3880 | 3946 | echo '<div class="' . esc_attr($class) . '">'; |
| 3881 | 3947 | printf( |
| 3882 | 3948 | '<input type="password" id="claude_api_key" name="claude_api_key" value="%s" class="regular-text" %s />', |
| 3883 | 3949 | $claudeApiKey, |
| @@ -3883,14 +3949,16 @@ | ||
| 3883 | 3949 | $claudeApiKey, |
| 3884 | 3950 | $disabled |
| 3885 | 3951 | ); |
| 3886 | 3952 | echo '<button type="button" id="toggleClaudeApiKeyVisibility">' . esc_html__('Show', 'mxchat') . '</button>'; |
| 3887 | - | |
| 3953 | + | |
| 3954 | + // If the feature is not activated, show the overlay with a "Pro Only" message | |
| 3888 | 3955 | if (!$this->is_activated) { |
| 3889 | 3956 | echo '<div class="pro-feature-overlay">'; |
| 3890 | 3957 | echo '<a href="https://mxchat.ai/" target="_blank"><img src="' . plugin_dir_url(__FILE__) . '../images/pro-only-dark.png" alt="' . esc_attr__('Pro Only', 'mxchat') . '" /></a>'; |
| 3891 | 3958 | echo '</div>'; |
| 3892 | 3959 | } |
| 3960 | + | |
| 3893 | 3961 | echo '</div>'; |
| 3894 | 3962 | } |
| 3895 | 3963 | public function deepseek_api_key_callback() { |
| 3896 | 3964 | // Retrieve from your stored 'deepseek_api_key' in the mxchat_options array |
| @@ -3901,11 +3969,79 @@ | ||
| 3901 | 3969 | echo '<button type="button" id="toggleDeepSeekApiKeyVisibility">' . esc_html__('Show', 'mxchat') . '</button>'; |
| 3902 | 3970 | } |
| 3903 | 3971 | |
| 3904 | 3972 | |
| 3973 | +public function mxchat_woocommerce_consumer_key_callback() { | |
| 3974 | + // Load the entire 'mxchat_options' array | |
| 3975 | + $all_options = get_option('mxchat_options', []); | |
| 3905 | 3976 | |
| 3977 | + // Retrieve the WooCommerce consumer key or set a default | |
| 3978 | + $consumer_key = isset($all_options['woocommerce_consumer_key']) ? $all_options['woocommerce_consumer_key'] : ''; | |
| 3906 | 3979 | |
| 3980 | + // Check if the feature is activated (paid feature) | |
| 3981 | + $disabled = $this->is_activated ? '' : 'disabled'; | |
| 3982 | + $class = $this->is_activated ? 'pro-feature-wrapper active' : 'pro-feature-wrapper inactive'; | |
| 3907 | 3983 | |
| 3984 | + echo '<div class="' . esc_attr($class) . '">'; | |
| 3985 | + | |
| 3986 | + // Render the input field | |
| 3987 | + printf( | |
| 3988 | + '<input type="text" id="woocommerce_consumer_key" name="woocommerce_consumer_key" value="%s" class="regular-text" %s />', | |
| 3989 | + esc_attr($consumer_key), | |
| 3990 | + esc_attr($disabled) | |
| 3991 | + ); | |
| 3992 | + | |
| 3993 | + // Description for the input field | |
| 3994 | + echo '<p class="description">' . esc_html__('Enter your WooCommerce consumer key for integration.', 'mxchat') . '</p>'; | |
| 3995 | + | |
| 3996 | + // Pro feature overlay for non-activated users | |
| 3997 | + if (!$this->is_activated) { | |
| 3998 | + echo '<div class="pro-feature-overlay">'; | |
| 3999 | + echo '<a href="https://mxchat.ai/" target="_blank"><img src="' . plugin_dir_url(__FILE__) . '../images/pro-only-dark.png" alt="' . esc_attr__('Pro Only', 'mxchat') . '" /></a>'; | |
| 4000 | + echo '</div>'; | |
| 4001 | + } | |
| 4002 | + | |
| 4003 | + echo '</div>'; | |
| 4004 | +} | |
| 4005 | + | |
| 4006 | +public function mxchat_woocommerce_consumer_secret_callback() { | |
| 4007 | + // Get value with fallback | |
| 4008 | + $consumer_secret = isset($this->options['woocommerce_consumer_secret']) | |
| 4009 | + ? esc_attr($this->options['woocommerce_consumer_secret']) | |
| 4010 | + : ''; | |
| 4011 | + | |
| 4012 | + // Check if the feature is activated (paid feature) | |
| 4013 | + $disabled = $this->is_activated ? '' : 'disabled'; | |
| 4014 | + $class = $this->is_activated ? 'pro-feature-wrapper active' : 'pro-feature-wrapper inactive'; | |
| 4015 | + | |
| 4016 | + echo '<div class="' . esc_attr($class) . '">'; | |
| 4017 | + | |
| 4018 | + // Output the password input | |
| 4019 | + echo sprintf( | |
| 4020 | + '<input type="password" | |
| 4021 | + id="woocommerce_consumer_secret" | |
| 4022 | + name="woocommerce_consumer_secret" | |
| 4023 | + value="%s" | |
| 4024 | + class="regular-text" | |
| 4025 | + %s />', | |
| 4026 | + $consumer_secret, | |
| 4027 | + esc_attr($disabled) | |
| 4028 | + ); | |
| 4029 | + | |
| 4030 | + // Add show/hide button | |
| 4031 | + echo '<button type="button" id="toggleWooCommerceSecretVisibility">' . esc_html__('Show', 'mxchat') . '</button>'; | |
| 4032 | + | |
| 4033 | + // Pro feature overlay | |
| 4034 | + if (!$this->is_activated) { | |
| 4035 | + echo '<div class="pro-feature-overlay">'; | |
| 4036 | + echo '<a href="https://mxchat.ai/" target="_blank">'; | |
| 4037 | + echo '<img src="' . esc_url(plugin_dir_url(__FILE__) . '../images/pro-only-dark.png') . '" alt="' . esc_attr__('Pro Only', 'mxchat') . '" />'; | |
| 4038 | + echo '</a>'; | |
| 4039 | + echo '</div>'; | |
| 4040 | + } | |
| 4041 | + | |
| 4042 | + echo '</div>'; | |
| 4043 | +} | |
| 3908 | 4044 | public function mxchat_loops_api_key_callback() { |
| 3909 | 4045 | // Support both old and new format |
| 3910 | 4046 | $loops_api_key = isset($this->options['loops_api_key']) ? esc_attr($this->options['loops_api_key']) : ''; |
| 3911 | 4047 | |
| @@ -5266,9 +5402,9 @@ | ||
| 5266 | 5402 | public function mxchat_enqueue_admin_assets() { |
| 5267 | 5403 | wp_enqueue_style('wp-color-picker'); |
| 5268 | 5404 | |
| 5269 | 5405 | // Get the plugin version or file modification time for cache busting |
| 5270 | - $plugin_version = '2.0.4'; // Replace this with your plugin's version | |
| 5406 | + $plugin_version = '2.0.2'; // Replace this with your plugin's version | |
| 5271 | 5407 | |
| 5272 | 5408 | // File paths |
| 5273 | 5409 | $color_picker_js_path = plugin_dir_path(__FILE__) . '../js/my-color-picker.js'; |
| 5274 | 5410 | $embedding_check_js_path = plugin_dir_path(__FILE__) . '../js/embedding-check.js'; |