Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created October 13, 2025 09:25
Show Gist options
  • Save andrewlimaza/71e17336e4c1c51013c956a71d795cc6 to your computer and use it in GitHub Desktop.
Save andrewlimaza/71e17336e4c1c51013c956a71d795cc6 to your computer and use it in GitHub Desktop.
PMPro Date Field limit minimum and maximum dates
<?php
// Example of using min and max input fields for date fields.
function my_pmpro_add_user_fields() {
// Don't break if PMPro is out of date or not loaded.
if ( ! function_exists( 'pmpro_add_user_field' ) ) {
return false;
}
// Store our field settings in an array.
$fields = array();
$fields[] = new PMPro_Field(
'my_date', // input name and user meta key
'date', // type of field
array(
'label' => 'date', // custom field label
'size' => 40, // input size
'class' => 'date', // custom class
'profile' => true, // show in user profile
'required' => true, // make this field required
'memberslistcsv' => true, // include in CSV export
'html_attributes' => array(
'min' => '1900-01-01',
'max' => '2030-12-31'
)
)
);
// Add a field group to put our fields into.
pmpro_add_field_group( 'Example Group Title' );
// Add all of our fields into that group.
foreach ( $fields as $field ) {
pmpro_add_user_field(
'Example Group Title', // Which group to add to.
$field // PMPro_Field object
);
}
}
add_action( 'init', 'my_pmpro_add_user_fields' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment