logo_url = QCLD_wpCHATBOT_IMG_URL . "/chatbot.png"; } function run(){ add_action('admin_init', array($this, 'qc_admin_notice_rating')); add_action('wp_ajax_qc_chatbot_feedback_notice_dismiss', array($this, 'notice_dismiss')); add_action('wp_ajax_qc_chatbot_blackfriday_notice_dismiss', array($this, 'blackfriday_notice_dismiss')); add_action('wp_ajax_qc_chatbot_generate_review_ai', array($this, 'generate_review_ai')); } public function blackfriday_notice_dismiss(){ if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field(wp_unslash($_POST['nonce'])), 'wp_chatbot' ) ) { wp_send_json_error( array( 'message' => 'Security check failed.' ) ); } if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => 'Unauthorized.' ) ); } update_option('wpbot-admin-notice-blackfriday', 'hide'); die(0); } public function notice_dismiss(){ if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field(wp_unslash($_POST['nonce'])), 'wp_chatbot' ) ) { wp_send_json_error( array( 'message' => 'Security check failed.' ) ); } if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => 'Unauthorized.' ) ); } update_option('wpbot-admin-notice-oninstallation', 'hide'); die(0); } /** * Check and Dismiss review message. * */ private function review_dismissal() { //delete_site_option( 'wp_analytify_review_dismiss' ); if ( ! is_admin() || ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'qc-'.$this->plugin_name.'-rating-nonce' ) || ! isset( $_GET['qc_'.$this->plugin_name.'_rating_dismiss'] ) ) { return; } update_option( 'qc_'.$this->plugin_name.'_rating_dismiss', 'yes' ); } /** * Set time to current so review notice will popup after X days */ function review_prending() { // delete_site_option( 'wp_analytify_review_dismiss' ); if ( ! is_admin() || ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'qc-'.$this->plugin_name.'-rating-nonce' ) || ! isset( $_GET['qc_'.$this->plugin_name.'_rating_later'] ) ) { return; } // Reset Time to current time. update_option( 'qc_'.$this->plugin_name.'_rating_active_time', time() ); } public function qc_admin_notice_rating(){ $this->review_dismissal(); $this->review_prending(); $activation_time = get_option( 'qc_'.$this->plugin_name.'_rating_active_time' ); $review_dismissal = get_option( 'qc_'.$this->plugin_name.'_rating_dismiss' ); if ( 'yes' == $review_dismissal ) { if( get_option( 'wpbot-admin-notice-oninstallation' ) && get_option( 'wpbot-admin-notice-oninstallation' ) == 'show' && $this->is_wpbot_page() ){ add_action( 'admin_enqueue_scripts', array($this, 'qc_load_rating_style') ); add_action( 'admin_notices', array( $this, 'admin_notice' ) ); } return; } if ( ! $activation_time ) { $activation_time = time(); add_option( 'qc_'.$this->plugin_name.'_rating_active_time', $activation_time ); } // 604800 = 7 Days in seconds. if ( time() - $activation_time > 604800 && $this->is_wpbot_page() ) { add_action( 'admin_enqueue_scripts', array($this, 'qc_load_rating_style') ); add_action( 'admin_notices' , array( $this, 'qc_rating_notice_message' ) ); }else{ if( get_option( 'wpbot-admin-notice-oninstallation' ) && get_option( 'wpbot-admin-notice-oninstallation' ) == 'show' && $this->is_wpbot_page() ){ add_action( 'admin_enqueue_scripts', array($this, 'qc_load_rating_style') ); add_action( 'admin_notices', array( $this, 'admin_notice' ) ); } } } public function admin_notice(){ ?>
admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'qc_chatbot_rating_nonce' ), ); wp_localize_script( 'qc_rating_js', 'qcld_rating_object', $translation_array ); wp_enqueue_script( 'qc_rating_js'); } public function qc_rating_notice_message(){ /*if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) { return; }*/ $scheme = ( wp_parse_url( isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '', PHP_URL_QUERY ) ) ? '&' : '?'; $url = esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'] . $scheme . 'qc_'.$this->plugin_name.'_rating_dismiss=yes')); $dismiss_url = wp_nonce_url( $url, 'qc-'.$this->plugin_name.'-rating-nonce' ); $_later_link = esc_url_raw($_SERVER['REQUEST_URI']) . $scheme . 'qc_'.$this->plugin_name.'_rating_later=yes'; $later_url = wp_nonce_url( $_later_link, 'qc-'.$this->plugin_name.'-rating-nonce' ); ?> 'Security check failed.' ) ); } if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => 'Unauthorized.' ) ); } // Predefined reviews as fallback $fallback_reviews = array( "WPBot is an absolute game-changer for WordPress! The AI integration is seamless, making customer support automated and highly responsive. Highly recommend it to anyone looking to enhance user interaction.", "I am highly impressed with the capabilities of this ChatBot. It is incredibly easy to set up and customize. The GPT/Gemini integration works flawlessly, taking customer engagement to the next level.", "WPBot is by far the best AI chatbot plugin for WordPress. It handles client queries with high accuracy and has significantly reduced our support workload. The setup is simple and user-friendly.", "Fantastic plugin with rich features! The customer service and automation options are top-notch. Integrating it with AI APIs was a breeze, and it functions perfectly on our site.", "A brilliant, highly intuitive chatbot plugin. It works exactly as described and has greatly boosted our lead generation. Truly a 5-star product with excellent developer support!" ); $selected_review = $fallback_reviews[ array_rand( $fallback_reviews ) ]; $prompt = "Write a short, engaging 5-star review (maximum 2-3 sentences) for the WordPress plugin 'AI ChatBot - WPBot'. Focus on its helpfulness, AI integration, or ease of use. Keep the tone friendly, helpful, and natural. Do not use quotes or placeholders."; // Check which AI is enabled $ai_enabled = get_option('ai_enabled'); $gemini_enabled = (get_option('qcld_gemini_enabled') == '1'); $grok_enabled = (get_option('qcld_grok_enabled') == '1'); $openrouter_enabled = (get_option('qcld_openrouter_enabled') == '1'); if ( $gemini_enabled ) { $gemini_api_key = get_option('qcld_gemini_api_key'); if ( ! empty( $gemini_api_key ) ) { $selected_model = get_option('qcld_gemini_model') ? get_option('qcld_gemini_model') : 'gemini-2.5-flash'; $api_url = 'https://generativelanguage.googleapis.com/v1/models/' . $selected_model . ':generateContent'; $data = array( 'contents' => array( array( 'role' => 'user', 'parts' => array( array( 'text' => $prompt ) ) ) ), ); $args = array( 'body' => json_encode( $data ), 'headers' => array( 'Content-Type' => 'application/json', 'X-goog-api-key' => $gemini_api_key, ), 'timeout' => 30, 'blocking' => true, ); $result = wp_remote_post( $api_url, $args ); if ( ! is_wp_error( $result ) && wp_remote_retrieve_response_code( $result ) === 200 ) { $body = json_decode( wp_remote_retrieve_body( $result ), true ); if ( isset( $body['candidates'][0]['content']['parts'][0]['text'] ) ) { $selected_review = trim( $body['candidates'][0]['content']['parts'][0]['text'] ); } } } } elseif ( $ai_enabled ) { $openai_api_key = get_option('open_ai_api_key'); if ( ! empty( $openai_api_key ) ) { $model = get_option( 'qcld_openai_custom_model' ); if ( empty( $model ) ) { $model = get_option( 'openai_engines', 'gpt-4o' ); } $api_url = 'https://api.openai.com/v1/chat/completions'; $data = array( 'model' => $model, 'messages' => array( array( 'role' => 'user', 'content' => $prompt ) ), ); $args = array( 'body' => json_encode( $data ), 'headers' => array( 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $openai_api_key, ), 'timeout' => 30, 'blocking' => true, ); $result = wp_remote_post( $api_url, $args ); if ( ! is_wp_error( $result ) && wp_remote_retrieve_response_code( $result ) === 200 ) { $body = json_decode( wp_remote_retrieve_body( $result ), true ); if ( isset( $body['choices'][0]['message']['content'] ) ) { $selected_review = trim( $body['choices'][0]['message']['content'] ); } } } } elseif ( $openrouter_enabled ) { $openrouter_api_key = get_option('qcld_openrouter_api_key'); if ( ! empty( $openrouter_api_key ) ) { $model = get_option( 'qcld_openrouter_model', 'google/gemini-2.5-pro' ); $api_url = 'https://openrouter.ai/api/v1/chat/completions'; $data = array( 'model' => $model, 'messages' => array( array( 'role' => 'user', 'content' => $prompt ) ), ); $args = array( 'body' => json_encode( $data ), 'headers' => array( 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $openrouter_api_key, ), 'timeout' => 30, 'blocking' => true, ); $result = wp_remote_post( $api_url, $args ); if ( ! is_wp_error( $result ) && wp_remote_retrieve_response_code( $result ) === 200 ) { $body = json_decode( wp_remote_retrieve_body( $result ), true ); if ( isset( $body['choices'][0]['message']['content'] ) ) { $selected_review = trim( $body['choices'][0]['message']['content'] ); } } } } elseif ( $grok_enabled ) { $grok_api_key = get_option('qcld_grok_api_key'); if ( ! empty( $grok_api_key ) ) { $model = get_option( 'qcld_grok_model', 'grok-2' ); $api_url = 'https://api.x.ai/v1/chat/completions'; $data = array( 'model' => $model, 'messages' => array( array( 'role' => 'user', 'content' => $prompt ) ), ); $args = array( 'body' => json_encode( $data ), 'headers' => array( 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $grok_api_key, ), 'timeout' => 30, 'blocking' => true, ); $result = wp_remote_post( $api_url, $args ); if ( ! is_wp_error( $result ) && wp_remote_retrieve_response_code( $result ) === 200 ) { $body = json_decode( wp_remote_retrieve_body( $result ), true ); if ( isset( $body['choices'][0]['message']['content'] ) ) { $selected_review = trim( $body['choices'][0]['message']['content'] ); } } } } // Clean up output $selected_review = trim( $selected_review, '"\'' ); wp_send_json_success( array( 'review' => $selected_review ) ); } } } $qc_wpbot_rating = new Wpbot_rating(); $qc_wpbot_rating->plugin_name = 'wpbot'; $qc_wpbot_rating->run();