I'm not much of a coder and I need to modify the following code to remove all options that are before today instead of just the 2 days in the array shown.
add_filter('frm_setup_new_fields_vars', 'remove_field_option', 30, 2);
add_filter('frm_setup_edit_fields_vars', 'remove_field_option', 30, 2);
function remove_field_option( $values, $field ) {
if ( $field->id == 242 ) {
$timestamp = time();
$options_to_remove = array( '2016-08-19', '2016-08-20' )
foreach ( $options_to_remove as $remove ) {
$option_key = array_search( $remove, $values['options'] );
if ( $option_key !== false ) {
unset( $values['options'][ $option_key ] );
}
}
}
return $values;
}
if you want to go with your way using $options_remove array
$newArray = array_filter($oldArray,function($a) {
global $options_remove;
return !in_array($a,$options_remove);
});
OR something like this
$today = mktime(0, 0, 0, date("m") , date("d"), date("Y"));
$newArray = array_filter($oldArray,function($a) {
// your old array assumed to hold the date or datetime as value such as '2016-08-11' or '2016-08-11 08:11:23'
global $today;
return strtotime($a) < $today;
});
$newarray holds value for time less than start of today. so until end of yesterday