An easier way to manage and limit dates on WordPress Gravity Forms. This plugin enables you to select dates to block for multiple calendars at once with a simple view.
Needs Gravity Forms and Gravity Perks, along with the Gravity Perks limit dates perk.
Like any WordPress plugin, download zip and upload, or git clone into
First, just go to the plugin settings under the Gravity Forms tab in the WordPress dashboard.
Clarification on 'all', every form field selected in other contexts will show up under all. So for every field selected in every other context, this field will be blocked in 'all' settings. Hope that makes sense.
- Create multiple contexts for calendars to manage, selecting which date fields belong in which.
- Assign each context dates to block, selecting individual date fields from all forms available. Slider lets you choose how many months are visible at a time.
- Select the date fields to block on each context from the various form fields defined from Gravity Forms.
- Block every other context type at once with the 'ALL' context
On initialization, creates a new role, edit_gfx_calendar
to allow only administrators to access and edit the
limitations.
- Unit testing -
- Create a readme text file, with similar content. Follow WordPress guidelines.
- Splitting code chunks, hashing, etc., for performance, loading by the generated manifest.
- More comments on code for clarity, perhaps migrate to TypeScript for strict type checking.
- Perhaps handle calendar naming differently, to ease naming restrictions for calendar contexts.
- Allow customization of limitation mode, i.e. block or allow dates
- Use intermediary client state for selection of dates/choices of fields, thereby not bind UI to server state, less
perceived loading.
- Put the loading indicator on a corner instead of as overlay.
- Debounce server updates, less bandwidth on user.
- More documentation and screenshots in readme.txt
- Deploy to WordPress Plugins
- Make sure that Gravity Perks Limit Date Extension is enabled!
- Watch for changes -
npm run watch
- Lint:
npm run lint
- Production bundle built with
npm run build
command
Use the following snippet in your themes functions.php
file to prevent picking a range with a blocked date in it:
//change the form id and date field to the form and the departure date of the form
function prevent_dates_in_between_please( $result, $date, $form, $field ) {
// if minDate is dictated by another field, make sure the selected range does not contain a disabled date
if( !isset($_GET["disabledatelimits"]) & $result['is_valid'] && $field->{gp_limit_dates()->key( 'minDate' )} && is_numeric( $field->{gp_limit_dates()->key( 'minDate')} ) ) {
$start_date = rgpost( sprintf( 'input_%d', $field->{gp_limit_dates()->key( 'minDate')} ) );
if( $start_date ) {
$end_date = strtotime( $date );
$_date = strtotime( $start_date );
while( $_date < $end_date ) {
$_is_excepted = gp_limit_dates()->is_excepted( $_date, $field );
$_date = strtotime( '+1 day', $_date );
if( $_is_excepted ) {
$result['is_valid'] = false;
$result['message'] = 'One or more dates in the selected range are not available.';
break;
}
}
}
}
return $result;
}
// replace form_id and last_date_field_id
add_filter( 'gform_field_validation_{{FORM_ID}}_{{LAST_DATE_FIELD_ID}}', prevent_dates_in_between_please, 11, 4 );