Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active February 8, 2021 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/87248e64c6d9eacae6f2ae1a77f6b562 to your computer and use it in GitHub Desktop.
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
<?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