gpld_limit_dates_options

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Disable All Dates & Set Enabled Dates via Exceptions
    2. Block Date Range via Exceptions
  5. Since

Description

Filter the date limiting options for each field.

Usage

Apply to all GPLD-enabled Date fields on a specific form.

add_filter( 'gpld_limit_dates_options_FORMID', 'my_custom_function' );

Apply to a specific GPLD-enabled Date field on a specific form.

add_filter( 'gpld_limit_dates_options_FORMID_FIELDID', 'my_custom_function' );

Parameters

  • options array

    For global and form-specific variations, this will pass the configured options for all Date fields on the current or specified form.

    For field-specific variations, this will pass the configured options for the specified field.

    Each field has the following options:

    • minDate string

      The minimum date that can be selected. Can be either a field ID, a ‘mm/dd/yyyy’ string, or ‘{today}’.

    • minDateMod string

      A string representing the addition or subtraction of time to be applied to the $minDate (i.e. ‘+2 days’).

    • minDateExcludeBeforeToday bool

      If true, $minDate will be adjusted to the current date if it is before the current date. Only available when “Set Specific Date” is selected for $minDate.

    • minDateExcludeBeforeTodayMod string

      A string representing the addition or subtraction of time to be applied to the current date when $minDateExcludeBeforeToday is enabled (i.e. ‘+2 days’).

    • maxDate string

      The maximum date that can be selected. Can be either a field ID, a ‘mm/dd/yyyy’ string, or ‘{today}’.

    • maxDateMod string

      A string representing the addition or subtraction of time to be applied to the $maxDate (i.e. ‘+2 days’).

    • daysOfWeek array

      An array of integers representing the days of the week that should be available (e.g. 0 = Sunday, 1 = Monday, 6 = Saturday). Return a false value to make all days of the week available.

    • exceptions array

      An array of ‘mm/dd/yyyy’ date strings that should be excepted from all other rules. If a date is unavailable, adding an exception will make it available and vice versa.

    • dateFormat string

      The GF date format for the current field. Defaults to ‘mdy’.

    • exceptionMode string

      Specify the mode in which exceptions should be handled; ‘default’ = Blocked dates are available, Available dates are blocked; ‘disable’ = Excepted dates are all blocked; ‘enable’ = Excepted dates are all enabled.

  • form array

    The current Form object.

  • field array

    The current Field object.

Examples

Disable All Dates & Set Enabled Dates via Exceptions

This example enables only the dates selected on the Limit Dates Exceptions of a date field.

* Instruction Video: https://www.loom.com/share/46883f47e71447108f70fd725af8ee97
 */
add_filter( 'gpld_limit_dates_options_123_1', function( $options, $form, $field ) {

	$options['exceptionMode'] = 'enable';
	$options['disableAll']    = true;

Block Date Range via Exceptions

This example allows you to block a range of dates on a Date field.

add_filter( 'gpld_limit_dates_options_FORMID_FIELDID', 'gpld_except_date_ranges', 10, 3 );
function gpld_except_date_ranges( $options, $form, $field ) {
	/**
	 * Format: Start Date, End Date
	 */
	$ranges = array(
		array( '2016-07-15', '2017-01-01' ),
		array( '2020-12-10', '2020-12-20' ),
	);

	// do not modify below this line
	foreach ( $ranges as $range ) {
		$start_date = new DateTime( $range[0] );
		$end_date   = new DateTime( $range[1] );
		// include end date.
		$end_date->setTime( 0, 0, 1 );
		$period = new DatePeriod( $start_date, new DateInterval( 'P1D' ), $end_date );

		foreach ( $period as $date ) {
			$options['exceptions'][] = $date->format( 'm/d/Y' );
		}
	}

	$options['exceptionMode'] = 'disable';

Since

This filter is available since Gravity Forms Limit Dates 1.0.