PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
← All changes | includes/class-give-cron.php +106 -32 2.3.24.17.0 View file →
@@ -45,11 +45,11 @@
45 45
46 46 /**
47 47 * Get instance.
48 48 *
49 + * @return static
49 50 * @since 1.8.13
50 51 * @access public
51 - * @return static
52 52 */
53 53 public static function get_instance() {
54 54 if ( null === static::$instance ) {
55 55 self::$instance = new static();
@@ -62,32 +62,46 @@
62 62
63 63 /**
64 64 * Setup
65 65 *
66 + * @since 4.9.0 rename function - PHP 8 compatibility
66 67 * @since 1.8.13
67 68 */
68 69 private function setup() {
69 - add_filter( 'cron_schedules', array( self::$instance, '__add_schedules' ) );
70 - add_action( 'wp', array( self::$instance, '__schedule_events' ) );
70 + add_filter( 'cron_schedules', array( self::$instance, 'add_schedules' ) );
71 + add_action( 'wp', array( self::$instance, 'schedule_events' ) );
71 72 }
72 73
73 74 /**
74 75 * Registers new cron schedules
75 76 *
77 + * @param array $schedules An array of non-default cron schedules.
78 + *
79 + * @return array An array of non-default cron schedules.
80 + *
81 + * @since 4.9.0 rename function - PHP 8 compatibility
76 82 * @since 1.3.2
77 83 * @access public
78 - *
79 - * @param array $schedules An array of non-default cron schedules.
80 - *
81 - * @return array An array of non-default cron schedules.
82 84 */
83 - public function __add_schedules( $schedules = array() ) {
85 + public function add_schedules( $schedules = array() ) {
84 86 // Adds once weekly to the existing schedules.
85 87 $schedules['weekly'] = array(
86 - 'interval' => 604800,
88 + 'interval' => 604800, // 7 * 24 * 3600
87 89 'display' => __( 'Once Weekly', 'give' ),
88 90 );
89 91
92 + // Adds once weekly to the existing schedules.
93 + $schedules['monthly'] = array(
94 + 'interval' => 2592000, // 30 * 24 * 3600
95 + 'display' => __( 'Once Monthly', 'give' ),
96 + );
97 +
98 + // Adds every third day to the existing schedules.
99 + $schedules['thricely'] = array(
100 + 'interval' => 259200, // 3 * 24 * 3600
101 + 'display' => __( 'Every Third Day', 'give' ),
102 + );
103 +
90 104 return $schedules;
91 105 }
92 106
93 107 /**
@@ -92,25 +106,40 @@
92 106
93 107 /**
94 108 * Schedules our events
95 109 *
110 + * @return void
111 + *
112 + * @since 4.9.0 rename function - PHP 8 compatibility
96 113 * @since 1.3.2
97 114 * @access public
115 + */
116 + public function schedule_events() {
117 + $this->monthly_events();
118 + $this->weekly_events();
119 + $this->daily_events();
120 + $this->thricely_events();
121 + }
122 +
123 + /**
124 + * Schedule monthly events
98 125 *
99 126 * @return void
127 + * @since 2.5.0
128 + * @access private
100 129 */
101 - public function __schedule_events() {
102 - $this->weekly_events();
103 - $this->daily_events();
130 + private function monthly_events() {
131 + if ( ! wp_next_scheduled( 'give_monthly_scheduled_events' ) ) {
132 + wp_schedule_event( current_time( 'timestamp' ), 'monthly', 'give_monthly_scheduled_events' );
133 + }
104 134 }
105 135
106 136 /**
107 137 * Schedule weekly events
108 138 *
139 + * @return void
109 140 * @since 1.3.2
110 141 * @access private
111 - *
112 - * @return void
113 142 */
114 143 private function weekly_events() {
115 144 if ( ! wp_next_scheduled( 'give_weekly_scheduled_events' ) ) {
116 145 wp_schedule_event( current_time( 'timestamp' ), 'weekly', 'give_weekly_scheduled_events' );
@@ -119,12 +148,11 @@
119 148
120 149 /**
121 150 * Schedule daily events
122 151 *
152 + * @return void
123 153 * @since 1.3.2
124 154 * @access private
125 - *
126 - * @return void
127 155 */
128 156 private function daily_events() {
129 157 if ( ! wp_next_scheduled( 'give_daily_scheduled_events' ) ) {
130 158 wp_schedule_event( current_time( 'timestamp' ), 'daily', 'give_daily_scheduled_events' );
@@ -131,24 +159,46 @@
131 159 }
132 160 }
133 161
134 162 /**
163 + * Schedule thricely events
164 + *
165 + * @return void
166 + * @since 2.5.11
167 + * @access private
168 + */
169 + private function thricely_events() {
170 + if ( ! wp_next_scheduled( 'give_thricely_scheduled_events' ) ) {
171 + wp_schedule_event( current_time( 'timestamp' ), 'thricely', 'give_thricely_scheduled_events' );
172 + }
173 + }
174 +
175 + /**
135 176 * get cron job action name
136 177 *
137 - * @since 1.8.13
138 - * @access public
139 - *
140 178 * @param string $type
141 179 *
142 180 * @return string
181 + * @since 1.8.13
182 + * @access public
143 183 */
144 184 public static function get_cron_action( $type = 'weekly' ) {
185 + $cron_action = '';
186 +
145 187 switch ( $type ) {
146 188 case 'daily':
147 189 $cron_action = 'give_daily_scheduled_events';
148 190 break;
149 191
150 - default:
192 + case 'thricely':
193 + $cron_action = 'give_thricely_scheduled_events';
194 + break;
195 +
196 + case 'monthly':
197 + $cron_action = 'give_monthly_scheduled_events';
198 + break;
199 +
200 + case 'weekly':
151 201 $cron_action = 'give_weekly_scheduled_events';
152 202 break;
153 203 }
154 204
@@ -157,41 +207,65 @@
157 207
158 208 /**
159 209 * Add action to cron action
160 210 *
211 + * @param string $callback
212 + * @param string $type
213 + *
161 214 * @since 1.8.13
162 215 * @access private
163 - *
164 - * @param $action
165 - * @param string $type
166 216 */
167 - private static function add_event( $action, $type = 'weekly' ) {
217 + private static function add_event( $callback, $type = 'weekly' ) {
168 218 $cron_event = self::get_cron_action( $type );
169 - add_action( $cron_event, $action );
219 + add_action( $cron_event, $callback );
170 220 }
171 221
172 222 /**
173 223 * Add weekly event
174 224 *
225 + * @param string $callback
226 + *
175 227 * @since 1.8.13
176 228 * @access public
177 - *
178 - * @param $action
179 229 */
180 - public static function add_weekly_event( $action ) {
181 - self::add_event( $action, 'weekly' );
230 + public static function add_weekly_event( $callback ) {
231 + self::add_event( $callback );
182 232 }
183 233
184 234 /**
185 235 * Add daily event
186 236 *
237 + * @param $callback
238 + *
187 239 * @since 1.8.13
188 240 * @access public
241 + */
242 + public static function add_daily_event( $callback ) {
243 + self::add_event( $callback, 'daily' );
244 + }
245 +
246 + /**
247 + * Add thricely event
189 248 *
190 - * @param $action
249 + * @param $callback
250 + *
251 + * @since 2.5.11
252 + * @access public
191 253 */
192 - public static function add_daily_event( $action ) {
193 - self::add_event( $action, 'daily' );
254 + public static function add_thricely_event( $callback ) {
255 + self::add_event( $callback, 'thricely' );
256 + }
257 +
258 + /**
259 + * Add monthly event
260 + *
261 + * @param $callback
262 + *
263 + * @since 2.5.0
264 + * @access public
265 + */
266 + public static function add_monthly_event( $callback ) {
267 + self::add_event( $callback, 'monthly' );
194 268 }
195 269 }
196 270
197 271 // Initiate class.