Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Date selector (datebox) control doesn’t allow future dates


r-a-y
Keymaster

@r-a-y

There’s a bug in the ‘bp_get_the_profile_field_datebox’ that’s preventing overriding the date field.
See – https://trac.buddypress.org/ticket/2947.

@bobsie – To override the year value temporarily, you’ll need to patch /buddypress/bp-xprofile/bp-xprofile-templatetags.php:
https://trac.buddypress.org/attachment/ticket/2947/2947.001.patch (only lines 457-534 are important).

Once you’ve made those changes, add the following to your theme’s functions.php:

`
function my_datebox_field ($html, $type, $day, $month, $year, $default_select ) {

// change your max year here
$year_max = 2013;

/* Check for updated posted values, but errors preventing them from being saved first time */
if ( !empty( $_POST ) ) {
if ( $day != $_POST )
$day = $_POST;
}

if ( !empty( $_POST ) ) {
if ( $month != $_POST )
$month = $_POST;
}

if ( !empty( $_POST ) ) {
if ( $year != date( “j”, $_POST ) )
$year = $_POST;
}

$html = ”;

switch ( $type ) {
case ‘day’:
$html .= ‘–‘;

for ( $i = 1; $i < 32; $i++ ) {
if ( $day == $i ) {
$selected = ‘ selected = “selected”‘;
} else {
$selected = ”;
}
$html .= ” . $i . ”;
}
break;

case ‘month’:
$eng_months = array( ‘January’, ‘February’, ‘March’, ‘April’, ‘May’, ‘June’, ‘July’, ‘August’, ‘September’, ‘October’, ‘November’, ‘December’ );

$months = array( __( ‘January’, ‘buddypress’ ), __( ‘February’, ‘buddypress’ ), __( ‘March’, ‘buddypress’ ),
__( ‘April’, ‘buddypress’ ), __( ‘May’, ‘buddypress’ ), __( ‘June’, ‘buddypress’ ),
__( ‘July’, ‘buddypress’ ), __( ‘August’, ‘buddypress’ ), __( ‘September’, ‘buddypress’ ),
__( ‘October’, ‘buddypress’ ), __( ‘November’, ‘buddypress’ ), __( ‘December’, ‘buddypress’ )
);

$html .= ‘


‘;

for ( $i = 0; $i < 12; $i++ ) {
if ( $month == $eng_months[$i] ) {
$selected = ‘ selected = “selected”‘;
} else {
$selected = ”;
}

$html .= ” . $months[$i] . ”;
}
break;

case ‘year’:
$html .= ‘—-‘;

for ( $i = $year_max; $i > 1899; $i– ) {
if ( $year == $i ) {
$selected = ‘ selected = “selected”‘;
} else {
$selected = ”;
}

$html .= ” . $i . ”;
}
break;
}

return $html;
}
add_filter( ‘bp_get_the_profile_field_datebox’, ‘my_datebox_field’, 10, 6 );
`

Skip to toolbar