As @amit wrote, the submission should have a daily counter that saves the count for that user, in the wp_usermeta table.
If you can run a cron job that runs daily, you can save the submission counter only. The daily cron can reset the counter on assigned time. But if you don’t you should save the counter and the day also.
$current_user = wp_get_current_user();
$old_count = get_user_meta($current_user->ID,'form-counter', true);
if($old_count['day'] == $today){ // still the same day
$new_count['day'] = $today;
$new_count['count'] = $old_count;
} else { // the day after the last submission
$new_count['day'] = $today;
$new_count['count'] = 1;
}
update_user_meta( $current_user->ID, 'form-counter', $new_count, $old_count);
The form itself can have a simple conditional that checks current user’s meta value.
$current_user = wp_get_current_user();
$counter = get_user_meta($current_user->ID,'form-counter', true);
if($counter['day'] != $today || ($counter['day'] == $today && $counter['count'] < 5)){
get_template_part('form');
} else {
echo ' You have reached your daily limit';
}
Hope this help
Update
I’m not sure how your form handle ajax using the get_author_custom_permalink()
.
Here is the code that goes to your functions.php, if you are using wp_ajax to handle form submission.
Please note that this code is untested.
add_action('wp_ajax_my_custom_form', 'process_my_custom_form');
function process_my_custom_form() {
global $current_user;
// validate nonce
if ( empty($_POST) || !wp_verify_nonce($_POST[$current_user->user_login],'form_process') ) {
echo 'You targeted the right function, but sorry, your nonce did not verify.';
die();
} else {
// validate post data
$input_1 = $_POST['input_1'];
$input_2 = $_POST['input_2'];
// process data
// start counter here
$old_count = get_user_meta($current_user->ID,'form-counter', true);
$today = date('YY-MM-DD');
// check if the user havent sent a submission at all
if(!$old_count){
$new_count['day'] = $today;
$new_count['count'] = 0;
}
if($old_count['day'] == $today){ // still the same day
$new_count['day'] = $today;
$new_count['count'] = $old_count;
} else { // the day after the last submission
$new_count['day'] = $today;
$new_count['count'] = 1;
}
update_user_meta( $current_user->ID, 'form-counter', $new_count, $old_count);
$submission_limit = 5
$message="You have ".$submission_limit - $new_count['count'].' submission left';
echo $message;
die();
}
}
And on your form
$counter = get_user_meta($current_user->ID,'form-counter', true);
$submission_limit = 5
if($counter['day'] != $today || ($counter['day'] == $today && $counter['count'] < $submission_limit)){
echo 'You have '.$submission_limit - $counter['count'].' submission left';
get_template_part('form');
} else {
echo ' You have reached your daily limit';
}