Last active
February 8, 2021 18:28
-
-
Save xnau/87248e64c6d9eacae6f2ae1a77f6b562 to your computer and use it in GitHub Desktop.
Shows how to set the default date for a specific date field in Participants Database
This file contains 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 | |
/** | |
* Plugin Name: PDB Default Date | |
* Description: sets the default date for a specific date field | |
*/ | |
add_action( 'pdb-before_display_form_input', 'xnau_set_default_date' ); | |
/** | |
* | |
* @param PDb_Field_Item $field | |
*/ | |
function xnau_set_default_date( $field ) | |
{ | |
// set this to the name of the field you want to set the default date on | |
$date_field = 'date_acquired'; | |
if ( $field->name() === $date_field && $field->is_empty() ) { | |
/** | |
* this sets the date relative to the current date | |
* | |
* @see https://www.php.net/manual/en/function.strtotime.php | |
*/ | |
$field->value = strtotime( '-1 month' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment