AI Comment Creator Plugin

'.$alerts.'

UPGRADE MEMBERSHİP

'; } } function aicommentcreator_enqueue_scripts() { $my_plugin_dir = plugin_dir_url(__FILE__); wp_enqueue_script('jquery'); wp_register_script( 'aicommentcreatorjs',$my_plugin_dir.'js/aicommentcreator.js' , array(), false, true ); wp_enqueue_script( 'aicommentcreatorjs' ); } add_action( 'admin_enqueue_scripts', 'aicommentcreator_enqueue_scripts' ); function aicommentcreator_enqueue_styles(){ $my_plugin_dir = plugin_dir_url(__FILE__); $screen = get_current_screen(); $slug = $screen->id; if($slug == 'toplevel_page_aicommentcreator_menu' || $slug == 'ai-comment-creator_page_aicommentcreator_buyCredit' || $slug == 'ai-comment-creator_page_aicommentcreator_automaticComment' || $slug == 'ai-comment-creator_page_aicommentcreator_addComment' ){ wp_register_style('aicommentcreator_bootstrap', $my_plugin_dir.'css/bootstrap.min.css', array(), 1); wp_enqueue_style('aicommentcreator_bootstrap'); wp_register_style('aicommentcreator_style', $my_plugin_dir.'css/style.css', array(), 1); wp_enqueue_style('aicommentcreator_style'); } wp_register_style('aicommentcreator_loader', $my_plugin_dir.'css/loader.css', array(), 1); wp_enqueue_style('aicommentcreator_loader'); } add_action('admin_print_styles','aicommentcreator_enqueue_styles'); function aicommentcreator_addComment_setOptions(){ if($_POST){ $received_data = array( "comment_approved" => "1", "comment_post_ID" => absint( $_POST["select_posts"] ), // validate as integer "comment_author" => sanitize_text_field( $_POST["comment_fullname"] ), // sanitize as text "comment_author_email" => sanitize_email( $_POST["comment_email"] ), // sanitize as email "comment_content" => wp_kses_post( $_POST["comment_content"] ), // validate as post content ); $comment_result = wp_insert_comment($received_data); // Check if user wants to add avatar if (isset($_POST["avatar_url"]) && !empty($_POST["avatar_url"])) { $sanitized_url = esc_url_raw($_POST['avatar_url']); if (!filter_var($sanitized_url, FILTER_VALIDATE_URL)) { // handle invalid url input } $escaped_url = esc_url($sanitized_url); add_comment_meta($comment_result, 'avatar_url', $escaped_url); } if($comment_result != false){ echo '
' . esc_html( __( 'Your comment successfully posted! Comment ID: ', 'ai-comment-creator' ) ) . esc_html( $comment_result ) . '
'; } else { echo '
' . esc_html( __( 'Sorry there was an error sending your message. Please try again later', 'ai-comment-creator' ) ) . '
'; } } } function aicommentcreator_automaticComment_setOptions(){ if ($_POST) { if(empty($_POST["select_categories"])){ echo '
' . esc_html__('Please select at least 1 category.', 'ai-comment-creator') . '
'; } $time_value_type = sanitize_text_field($_POST["select_time_type"]); $user_wpcron_time = aicommentcreator_get_wpcron_time($time_value_type); if(empty($_POST["max_token"])){ echo '
' . esc_html__('Please select max token.', 'ai-comment-creator') . '
'; } if(empty($_POST["comment_prompt"])){ echo '
' . esc_html__('Please should select at least 1 comment prompt.', 'ai-comment-creator') . '
'; } if(!empty($_POST["select_categories"]) && !empty($_POST["max_token"]) && !empty($_POST["comment_prompt"]) ){ $received_data = array( "aicommentcreator_categories" => array_map('sanitize_text_field',$_POST["select_categories"]), "aicommentcreator_time_type" => sanitize_text_field($_POST["select_time_type"]), "aicommentcreator_comment_language" => sanitize_text_field($_POST["select_language"]), "aicommentcreator_max_token" => absint($_POST["max_token"]), "aicommentcreator_comment_prompt" => array_map('sanitize_text_field',$_POST["comment_prompt"]), "automatic_status" => sanitize_text_field($_POST["automatic_status"]), "select_avatar" => absint($_POST["select_avatar"]), "aicommentcreator_post_orderby" => sanitize_text_field($_POST["select_orderby"]), "aicommentcreator_post_order" => sanitize_text_field($_POST["select_order"]), ); $save = serialize($received_data); update_option('aicommentcreator_autocomment_settings', $save); if (!wp_next_scheduled('aicommentcreator_cronjob_autocomment')) { wp_schedule_event(time(), $user_wpcron_time, 'aicommentcreator_cronjob_autocomment'); } else { wp_clear_scheduled_hook('aicommentcreator_cronjob_autocomment'); wp_schedule_event(time(), $user_wpcron_time, 'aicommentcreator_cronjob_autocomment'); } if ($save != false) { echo '
' . esc_html__('Your settings have been successfully saved!', 'ai-comment-creator') . '
'; } else { echo '
' . esc_html__('Sorry, there was an error saving your settings. Please try again later.', 'ai-comment-creator') . '
'; } } } } function aicommentcreator_get_wpcron_time($time){ switch($time){ case 1: return 'hourly'; case 2: return 'twicedaily'; case 3: return 'daily'; case 4: return 'weekly'; default: return 'hourly'; } } function aicommentcreator_remove_element($array, $element){ $index = array_search($element, $array); if($index !== false){ array_splice($array, $index, 1); } return $array; } function aicommentcreator_get_last_post_by_category($category_ids,$post_count = 30,$order_by = 'date',$order = 'DESC') { $args = array( 'category__in' => $category_ids, 'orderby' => $order_by, 'order' => $order, 'numberposts' => $post_count ); $posts = get_posts($args); return $posts; } function aicommentcreator_get_user_info($json_data) { $data = json_decode($json_data, true); $user = $data["results"][0]; $name = $user["name"]["first"]; $last_name = $user["name"]["last"]; $email = $user["email"]; $user_avatar = $user["picture"]["large"]; $user_avatar_thumbnail = $user["picture"]["thumbnail"]; return array("name" => $name, "last_name" => $last_name, "email" => $email, "user_avatar" => $user_avatar, "user_avatar_thumbnail" => $user_avatar_thumbnail); } function aicommentcreator_parseHTML($string) { $string = preg_replace('/<[^>]*>/', '', $string); return $string; } function aicommentcreator_custom_avatar($avatar, $id_or_email, $size, $default, $alt) { $comment = get_comment($id_or_email); $comment_id = $comment->comment_ID; $avatar_url = get_comment_meta($comment_id, 'avatar_url', true); if (!empty($avatar_url)) { $custom_avatar = $avatar_url; } else { $custom_avatar = get_avatar_url($id_or_email); } return "" . $alt . ""; } add_filter('get_avatar', 'aicommentcreator_custom_avatar', 10, 5); function aicommentcreator_generate_comment_with_aicontentgenerator($domain_name,$prompt,$blog_post,$max_token, $selected_commment_text_language){ $url = 'https://www.aicontentgenerator.app/api/v3/generateComment'; $admin_email = get_option('admin_email', false); if ($admin_email !== false) { // seçenek varsa işlemlerinizi yapabilirsiniz } else { // seçenek yoksa, bir hata mesajı görüntüleyebilir veya varsayılan bir değer kullanabilirsiniz $admin_email = 'email@example.com'; } $data = array( 'userDomain' => $domain_name, 'userEmail' => sanitize_email($admin_email), 'maxToken' => $max_token, 'prompt' => $prompt, 'post' => $blog_post, 'comment_text_language' => $selected_commment_text_language ); $response = wp_remote_post( $url, array( 'timeout' => 2400, // Timeout set to 2 minutes. 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => json_encode($data) ) ); if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); return ""; } else { $response_data = wp_remote_retrieve_body($response); $responseData = json_decode($response_data, true); $text = $responseData['choices'][0]['text']; return $text; } } //Check subscription with WP-CRON - START // Deactivation hook register_deactivation_hook(__FILE__, 'aicommentcreator_subscription_checker_deactivate'); // Deactivation callback function function aicommentcreator_subscription_checker_deactivate() { // Check if the cron job is scheduled and unschedule it if (wp_next_scheduled('aicommentcreator_check_subscription_event')) { wp_clear_scheduled_hook('aicommentcreator_check_subscription_event'); } } // Uninstall hook register_uninstall_hook(__FILE__, 'aicommentcreator_subscription_checker_uninstall'); // Uninstall callback function function aicommentcreator_subscription_checker_uninstall() { // Check if the cron job is scheduled and unschedule it if (wp_next_scheduled('aicomentcreator_check_subscription_event')) { wp_clear_scheduled_hook('aicomentcreator_check_subscription_event'); } // Additional uninstall actions can be performed here if needed } // Activation hook register_activation_hook( __FILE__, 'aicommentcreator_subscription_checker_activate' ); // Activation callback function function aicommentcreator_subscription_checker_activate() { // Check if the cron job is already scheduled if ( ! wp_next_scheduled( 'aicommentcreator_check_subscription_event' ) ) { // Schedule the cron job to run every 30 minutes wp_schedule_event( time(), 'halfhourly', 'aicommentcreator_check_subscription_event' ); } } // Cron callback function function aicommentcreator_check_subscription() { // Get the subscription ID from plugin options $subscription_id = get_user_from_aicontentgenerator_api()['subscription_id']; // Check if the subscription ID is empty if (empty($subscription_id)) { return; // No subscription ID found, exit the function } // API request URL $api_url = 'https://aicontentgenerator.app/api/v3/checkSubscription'; // API request parameters $params = array( 'sub_id' => $subscription_id ); // Perform the API request using WordPress HTTP API $response = wp_remote_post($api_url, array('body' => $params)); // Check if the API request was successful if (is_wp_error($response)) { error_log('API request failed: ' . $response->get_error_message()); return; } // Get the response body $body = wp_remote_retrieve_body($response); // Parse the JSON response $data = json_decode($body); } // Hook into the cron event add_action( 'aicommentcreator_check_subscription_event', 'aicommentcreator_check_subscription' ); //Check subscription with WP-CRON - END //CRONJOB START // unschedule event upon plugin deactivation function aicommentcreator_cronstarter_deactivate() { // find out when the last event was scheduled $timestamp = wp_next_scheduled ('aicommentcreator_cronjob_autocomment'); // unschedule previous event if any wp_unschedule_event ($timestamp, 'aicommentcreator_cronjob_autocomment'); } register_deactivation_hook (__FILE__, 'aicommentcreator_cronstarter_deactivate'); //Register AIContentGenerator API with Domain function aicommentcreator_register_to_aicontentgenerator() { // Do something when plugin is activated //Register with Domain $admin_email = get_option('admin_email', false); if ($admin_email !== false) { // if admin email is not NULL } else { // if admin email is NULL $admin_email = 'email@example.com'; } $args = array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => array( 'userDomain' => sanitize_url(esc_url(get_site_url())), 'userEmail' => sanitize_email($admin_email) ), 'cookies' => array(), ); $response = wp_remote_post( 'https://aicontentgenerator.app/api/registerNewDomainPost', $args ); } register_activation_hook( __FILE__, 'aicommentcreator_register_to_aicontentgenerator' ); function aicommentcreator_cronjob_setAutoComment(){ $settings = unserialize(get_option('aicommentcreator_autocomment_settings')); if ($settings['automatic_status'] == 1) { //Start Auto Commenting aicommentcreator_cronjob_auto_comment(); } } // here's the function we'd like to call with our cron job function aicommentcreator_cronjob_auto_comment() { //Check if user have a enough credits in AIContentGenerator $credit = (int) get_user_from_aicontentgenerator_api()["user_token"]; //Get Options $selected_categories = unserialize(get_option("aicommentcreator_autocomment_settings"))["aicommentcreator_categories"]; $selected_language = unserialize(get_option("aicommentcreator_autocomment_settings"))["aicommentcreator_comment_language"]; $selected_prompt = unserialize(get_option("aicommentcreator_autocomment_settings"))["aicommentcreator_comment_prompt"]; $api_key = unserialize(get_option("aicommentcreator_settings"))["aicommentcreator_settings_apikey"]; $max_token = unserialize(get_option("aicommentcreator_autocomment_settings"))["aicommentcreator_max_token"]; $has_avatar = unserialize(get_option("aicommentcreator_autocomment_settings"))["select_avatar"]; $aicommentcreator_apikey = esc_url(get_site_url()); $post_order = unserialize(get_option("aicommentcreator_autocomment_settings"))["aicommentcreator_post_order"]; $post_orderby = unserialize(get_option("aicommentcreator_autocomment_settings"))["aicommentcreator_post_orderby"]; //Get last 5 post by selected categories $posts_selected= aicommentcreator_get_last_post_by_category($selected_categories,30,$post_orderby,$post_order); //Randomly select a post $random_post = $posts_selected[array_rand($posts_selected)]; //Create author info $response = wp_remote_get("https://randomuser.me/api?nat=".$selected_language); $json_data = wp_remote_retrieve_body($response); $user_info = aicommentcreator_get_user_info($json_data); //Get comment prompt if (!empty($selected_prompt)) { $prompt = $selected_prompt[array_rand($selected_prompt)]; } else { $prompt = "Please write a comment about the following blog post: "; } $domain_name = esc_url(get_site_url()); //Generate comment with AIContentGenerator API $comment_content = aicommentcreator_generate_comment_with_aicontentgenerator($domain_name, $prompt, $random_post->post_content, $max_token, $selected_language); $received_data = array( "comment_approved" => "1", "comment_post_ID" => $random_post->ID, "comment_author" => $user_info["name"] . " " . $user_info["last_name"], "comment_author_email" => change_email($user_info["email"]), "comment_content" => $comment_content, ); if($comment_content != ""){ $comment_id = wp_insert_comment($received_data); // Check if user want to add avatar if($has_avatar == 1){ add_comment_meta($comment_id, 'avatar_url', $user_info['user_avatar']); } //Add to database update_option('aicommentcreator_alerts', ''); }else{ //Add to database update_option('aicommentcreator_alerts', 'AI Comment Creator has stopped working because you exceeded the maximum comment limit of your package. Please upgrade your package to generate more comments! '); } } // hook that function onto our scheduled event: add_action ('aicommentcreator_cronjob_autocomment', 'aicommentcreator_cronjob_setAutoComment'); function change_email($email) { $username = strstr($email, '@', true); // extract the username before @ symbol $email_list = array('@hotmail.com','@gmail.com','@outlook.com','@yahoo.com','@icloud.com'); $newEmail = $username . $email_list[array_rand($email_list)]; // replace the domain with hotmail.com return $newEmail; } // create a scheduled event (if it does not exist already) function aicommentcreator_cronstarter_activation() { $selected_time_type = unserialize( get_option( "aicommentcreator_autocomment_settings" ) )["aicommentcreator_time_type"]; $time_type_str = aicommentcreator_get_wpcron_time($selected_time_type); if( !wp_next_scheduled( 'aicommentcreator_cronjob_autocomment' ) ) { wp_schedule_event( time(), $time_type_str, 'aicommentcreator_cronjob_autocomment' ); } } // and make sure it's called whenever WordPress loads add_action('wp', 'aicommentcreator_cronstarter_activation'); //CRONJOB END function get_user_from_aicontentgenerator_api() { //Get Credit from AIContentGenerator.APP API $url = 'https://aicontentgenerator.app/api/v3/getUserByDomain'; $admin_email = get_option('admin_email', false); if ($admin_email !== false) { // seçenek varsa işlemlerinizi yapabilirsiniz } else { // seçenek yoksa, bir hata mesajı görüntüleyebilir veya varsayılan bir değer kullanabilirsiniz $admin_email = 'email@example.com'; } $args = array( 'body' => array( 'user_domainname' => esc_url(get_site_url()), 'user_email' => sanitize_email($admin_email), 'timeout' => 120, // Timeout set to 2 minutes. ) ); $response = wp_remote_post($url, $args); $json = json_decode(wp_remote_retrieve_body($response), true); return $json; } function aicommentcreator_generalSettings(){ ?>
' . esc_html__('AI Comment Creator has stopped working because you exceeded the maximum comment limit of your package. Please upgrade your package to generate more comments!', 'ai-comment-creator') . ' ' . ''; } ?>


  • Basic
  • Free
  • 3 Comments per Month
  • Automatic/Manual
  • AI-generated Avatars
  • Multi-Prompts
  • Golden Membership
  • £ 5.99 / Month
  • 150 Comments per Month
  • Automatic/Manual
  • AI-generated Avatars
  • Multi-Prompts
  • Sign Up'; } ?>
  • Platin Membership
  • £ 19.99 / Month
  • 1000 Comments per Month
  • Automatic/Manual
  • AI-generated Avatars
  • Multi-Prompts
  • Sign Up'; } ?>
' . esc_html__('You are not a premium user so that is why you have ', 'ai-comment-creator') . esc_html($user_maxToken) . esc_html__(' token limit. If you want unlimited tokens, you should upgrade your membership to Golden or Platin.', 'ai-comment-creator') . '
'; echo ''; }else{ $tokenLimit = $user_maxToken; echo '
User Information

Membership Type: ' . $isUserPremium . '

Renewal Date: ' . $user['renewal_date'] . '

Comment Credit:' . $user_comment_balance . '

Max Token Limit: ' . $user_maxToken . '

'; } ?>

>
>
>
>
'; //Create hidden input for admin email echo ''; ?>
If you dont want to avatar, you can leave it blank.