|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Gravity Wiz // Gravity Forms // Daily Form Schedule |
4 |
| - * |
5 |
| - * Allow your form schedule to apply daily. |
6 |
| - * |
7 |
| - * @version 1.3 |
8 |
| - * @author David Smith <[email protected]> |
9 |
| - * @license GPL-2.0+ |
10 |
| - * @link http://gravitywiz.com/ |
11 |
| - * |
12 |
| - * Plugin Name: Gravity Forms Daily Form Schedule |
13 |
| - * Plugin URI: http://gravitywiz.com/ |
14 |
| - * Description: Allow your form schedule to apply daily. |
15 |
| - * Author: Gravity Wiz |
16 |
| - * Version: 1.3 |
17 |
| - * Author URI: http://gravitywiz.com/ |
18 |
| - * |
19 |
| - * Usage: |
20 |
| - * |
21 |
| - * 1. Install and activate. |
22 |
| - * 2. Set your form schedule via Form Settings › Restrictions › Schedule form. |
23 |
| - * a. Specify your desired daily start and end times via the Start and End Time settings. |
24 |
| - * b. Leave the Start and End Date inputs EMPTY! |
25 |
| - * |
26 |
| - * Want to make your schedule weekly? |
27 |
| - * |
28 |
| - * 1. Follow the steps above. |
29 |
| - * 2. Specify the day of the week your schedule starts and ends with it's numeric equivalent. |
30 |
| - * a. Sunday = 0 |
31 |
| - * Monday = 1 |
32 |
| - * Tuesday = 2 |
33 |
| - * Wednesday = 3 |
34 |
| - * Thursday = 4 |
35 |
| - * Friday = 5 |
36 |
| - * Saturday = 6 |
37 |
| - * b. Enter the applicable day of the week number into the Start and End Date inputs respectively. |
38 |
| - * |
39 |
| - * That's it. This super simple plugin will automatically ensure that your schedule will apply daily (or weekly). 🙂 |
| 3 | + * This snippet is now available as a free plugin with Spellbook. ✨ |
| 4 | + * Instructions for installing this plugin can be found here: |
| 5 | + * https://gravitywiz.com/gravity-forms-flexible-form-schedules/ |
40 | 6 | */
|
41 |
| -add_filter( 'gform_pre_render', 'gw_daily_form_schedule' ); |
42 |
| -add_filter( 'gform_pre_validation', 'gw_daily_form_schedule' ); |
43 |
| -function gw_daily_form_schedule( $form ) { |
44 |
| - |
45 |
| - // Skip "Gravity Forms Daily Form Schedule" for the forms having set schedule start and schedule end date via Form Settings. |
46 |
| - if ( strstr( $form['scheduleStart'], '/' ) || strstr( $form['scheduleEnd'], '/' ) ) { |
47 |
| - return $form; |
48 |
| - } |
49 |
| - |
50 |
| - $days = array( 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday' ); |
51 |
| - |
52 |
| - if ( rgar( $form, 'scheduleForm' ) ) { |
53 |
| - |
54 |
| - // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested |
55 |
| - $time = current_time( 'timestamp' ); |
56 |
| - $is_interweek = false; |
57 |
| - |
58 |
| - if ( ! $form['scheduleStart'] || $form['scheduleStart'] <= 6 ) { |
59 |
| - if ( ! rgblank( $form['scheduleStart'] ) && $form['scheduleStart'] <= 6 ) { |
60 |
| - |
61 |
| - $is_interweek = $form['scheduleStart'] > $form['scheduleEnd']; |
62 |
| - // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date |
63 |
| - $current_day = (int) date( 'w' ); |
64 |
| - |
65 |
| - // If it's a Thursday and the schedule starts on Friday, assume the current schedule is for the previous week. |
66 |
| - // Pro Tip: In PHP, Monday is the first day of the week. |
67 |
| - $is_current_day_less_than_schedule_day = $current_day < $form['scheduleStart'] && $current_day !== 0; |
68 |
| - $use_last_week = $is_interweek && $is_current_day_less_than_schedule_day; |
69 |
| - $week_phrase = (int) $form['scheduleStart'] === 0 || $use_last_week ? 'last week' : 'this week'; |
70 |
| - |
71 |
| - // Sunday last week, Monday this week. |
72 |
| - $time = strtotime( "{$days[ $form['scheduleStart'] ]} {$week_phrase}", $time ); |
73 |
| - |
74 |
| - } |
75 |
| - |
76 |
| - // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date |
77 |
| - $form['scheduleStart'] = date( 'm/d/Y', $time ); |
78 |
| - } |
79 |
| - |
80 |
| - if ( ! $form['scheduleEnd'] || $form['scheduleEnd'] <= 6 ) { |
81 |
| - if ( ! rgblank( $form['scheduleEnd'] ) && $form['scheduleEnd'] <= 6 ) { |
82 |
| - $week_phrase = $is_interweek ? 'next week' : 'this week'; |
83 |
| - $time = strtotime( "{$days[ $form['scheduleEnd'] ]} {$week_phrase}", $time ); |
84 |
| - } |
85 |
| - |
86 |
| - // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date |
87 |
| - $form['scheduleEnd'] = date( 'm/d/Y', $time ); |
88 |
| - } |
89 |
| - } |
90 |
| - |
91 |
| - return $form; |
92 |
| -} |
0 commit comments