Skip to content

Commit add8056

Browse files
committed
~ Refactored code.
1 parent b2bbb9e commit add8056

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

gp-populate-anything/gppa-acf-date-formatter.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@
1717
* Author URI: http://gravitywiz.com
1818
*/
1919
add_filter( 'gppa_process_template_value', function( $template_value, $field, $template_name, $populate, $object, $object_type, $objects ) {
20-
2120
if ( strpos( $field->cssClass, 'gppa-format-acf-date' ) === false ) {
2221
return $template_value;
2322
}
2423

2524
$timezone = new DateTimeZone( 'UTC' );
2625

27-
return wp_date( 'd/m/Y', strtotime( $template_value ), $timezone );
26+
try {
27+
// Attempt to parse the date value.
28+
$date = new DateTime( $template_value );
29+
$date->setTimezone( $timezone ); // Ensure it's parsed as UTC.
30+
31+
return wp_date( 'd/m/Y', $date->getTimestamp(), $timezone );
32+
} catch ( Exception $e ) {
33+
// Handle invalid date formats gracefully.
34+
return $template_value;
35+
}
2836
}, 10, 7 );

0 commit comments

Comments
 (0)