Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ultimate Member - Change date format to timestamp
<?php
add_filter('um_user_pre_updating_profile_array','um_custom_user_pre_updating_profile_array');
function um_custom_user_pre_updating_profile_array( $arr ){
global $ultimatemember;
foreach ($arr as $key => $value) {
$field = $ultimatemember->fields->get_field( $key );
if( $field['type'] == 'date' && ! empty( $value ) ){
$arr[ $key ] = strtotime( $value );
}
}
return $arr;
}
add_action('init','um_custom_init');
function um_custom_init(){
remove_filter('um_profile_field_filter_hook__date', 'um_profile_field_filter_hook__date', 99 );
}
add_filter('um_profile_field_filter_hook__date','um_custom_profile_field_filter_hook__date', 100, 2 );
function um_custom_profile_field_filter_hook__date( $value, $data ){
global $ultimatemember;
if( is_numeric( $value ) && ! strstr( $value , "/" ) ){
$value = date('Y-m-d', $value );
}
if ( $data['pretty_format'] == 1 ) {
$value = $ultimatemember->datetime->get_age( $value );
} else {
$value = $ultimatemember->datetime->format( $value, $data['format'] );
}
return $value;
}
add_filter('um_edit_date_field_value','um_custom_edit_date_field_value', 10, 2);
function um_custom_edit_date_field_value( $value, $key ){
$value = date('Y-m-d', $value );
return $value;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment