Automatically populating a date parameter within a shortcode

you can generate shortcodes and launch them with this function :
https://developer.wordpress.org/reference/functions/do_shortcode/

so you can do that in your plugin :

add_shortcode("MY_PLUGIN__forms_with_dates", function ($atts, $content, $tag) {


    $atts = shortcode_atts([
        "months" => 11,
        "id_form" => NULL,
    ], $atts, $tag);
    
    
    if (!isset($atts["id_form"])) {
        return "shortcode $tag : the argument id_form is missing.";
    }
    
    
    $shortcodes = "";
    
    $today = current_datetime()->setTime(12, 0, 0, 0);
    $year_today = wp_date("Y");
    $month_today = wp_date("m");
    
    
    foreach (range(0, $atts["months"]) as $months_diff) {
        
        $first_day = $today->setDate($year_today, $month_today - $months_diff, 1);
        $last_day = $today->setDate($year_today, $month_today - $months_diff + 1, 0);
        
        $first_day_shortcode = wp_date("Y-m-d", $first_day->getTimestamp());
        $last_day_shortcode = wp_date("Y-m-d", $last_day->getTimestamp());
        
        $shortcodes .= "[frm-stats";
            $shortcodes .= " id=$atts[id_form]";
            $shortcodes .= " type=count";
            $shortcodes .= " created_at_greater_than=\"$first_day_shortcode\"";
            $shortcodes .= " created_at_less_than=\"$last_day_shortcode\"";
        $shortcodes .= "]";
        
    }
    
    
    return do_shortcode($shortcodes);
    
});

with this new shortcode, you can for example use
[MY_PLUGIN__forms_with_dates id_form=862 months=3]
and the result will be equivalent to this :

[frm-stats id=862 type=count created_at_greater_than="2024-08-01" created_at_less_than="2024-08-31"]
[frm-stats id=862 type=count created_at_greater_than="2024-07-01" created_at_less_than="2024-07-31"]
[frm-stats id=862 type=count created_at_greater_than="2024-06-01" created_at_less_than="2024-06-30"]
[frm-stats id=862 type=count created_at_greater_than="2024-05-01" created_at_less_than="2024-05-31"]

techhipbettruvabetnorabahisbahis forumutaraftarium24eduedueduseduedusedueduseduedusedu