gpls_calendar_periods

  1. Description
  2. Usage
  3. Parameters
  4. Since
  5. Examples
    1. Custom Monthly Period

Description

Filter the available calendar periods available to Limit Submissions. Useful for adding custom periods such as periods starting on a specific day of the month.

Usage

add_filter( 'gpls_calendar_periods', 'my_custom_function' );

Parameters

  • periods array

    An array of calendar periods available to Limit Submissions.

Since

This filter is available since Gravity Forms Limit Submissions 1.1.4.

Examples

Custom Monthly Period

Add a custom monthly period that starts on the 24th of each month rather than the 1st.

add_filter( 'gpls_calendar_periods', function ( $periods ) {
	$periods['month_on_24th'] = array(
		'label'        => __( 'Per Month - Starting on the 24th', 'gp-limit-submissions' ),
		'value'        => 'month_on_24th',
		'sql_callback' => function ( $date_created_sql, $utc_timestamp_sql ) {
			$time_period_sql = "$date_created_sql >= 
				IF(DAYOFMONTH(CURRENT_TIMESTAMP()) < 24,
					DATE(DATE_FORMAT($utc_timestamp_sql - INTERVAL 1 month, '%Y-%m-24')),
					DATE(DATE_FORMAT($utc_timestamp_sql, '%Y-%m-24')))
				
				AND $date_created_sql <=
					IF(DAYOFMONTH(CURRENT_TIMESTAMP()) < 24,
				        DATE(DATE_FORMAT($utc_timestamp_sql, '%Y-%m-24')),
				        DATE(DATE_FORMAT($utc_timestamp_sql, '%Y-%m-24') + INTERVAL 1 MONTH))";

			return $time_period_sql;
		},
	);

	return $periods;
} );