/*
 Theme Name:   Soledad Child Theme
 Theme URI:    http://pencidesign.com/
 Description:  Soledad Child Theme - Made by PenciDesign
 Author:       Pencidesign
 Version:      1.0
 Author URI:   http://pencidesign.com/
 Template:     soledad
 Text Domain:  soledad
*/

/* = Theme customization go here
-------------------------------------------------------------- */
// Generate random date between two dates
function random_date_in_range($start_date, $end_date) {
    $start_timestamp = strtotime($start_date);
    $end_timestamp = strtotime($end_date);
    $random_timestamp = mt_rand($start_timestamp, $end_timestamp);
    return date("Y-m-d", $random_timestamp);
}

// Random list of 100 names
function get_random_name() {
    $names = [
        'John', 'Emily', 'Michael', 'Sarah', 'David', 'Jessica', 'Daniel', 'Laura', 
        'James', 'Hannah', 'Robert', 'Emma', 'Paul', 'Olivia', 'Peter', 'Sophia', 
        'Mark', 'Chloe', 'Kevin', 'Megan', 'Jason', 'Amy', 'Ryan', 'Katie', 'Alex', 
        'Zoe', 'Chris', 'Molly', 'Tom', 'Jasmine', 'Jacob', 'Ella', 'Kyle', 'Isabella', 
        'Steven', 'Grace', 'Aaron', 'Mia', 'Richard', 'Lily', 'Scott', 'Natalie', 
        'Andrew', 'Sophie', 'Adam', 'Victoria', 'Samuel', 'Alice', 'Joseph', 'Ruby', 
        'Nathan', 'Ella', 'Ben', 'Lucy', 'Luke', 'Georgia', 'Jack', 'Abigail', 
        'Harry', 'Rebecca', 'Liam', 'Charlotte', 'Ethan', 'Bethany', 'Jake', 'Eleanor', 
        'Zach', 'Holly', 'Connor', 'Eva', 'Declan', 'Samantha', 'Owen', 'Lydia', 
        'Evan', 'Rosie', 'Lewis', 'Madison', 'Cameron', 'Ivy', 'Max', 'Scarlett', 
        'Isaac', 'Amber', 'Sebastian', 'Martha', 'Oscar', 'Maria', 'Tyler', 'Daisy', 
        'George', 'Lara', 'Henry', 'Eliza', 'Caleb', 'Leah', 'Patrick', 'Heidi'
    ];
    return $names[array_rand($names)];
}

// Random comment templates related to freelancing
function get_random_comment() {
    $comments = [
        "Great post about Fiverr tips! It really helped me improve my profile.",
        "Thanks for the advice on getting my first freelancing job!",
        "I just started on Fiverr and this post gave me confidence to keep going.",
        "These freelancing tips are spot on. Thank you for sharing!",
        "Great insight! I've been struggling with my gigs, but this gave me new ideas.",
        "This blog has really opened my eyes to freelancing strategies!",
        "I'm glad I found this post. Fiverr has been challenging, but this helps!",
        "Excellent points! I'm applying these tips to improve my freelancing game.",
        "This blog has been so helpful for my freelancing journey. Thank you!",
        "Amazing post! Your tips have boosted my confidence to take on more gigs."
    ];
    return $comments[array_rand($comments)];
}

// Function to insert exactly 100 random comments into blog posts
function generate_100_random_comments() {
    global $wpdb;

    // Get all blog posts
    $posts = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish'");

    $comment_count = 100; // Set total number of comments to generate

    // Calculate how many comments to assign to each post
    $remaining_comments = $comment_count;
    $post_comments = [];

    // Randomly assign 1-5 comments per post
    foreach ($posts as $post) {
        $max_comments = min(5, $remaining_comments);
        $assigned_comments = rand(1, $max_comments);
        $post_comments[$post->ID] = $assigned_comments;
        $remaining_comments -= $assigned_comments;
        if ($remaining_comments <= 0) {
            break;
        }
    }

    // Insert comments into the posts
    foreach ($post_comments as $post_id => $num_comments) {
        for ($i = 0; $i < $num_comments; $i++) {
            $comment_data = array(
                'comment_post_ID' => $post_id,
                'comment_author' => get_random_name(),
                'comment_content' => get_random_comment(),
                'comment_date' => random_date_in_range('2024-01-01', date('Y-m-d')),
                'comment_approved' => 1,
            );
            wp_insert_comment($comment_data);
        }
    }
}

// Hook the function to run manually

add_action('admin_init', 'generate_100_random_comments');

