Skip to content

Instantly share code, notes, and snippets.

@nikitasinelnikov
Created April 23, 2019 08:37
Show Gist options
  • Save nikitasinelnikov/a12d3cdad6a013046ea288c135e42545 to your computer and use it in GitHub Desktop.
Save nikitasinelnikov/a12d3cdad6a013046ea288c135e42545 to your computer and use it in GitHub Desktop.
Set current date as default value for datepicker field
/**
* 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