Created
May 10, 2017 04:58
-
-
Save champsupertramp/cd67255150a95b6497a5e12f5f5968ad to your computer and use it in GitHub Desktop.
Ultimate Member - Change date format to timestamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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