Last active
May 8, 2023 10:34
-
-
Save adczk/e72fc7d55de43978152ff32757ad59b1 to your computer and use it in GitHub Desktop.
Forminator - datepicker: disable date ranges via ACF repeater (options page field)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: Forminator - datepicker: disable date ranges via ACF repeater (options page field) | |
| * Plugin URI: https://premium.wpmudev.org/ | |
| * Description: Forminator - datepicker: disable date ranges via ACF repeater (options page field) | |
| * Note: ACF date fields in repeater (options page) must have "return date format" set the same as Forminator datepicker date format | |
| * Make sure to adjust ACF fields names too | |
| * | |
| * Author: adczk | |
| * Author URI: https://premium.wpmudev.org/ | |
| * License: GPLv2 or later | |
| * | |
| * config in comment | |
| * use as MU plugin | |
| */ | |
| add_filter( 'forminator_field_date_markup', 'wpmu_forminator_datepicker_acf_ranges', 11, 2); | |
| function wpmu_forminator_datepicker_acf_ranges( $html, $field ) { | |
| $allowed_fields = array( 'date-1' ); // define datepicker fields ID this should be applied to | |
| ####################### | |
| if ( !in_array( $field['element_id'], $allowed_fields ) ) { | |
| return $html; | |
| } | |
| $date_ranges = array(); | |
| if( have_rows('date_ranges', 'option') ) { // adjust repeater field name here and in line below | |
| while ( have_rows('date_ranges', 'option') ) { | |
| the_row(); | |
| // adjust date start/end subfields names below | |
| $date_ranges[] = get_sub_field('start_date') . ' - ' . get_sub_field('end_date'); | |
| } | |
| $disabled_ranges = implode( ',', $date_ranges ); | |
| $html = str_replace( 'data-disable-range=""', 'data-disable-range="' .$disabled_ranges. '"', $html ); | |
| } | |
| return $html; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment