I wanted to send the current time in the text of the email notification for the user data.
Unfortunately, the placeholder %%DATE_TIME%% does not work as I wanted.
It outputs the date as Y-m-d H: i: s format and not as j.m.Y H: i: s (which I have preset in the WordPress settings) in the e-mail.
I had already found this problem in a post several years old, but I didn't know the ID yet.
Hopefully it won't take as many years to get fixed.
I have escalated this bug to our 2nd Tier for another evaluation, and I'll share the workaround again here for other users to benefit from.
add_filter('cred_body_notification_codes', 'my_date_time_format', 999, 3);
function my_date_time_format($defaultPlaceHolders,$form_id,$post_id) {
if($form_id == 14) {
$new_datetime = date("d.m.Y H:i:s", strtotime($defaultPlaceHolders['%%DATE_TIME%%']));
$defaultPlaceHolders['%%DATE_TIME%%'] = $new_datetime;
return $defaultPlaceHolders;
}
}
I'll get back to you as soon as we have any feedback.
Hello again, our 2nd Tier has escalated this bug to the developers to be fixed in an upcoming release. He also improved the custom code solution that I shared to make it work for all forms, and to make it take the date_time format from the system instead of hardcoding it:
add_filter( 'cred_subject_notification_codes', 'ts_date_placeholder' );
add_filter( 'cred_body_notification_codes', 'ts_date_placeholder' );
function ts_date_placeholder( $placeholders ){
$date_format = get_option( 'date_format' );
$time_format = get_option( 'time_format' );
$now = date( $date_format.' '.$time_format, current_time( 'timestamp' ) );
$placeholders['%%DATE_TIME%%'] = $now;
return $placeholders;
}