Created
April 23, 2019 08:37
-
-
Save nikitasinelnikov/a12d3cdad6a013046ea288c135e42545 to your computer and use it in GitHub Desktop.
Set current date as default value for datepicker field
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
/** | |
* Set current date if date value is empty | |
* | |
* @param string $value "Field Value" | |
* @param string $default "Field Key" | |
* @param string $key "Field Type" | |
* @param string $type "Field Default Value" | |
* @param array $data "Field Data" | |
* @return string | |
*/ | |
function um_field_value__default_datetime( $value, $default, $key, $type, $data ) { | |
if ( empty( $value ) && empty( $default ) && $type === 'date' ) { | |
$value = date( 'Y/m/d' ); | |
} elseif ( empty( $value ) && empty( $default ) && $type === 'time' ) { | |
$value = date( 'H:i' ); | |
} | |
return $value; | |
} | |
add_filter( 'um_field_value', 'um_field_value__default_datetime', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment