Completed
Push — master ( e28fbc...c4731d )
by Stephanie
16s queued 11s
created
classes/models/FrmFormAction.php 1 patch
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	}
30 30
 
31 31
 	/**
32
-     * Echo the settings update form
32
+	 * Echo the settings update form
33 33
 	 *
34 34
 	 * @param array $instance Current settings
35 35
 	 */
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
 	 * @return array of the default options
43 43
 	 */
44 44
 	public function get_defaults() {
45
-	    return array();
45
+		return array();
46 46
 	}
47 47
 
48 48
 	public function get_switch_fields() {
49
-	    return array();
49
+		return array();
50 50
 	}
51 51
 
52 52
 	public function migrate_values( $action, $form ) {
53
-	    return $action;
53
+		return $action;
54 54
 	}
55 55
 
56 56
 	// Functions you'll need to call.
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
 		$this->name = $name;
78 78
 		$this->option_name = 'frm_' . $this->id_base . '_action';
79 79
 
80
-        $default_options = array(
81
-            'classes'   => '',
82
-            'active'    => true,
80
+		$default_options = array(
81
+			'classes'   => '',
82
+			'active'    => true,
83 83
 			'event'     => array( 'create' ),
84
-            'limit'     => 1,
85
-            'force_event' => false,
86
-            'priority'  => 20,
87
-            'ajax_load' => true,
88
-            'tooltip'   => $name,
89
-        );
84
+			'limit'     => 1,
85
+			'force_event' => false,
86
+			'priority'  => 20,
87
+			'ajax_load' => true,
88
+			'tooltip'   => $name,
89
+		);
90 90
 
91 91
 		$action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
92 92
 		$this->action_options = wp_parse_args( $action_options, $default_options );
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
 	}
136 136
 
137 137
 	public function prepare_new( $form_id = false ) {
138
-        if ( $form_id ) {
139
-            $this->form_id = $form_id;
140
-        }
138
+		if ( $form_id ) {
139
+			$this->form_id = $form_id;
140
+		}
141 141
 
142
-        $post_content = array();
143
-        $default_values = $this->get_global_defaults();
142
+		$post_content = array();
143
+		$default_values = $this->get_global_defaults();
144 144
 
145 145
 		// fill default values
146 146
 		$post_content = wp_parse_args( $post_content, $default_values );
@@ -149,118 +149,118 @@  discard block
 block discarded – undo
149 149
 			$post_content['event'] = array( reset( $this->action_options['event'] ) );
150 150
 		}
151 151
 
152
-        $form_action = array(
153
-            'post_title'    => $this->name,
154
-            'post_content'  => $post_content,
155
-            'post_excerpt'  => $this->id_base,
156
-            'ID'            => '',
157
-            'post_status'   => 'publish',
158
-            'post_type'     => FrmFormActionsController::$action_post_type,
152
+		$form_action = array(
153
+			'post_title'    => $this->name,
154
+			'post_content'  => $post_content,
155
+			'post_excerpt'  => $this->id_base,
156
+			'ID'            => '',
157
+			'post_status'   => 'publish',
158
+			'post_type'     => FrmFormActionsController::$action_post_type,
159 159
 			'post_name'     => $this->form_id . '_' . $this->id_base . '_' . $this->number,
160
-            'menu_order'    => $this->form_id,
161
-        );
160
+			'menu_order'    => $this->form_id,
161
+		);
162 162
 		unset( $post_content );
163 163
 
164
-        return (object) $form_action;
165
-    }
164
+		return (object) $form_action;
165
+	}
166 166
 
167 167
 	public function create( $form_id ) {
168
-        $this->form_id = $form_id;
168
+		$this->form_id = $form_id;
169 169
 
170
-        $action = $this->prepare_new();
170
+		$action = $this->prepare_new();
171 171
 
172 172
 		return $this->save_settings( $action );
173
-    }
173
+	}
174 174
 
175 175
 	public function duplicate_form_actions( $form_id, $old_id ) {
176
-        if ( $form_id == $old_id ) {
177
-            // don't duplicate the actions if this is a template getting updated
178
-            return;
179
-        }
176
+		if ( $form_id == $old_id ) {
177
+			// don't duplicate the actions if this is a template getting updated
178
+			return;
179
+		}
180 180
 
181
-        $this->form_id = $old_id;
182
-        $actions = $this->get_all( $old_id );
181
+		$this->form_id = $old_id;
182
+		$actions = $this->get_all( $old_id );
183 183
 
184
-        $this->form_id = $form_id;
185
-        foreach ( $actions as $action ) {
184
+		$this->form_id = $form_id;
185
+		foreach ( $actions as $action ) {
186 186
 			$this->duplicate_one( $action, $form_id );
187 187
 			unset( $action );
188
-        }
189
-    }
188
+		}
189
+	}
190 190
 
191
-    /* Check if imported action should be created or updated
191
+	/* Check if imported action should be created or updated
192 192
     *
193 193
     * Since 2.0
194 194
     *
195 195
     * @param array $action
196 196
     * @return integer $post_id
197 197
     */
198
-    public function maybe_create_action( $action, $forms ) {
198
+	public function maybe_create_action( $action, $forms ) {
199 199
 		if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
200
-            // Update action only
201
-            $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
202
-            $post_id = $this->save_settings( $action );
203
-        } else {
200
+			// Update action only
201
+			$action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
202
+			$post_id = $this->save_settings( $action );
203
+		} else {
204 204
 			// Create action
205 205
 			$action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
206 206
 			$post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
207
-        }
208
-        return $post_id;
209
-    }
207
+		}
208
+		return $post_id;
209
+	}
210 210
 
211 211
 	public function duplicate_one( $action, $form_id ) {
212
-        global $frm_duplicate_ids;
212
+		global $frm_duplicate_ids;
213 213
 
214
-        $action->menu_order = $form_id;
215
-        $switch = $this->get_global_switch_fields();
216
-        foreach ( (array) $action->post_content as $key => $val ) {
214
+		$action->menu_order = $form_id;
215
+		$switch = $this->get_global_switch_fields();
216
+		foreach ( (array) $action->post_content as $key => $val ) {
217 217
 			if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
218 218
 				$action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
219
-            } else if ( ! is_array( $val ) ) {
219
+			} else if ( ! is_array( $val ) ) {
220 220
 				$action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
221 221
 			} else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
222
-                // loop through each value if empty
222
+				// loop through each value if empty
223 223
 				if ( empty( $switch[ $key ] ) ) {
224 224
 					$switch[ $key ] = array_keys( $val );
225 225
 				}
226 226
 
227 227
 				foreach ( $switch[ $key ] as $subkey ) {
228 228
 					$action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
229
-                }
230
-            }
229
+				}
230
+			}
231 231
 
232 232
 			unset( $key, $val );
233 233
 		}
234 234
 		unset( $action->ID );
235 235
 
236 236
 		return $this->save_settings( $action );
237
-    }
237
+	}
238 238
 
239 239
 	private function duplicate_array_walk( $action, $subkey, $val ) {
240
-        global $frm_duplicate_ids;
240
+		global $frm_duplicate_ids;
241 241
 
242 242
 		if ( is_array( $subkey ) ) {
243
-            foreach ( $subkey as $subkey2 ) {
244
-                foreach ( (array) $val as $ck => $cv ) {
243
+			foreach ( $subkey as $subkey2 ) {
244
+				foreach ( (array) $val as $ck => $cv ) {
245 245
 					if ( is_array( $cv ) ) {
246 246
 						$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
247 247
 					} else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
248 248
 						$action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
249
-                    }
250
-                }
251
-            }
252
-        } else {
253
-            foreach ( (array) $val as $ck => $cv ) {
249
+					}
250
+				}
251
+			}
252
+		} else {
253
+			foreach ( (array) $val as $ck => $cv ) {
254 254
 				if ( is_array( $cv ) ) {
255 255
 					$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
256 256
 				} else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
257 257
 					$action[ $ck ] = $frm_duplicate_ids[ $cv ];
258
-                }
259
-            }
260
-        }
258
+				}
259
+			}
260
+		}
261 261
 
262
-        return $action;
263
-    }
262
+		return $action;
263
+	}
264 264
 
265 265
 	/**
266 266
 	 * Deal with changed settings.
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 * Do NOT over-ride this function
269 269
 	 */
270 270
  	public function update_callback( $form_id ) {
271
-        $this->form_id = $form_id;
271
+		$this->form_id = $form_id;
272 272
 
273 273
  		$all_instances = $this->get_settings();
274 274
 
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
  			return;
284 284
  		}
285 285
 
286
-        $action_ids = array();
286
+		$action_ids = array();
287 287
 
288 288
  		foreach ( $settings as $number => $new_instance ) {
289 289
  			$this->_set( $number );
@@ -297,9 +297,9 @@  discard block
 block discarded – undo
297 297
 			// settings were never opened, so don't update
298 298
  			if ( ! isset( $new_instance['post_title'] ) ) {
299 299
 				$this->maybe_update_status( $new_instance, $old_instance );
300
- 			    $action_ids[] = $new_instance['ID'];
301
-         		$this->updated = true;
302
-         		continue;
300
+ 				$action_ids[] = $new_instance['ID'];
301
+		 		$this->updated = true;
302
+		 		continue;
303 303
  			}
304 304
 
305 305
 			$new_instance['post_type']  = FrmFormActionsController::$action_post_type;
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 
334 334
 			$action_ids[] = $this->save_settings( $instance );
335 335
 
336
-     		$this->updated = true;
336
+	 		$this->updated = true;
337 337
  		}
338 338
 
339 339
  		return $action_ids;
@@ -367,19 +367,19 @@  discard block
 block discarded – undo
367 367
 			$action = $this->prepare_action( $action );
368 368
 			$this->_set( $id );
369 369
 		}
370
-	    return $action;
370
+		return $action;
371 371
 	}
372 372
 
373 373
 	public function get_one( $form_id ) {
374 374
 		return $this->get_all( $form_id, 1 );
375 375
 	}
376 376
 
377
-    public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
378
-        $action_controls = FrmFormActionsController::get_form_actions( $type );
377
+	public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
378
+		$action_controls = FrmFormActionsController::get_form_actions( $type );
379 379
 		if ( empty( $action_controls ) ) {
380
-            // don't continue if there are no available actions
381
-            return array();
382
-        }
380
+			// don't continue if there are no available actions
381
+			return array();
382
+		}
383 383
 
384 384
 		if ( 'all' != $type ) {
385 385
 			return $action_controls->get_all( $form_id, $atts );
@@ -393,33 +393,33 @@  discard block
 block discarded – undo
393 393
 		$args['post_status'] = $atts['post_status'];
394 394
 		$actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
395 395
 
396
-        if ( ! $actions ) {
397
-            return array();
398
-        }
396
+		if ( ! $actions ) {
397
+			return array();
398
+		}
399 399
 
400
-        $settings = array();
401
-        foreach ( $actions as $action ) {
400
+		$settings = array();
401
+		foreach ( $actions as $action ) {
402 402
 			// some plugins/themes are formatting the post_excerpt
403 403
 			$action->post_excerpt = sanitize_title( $action->post_excerpt );
404 404
 
405 405
 			if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
406
-                continue;
407
-            }
406
+				continue;
407
+			}
408 408
 
409
-            $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
409
+			$action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
410 410
 			$settings[ $action->ID ] = $action;
411 411
 
412 412
 			if ( count( $settings ) >= $limit ) {
413 413
 				break;
414 414
 			}
415
-        }
415
+		}
416 416
 
417
-        if ( 1 === $limit ) {
417
+		if ( 1 === $limit ) {
418 418
 			$settings = reset( $settings );
419
-        }
419
+		}
420 420
 
421
-        return $settings;
422
-    }
421
+		return $settings;
422
+	}
423 423
 
424 424
 	/**
425 425
 	 * @since 3.04
@@ -464,19 +464,19 @@  discard block
 block discarded – undo
464 464
 		self::prepare_get_action( $atts, 'any' );
465 465
 		$limit = $atts['limit'];
466 466
 
467
-	    if ( $form_id ) {
468
-	        $this->form_id = $form_id;
469
-	    }
467
+		if ( $form_id ) {
468
+			$this->form_id = $form_id;
469
+		}
470 470
 
471
-	    $type = $this->id_base;
471
+		$type = $this->id_base;
472 472
 
473
-	    global $frm_vars;
474
-	    $frm_vars['action_type'] = $type;
473
+		global $frm_vars;
474
+		$frm_vars['action_type'] = $type;
475 475
 
476 476
 		add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
477 477
 		$query = self::action_args( $form_id, $limit );
478 478
 		$query['post_status'] = $atts['post_status'];
479
-        $query['suppress_filters'] = false;
479
+		$query['suppress_filters'] = false;
480 480
 
481 481
 		$actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
482 482
 		unset( $query );
@@ -484,25 +484,25 @@  discard block
 block discarded – undo
484 484
 		remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
485 485
 
486 486
 		if ( empty( $actions ) ) {
487
-            return array();
488
-        }
487
+			return array();
488
+		}
489 489
 
490
-        $settings = array();
491
-        foreach ( $actions as $action ) {
490
+		$settings = array();
491
+		foreach ( $actions as $action ) {
492 492
 			if ( count( $settings ) >= $limit ) {
493
-                continue;
494
-            }
493
+				continue;
494
+			}
495 495
 
496 496
 			$action = $this->prepare_action( $action );
497 497
 
498 498
 			$settings[ $action->ID ] = $action;
499
-        }
499
+		}
500 500
 
501
-        if ( 1 === $limit ) {
501
+		if ( 1 === $limit ) {
502 502
 			$settings = reset( $settings );
503
-        }
503
+		}
504 504
 
505
-        return $settings;
505
+		return $settings;
506 506
 	}
507 507
 
508 508
 	public static function action_args( $form_id = 0, $limit = 99 ) {
@@ -525,45 +525,45 @@  discard block
 block discarded – undo
525 525
 		$action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
526 526
 		$action->post_excerpt = sanitize_title( $action->post_excerpt );
527 527
 
528
-        $default_values = $this->get_global_defaults();
528
+		$default_values = $this->get_global_defaults();
529 529
 
530
-        // fill default values
531
-        $action->post_content += $default_values;
530
+		// fill default values
531
+		$action->post_content += $default_values;
532 532
 
533
-        foreach ( $default_values as $k => $vals ) {
533
+		foreach ( $default_values as $k => $vals ) {
534 534
 			if ( is_array( $vals ) && ! empty( $vals ) ) {
535 535
 				if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
536
-                    continue;
537
-                }
536
+					continue;
537
+				}
538 538
 				$action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
539
-            }
540
-        }
539
+			}
540
+		}
541 541
 
542 542
 		if ( ! is_array( $action->post_content['event'] ) ) {
543 543
 			$action->post_content['event'] = explode( ',', $action->post_content['event'] );
544 544
 		}
545 545
 
546
-        return $action;
546
+		return $action;
547 547
 	}
548 548
 
549 549
 	public function destroy( $form_id = false, $type = 'default' ) {
550
-	    global $wpdb;
550
+		global $wpdb;
551 551
 
552
-	    $this->form_id = $form_id;
552
+		$this->form_id = $form_id;
553 553
 
554
-	    $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
555
-	    if ( $form_id ) {
556
-	        $query['menu_order'] = $form_id;
557
-	    }
558
-	    if ( 'all' != $type ) {
559
-	        $query['post_excerpt'] = $this->id_base;
560
-	    }
554
+		$query = array( 'post_type' => FrmFormActionsController::$action_post_type );
555
+		if ( $form_id ) {
556
+			$query['menu_order'] = $form_id;
557
+		}
558
+		if ( 'all' != $type ) {
559
+			$query['post_excerpt'] = $this->id_base;
560
+		}
561 561
 
562
-        $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
562
+		$post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
563 563
 
564
-        foreach ( $post_ids as $id ) {
564
+		foreach ( $post_ids as $id ) {
565 565
 			wp_delete_post( $id );
566
-        }
566
+		}
567 567
 		self::clear_cache();
568 568
 	}
569 569
 
@@ -581,26 +581,26 @@  discard block
 block discarded – undo
581 581
 	}
582 582
 
583 583
 	public function get_global_defaults() {
584
-	    $defaults = $this->get_defaults();
584
+		$defaults = $this->get_defaults();
585 585
 
586 586
 		if ( ! isset( $defaults['event'] ) ) {
587 587
 			$defaults['event'] = array( 'create' );
588
-	    }
588
+		}
589 589
 
590 590
 		if ( ! isset( $defaults['conditions'] ) ) {
591
-	        $defaults['conditions'] = array(
592
-                'send_stop' => '',
593
-                'any_all'   => '',
594
-            );
595
-        }
591
+			$defaults['conditions'] = array(
592
+				'send_stop' => '',
593
+				'any_all'   => '',
594
+			);
595
+		}
596 596
 
597
-        return $defaults;
597
+		return $defaults;
598 598
 	}
599 599
 
600 600
 	public function get_global_switch_fields() {
601
-	    $switch = $this->get_switch_fields();
601
+		$switch = $this->get_switch_fields();
602 602
 		$switch['conditions'] = array( 'hide_field' );
603
-	    return $switch;
603
+		return $switch;
604 604
 	}
605 605
 
606 606
 	/**
@@ -610,17 +610,17 @@  discard block
 block discarded – undo
610 610
 		$action = $this->prepare_new( $form->id );
611 611
 		$form->options = maybe_unserialize( $form->options );
612 612
 
613
-        // fill with existing options
614
-        foreach ( $action->post_content as $name => $val ) {
613
+		// fill with existing options
614
+		foreach ( $action->post_content as $name => $val ) {
615 615
 			if ( isset( $form->options[ $name ] ) ) {
616 616
 				$action->post_content[ $name ] = $form->options[ $name ];
617 617
 				unset( $form->options[ $name ] );
618
-            }
619
-        }
618
+			}
619
+		}
620 620
 
621 621
 		$action = $this->migrate_values( $action, $form );
622 622
 
623
-        // check if action already exists
623
+		// check if action already exists
624 624
 		$post_id = get_posts(
625 625
 			array(
626 626
 				'name'          => $action->post_name,
@@ -635,17 +635,17 @@  discard block
 block discarded – undo
635 635
 			$post_id = $this->save_settings( $action );
636 636
 		}
637 637
 
638
-        if ( $post_id && 'update' == $update ) {
639
-            global $wpdb;
638
+		if ( $post_id && 'update' == $update ) {
639
+			global $wpdb;
640 640
 			$form->options = maybe_serialize( $form->options );
641 641
 
642
-            // update form options
642
+			// update form options
643 643
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
644
-	        FrmForm::clear_form_cache();
645
-        }
644
+			FrmForm::clear_form_cache();
645
+		}
646 646
 
647
-        return $post_id;
648
-    }
647
+		return $post_id;
648
+	}
649 649
 
650 650
 	public static function action_conditions_met( $action, $entry ) {
651 651
 		$notification = $action->post_content;
Please login to merge, or discard this patch.
classes/controllers/FrmFormActionsController.php 1 patch
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class FrmFormActionsController {
4
-    public static $action_post_type = 'frm_form_actions';
5
-    public static $registered_actions;
4
+	public static $action_post_type = 'frm_form_actions';
5
+	public static $registered_actions;
6 6
 
7 7
 	/**
8 8
 	 * Variables saved in the post:
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 	 * menu_order: form id
11 11
 	 * post_excerpt: action type
12 12
 	 */
13
-    public static function register_post_types() {
13
+	public static function register_post_types() {
14 14
 		register_post_type(
15 15
 			self::$action_post_type,
16 16
 			array(
@@ -27,84 +27,84 @@  discard block
 block discarded – undo
27 27
 			)
28 28
 		);
29 29
 
30
-        self::actions_init();
31
-    }
30
+		self::actions_init();
31
+	}
32 32
 
33
-    public static function actions_init() {
34
-        self::$registered_actions = new Frm_Form_Action_Factory();
35
-        self::register_actions();
36
-        do_action( 'frm_form_actions_init' );
37
-    }
33
+	public static function actions_init() {
34
+		self::$registered_actions = new Frm_Form_Action_Factory();
35
+		self::register_actions();
36
+		do_action( 'frm_form_actions_init' );
37
+	}
38 38
 
39
-    public static function register_actions() {
39
+	public static function register_actions() {
40 40
 		$action_classes = array(
41
-            'email'     => 'FrmEmailAction',
42
-            'wppost'    => 'FrmDefPostAction',
43
-            'register'  => 'FrmDefRegAction',
44
-            'paypal'    => 'FrmDefPayPalAction',
45
-            //'aweber'    => 'FrmDefAweberAction',
46
-            'mailchimp' => 'FrmDefMlcmpAction',
47
-            'twilio'    => 'FrmDefTwilioAction',
48
-            'payment'   => 'FrmDefHrsAction',
49
-        );
41
+			'email'     => 'FrmEmailAction',
42
+			'wppost'    => 'FrmDefPostAction',
43
+			'register'  => 'FrmDefRegAction',
44
+			'paypal'    => 'FrmDefPayPalAction',
45
+			//'aweber'    => 'FrmDefAweberAction',
46
+			'mailchimp' => 'FrmDefMlcmpAction',
47
+			'twilio'    => 'FrmDefTwilioAction',
48
+			'payment'   => 'FrmDefHrsAction',
49
+		);
50 50
 		$action_classes = apply_filters( 'frm_registered_form_actions', $action_classes );
51 51
 
52 52
 		include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php' );
53 53
 		include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php' );
54 54
 
55
-        foreach ( $action_classes as $action_class ) {
55
+		foreach ( $action_classes as $action_class ) {
56 56
 			self::$registered_actions->register( $action_class );
57
-        }
58
-    }
57
+		}
58
+	}
59 59
 
60 60
 	public static function get_form_actions( $action = 'all' ) {
61
-        $temp_actions = self::$registered_actions;
61
+		$temp_actions = self::$registered_actions;
62 62
 		if ( empty( $temp_actions ) ) {
63
-            self::actions_init();
64
-            $temp_actions = self::$registered_actions->actions;
65
-        } else {
66
-            $temp_actions = $temp_actions->actions;
67
-        }
63
+			self::actions_init();
64
+			$temp_actions = self::$registered_actions->actions;
65
+		} else {
66
+			$temp_actions = $temp_actions->actions;
67
+		}
68 68
 
69
-        $actions = array();
69
+		$actions = array();
70 70
 
71
-        foreach ( $temp_actions as $a ) {
72
-            if ( 'all' != $action && $a->id_base == $action ) {
73
-                return $a;
74
-            }
71
+		foreach ( $temp_actions as $a ) {
72
+			if ( 'all' != $action && $a->id_base == $action ) {
73
+				return $a;
74
+			}
75 75
 
76 76
 			$actions[ $a->id_base ] = $a;
77
-        }
78
-        unset( $temp_actions, $a );
79
-
80
-        $action_limit = 10;
81
-        if ( count( $actions ) <= $action_limit ) {
82
-            return $actions;
83
-        }
84
-
85
-        // remove the last few inactive icons if there are too many
86
-        $temp_actions = $actions;
87
-        arsort( $temp_actions );
88
-        foreach ( $temp_actions as $type => $a ) {
89
-            if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) {
77
+		}
78
+		unset( $temp_actions, $a );
79
+
80
+		$action_limit = 10;
81
+		if ( count( $actions ) <= $action_limit ) {
82
+			return $actions;
83
+		}
84
+
85
+		// remove the last few inactive icons if there are too many
86
+		$temp_actions = $actions;
87
+		arsort( $temp_actions );
88
+		foreach ( $temp_actions as $type => $a ) {
89
+			if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) {
90 90
 				unset( $actions[ $type ] );
91
-                if ( count( $actions ) <= $action_limit ) {
92
-                    break;
93
-                }
94
-            }
95
-            unset( $type, $a );
96
-        }
91
+				if ( count( $actions ) <= $action_limit ) {
92
+					break;
93
+				}
94
+			}
95
+			unset( $type, $a );
96
+		}
97 97
 
98
-        return $actions;
99
-    }
98
+		return $actions;
99
+	}
100 100
 
101 101
 	/**
102 102
 	 * @since 2.0
103 103
 	 */
104
-    public static function list_actions( $form, $values ) {
105
-        if ( empty( $form ) ) {
106
-            return;
107
-        }
104
+	public static function list_actions( $form, $values ) {
105
+		if ( empty( $form ) ) {
106
+			return;
107
+		}
108 108
 
109 109
 		/**
110 110
 		 * Use this hook to migrate old settings into a new action
@@ -118,72 +118,72 @@  discard block
 block discarded – undo
118 118
 		);
119 119
 		$form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters );
120 120
 
121
-        $action_controls = self::get_form_actions();
121
+		$action_controls = self::get_form_actions();
122 122
 
123
-        $action_map = array();
123
+		$action_map = array();
124 124
 
125 125
 		foreach ( $action_controls as $key => $control ) {
126
-            $action_map[ $control->id_base ] = $key;
127
-        }
126
+			$action_map[ $control->id_base ] = $key;
127
+		}
128 128
 
129
-    	foreach ( $form_actions as $action ) {
130
-    	    if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
131
-    	        // don't try and show settings if action no longer exists
132
-    	        continue;
133
-    	    }
129
+		foreach ( $form_actions as $action ) {
130
+			if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
131
+				// don't try and show settings if action no longer exists
132
+				continue;
133
+			}
134 134
 
135
-    		self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
136
-    	}
137
-    }
135
+			self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
136
+		}
137
+	}
138 138
 
139 139
 	public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
140 140
 		$action_control->_set( $action_key );
141 141
 		include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
142
-    }
142
+	}
143 143
 
144
-    public static function add_form_action() {
144
+	public static function add_form_action() {
145 145
 		FrmAppHelper::permission_check( 'frm_edit_forms' );
146
-        check_ajax_referer( 'frm_ajax', 'nonce' );
146
+		check_ajax_referer( 'frm_ajax', 'nonce' );
147 147
 
148
-        global $frm_vars;
148
+		global $frm_vars;
149 149
 
150 150
 		$action_key = absint( $_POST['list_id'] );
151
-        $action_type = sanitize_text_field( $_POST['type'] );
151
+		$action_type = sanitize_text_field( $_POST['type'] );
152 152
 
153
-        $action_control = self::get_form_actions( $action_type );
153
+		$action_control = self::get_form_actions( $action_type );
154 154
 		$action_control->_set( $action_key );
155 155
 
156
-        $form_id = absint( $_POST['form_id'] );
156
+		$form_id = absint( $_POST['form_id'] );
157 157
 
158 158
 		$form_action = $action_control->prepare_new( $form_id );
159 159
 
160
-        $values = array();
160
+		$values = array();
161 161
 		$form = self::fields_to_values( $form_id, $values );
162 162
 
163 163
 		include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
164
-        wp_die();
165
-    }
164
+		wp_die();
165
+	}
166 166
 
167
-    public static function fill_action() {
167
+	public static function fill_action() {
168 168
 		FrmAppHelper::permission_check( 'frm_edit_forms' );
169
-        check_ajax_referer( 'frm_ajax', 'nonce' );
169
+		check_ajax_referer( 'frm_ajax', 'nonce' );
170 170
 
171
-        $action_key = absint( $_POST['action_id'] );
172
-        $action_type = sanitize_text_field( $_POST['action_type'] );
171
+		$action_key = absint( $_POST['action_id'] );
172
+		$action_type = sanitize_text_field( $_POST['action_type'] );
173 173
 
174
-        $action_control = self::get_form_actions( $action_type );
174
+		$action_control = self::get_form_actions( $action_type );
175 175
 		if ( empty( $action_control ) ) {
176
-            wp_die();
177
-        }
176
+			wp_die();
177
+		}
178 178
 
179
-        $form_action = $action_control->get_single_action( $action_key );
179
+		$form_action = $action_control->get_single_action( $action_key );
180 180
 
181
-        $values = array();
181
+		$values = array();
182 182
 		$form = self::fields_to_values( $form_action->menu_order, $values );
183 183
 
184 184
 		include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' );
185
-        wp_die();
186
-    }
185
+		wp_die();
186
+	}
187 187
 
188 188
 	private static function fields_to_values( $form_id, array &$values ) {
189 189
 		$form = FrmForm::getOne( $form_id );
@@ -194,19 +194,19 @@  discard block
 block discarded – undo
194 194
 		);
195 195
 
196 196
 		$fields = FrmField::get_all_for_form( $form->id );
197
-        foreach ( $fields as $k => $f ) {
198
-            $f = (array) $f;
199
-            $opts = (array) $f['field_options'];
197
+		foreach ( $fields as $k => $f ) {
198
+			$f = (array) $f;
199
+			$opts = (array) $f['field_options'];
200 200
 			$f = array_merge( $opts, $f );
201
-            if ( ! isset( $f['post_field'] ) ) {
202
-                $f['post_field'] = '';
203
-            }
204
-            $values['fields'][] = $f;
201
+			if ( ! isset( $f['post_field'] ) ) {
202
+				$f['post_field'] = '';
203
+			}
204
+			$values['fields'][] = $f;
205 205
 			unset( $k, $f );
206
-        }
206
+		}
207 207
 
208
-        return $form;
209
-    }
208
+		return $form;
209
+	}
210 210
 
211 211
 	public static function update_settings( $form_id ) {
212 212
 		$process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
@@ -214,9 +214,9 @@  discard block
 block discarded – undo
214 214
 			wp_die( esc_html__( 'You do not have permission to do that', 'formidable' ) );
215 215
 		}
216 216
 
217
-        global $wpdb;
217
+		global $wpdb;
218 218
 
219
-        $registered_actions = self::$registered_actions->actions;
219
+		$registered_actions = self::$registered_actions->actions;
220 220
 
221 221
 		$old_actions = FrmDb::get_col(
222 222
 			$wpdb->posts,
@@ -226,23 +226,23 @@  discard block
 block discarded – undo
226 226
 			),
227 227
 			'ID'
228 228
 		);
229
-        $new_actions = array();
229
+		$new_actions = array();
230 230
 
231
-        foreach ( $registered_actions as $registered_action ) {
231
+		foreach ( $registered_actions as $registered_action ) {
232 232
 			$action_ids = $registered_action->update_callback( $form_id );
233
-            if ( ! empty( $action_ids ) ) {
234
-                $new_actions[] = $action_ids;
235
-            }
236
-        }
233
+			if ( ! empty( $action_ids ) ) {
234
+				$new_actions[] = $action_ids;
235
+			}
236
+		}
237 237
 
238
-        //Only use array_merge if there are new actions
239
-        if ( ! empty( $new_actions ) ) {
240
-            $new_actions = call_user_func_array( 'array_merge', $new_actions );
241
-        }
242
-        $old_actions = array_diff( $old_actions, $new_actions );
238
+		//Only use array_merge if there are new actions
239
+		if ( ! empty( $new_actions ) ) {
240
+			$new_actions = call_user_func_array( 'array_merge', $new_actions );
241
+		}
242
+		$old_actions = array_diff( $old_actions, $new_actions );
243 243
 
244 244
 		self::delete_missing_actions( $old_actions );
245
-    }
245
+	}
246 246
 
247 247
 	public static function delete_missing_actions( $old_actions ) {
248 248
 		if ( ! empty( $old_actions ) ) {
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
 		self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
263 263
 	}
264 264
 
265
-    /**
266
-     * @param string $event
267
-     */
265
+	/**
266
+	 * @param string $event
267
+	 */
268 268
 	public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
269 269
 		$action_status = array(
270 270
 			'post_status' => 'publish',
@@ -272,15 +272,15 @@  discard block
 block discarded – undo
272 272
 		$form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
273 273
 
274 274
 		if ( empty( $form_actions ) ) {
275
-            return;
276
-        }
275
+			return;
276
+		}
277 277
 
278 278
 		FrmForm::maybe_get_form( $form );
279 279
 
280
-        $link_settings = self::get_form_actions( $type );
281
-        if ( 'all' != $type ) {
282
-            $link_settings = array( $type => $link_settings );
283
-        }
280
+		$link_settings = self::get_form_actions( $type );
281
+		if ( 'all' != $type ) {
282
+			$link_settings = array( $type => $link_settings );
283
+		}
284 284
 
285 285
 		$stored_actions = array();
286 286
 		$action_priority = array();
@@ -291,17 +291,17 @@  discard block
 block discarded – undo
291 291
 			$this_event = $event;
292 292
 		}
293 293
 
294
-        foreach ( $form_actions as $action ) {
294
+		foreach ( $form_actions as $action ) {
295 295
 
296 296
 			$skip_this_action = ( ! in_array( $this_event, $action->post_content['event'] ) );
297 297
 			$skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
298 298
 			if ( $skip_this_action ) {
299
-                continue;
300
-            }
299
+				continue;
300
+			}
301 301
 
302
-            if ( ! is_object( $entry ) ) {
303
-                $entry = FrmEntry::getOne( $entry, true );
304
-            }
302
+			if ( ! is_object( $entry ) ) {
303
+				$entry = FrmEntry::getOne( $entry, true );
304
+			}
305 305
 
306 306
 			if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) {
307 307
 				continue;
@@ -315,64 +315,64 @@  discard block
 block discarded – undo
315 315
 				if ( ! $trigger_children ) {
316 316
 					continue;
317 317
 				}
318
-            }
318
+			}
319 319
 
320
-            // check conditional logic
320
+			// check conditional logic
321 321
 			$stop = FrmFormAction::action_conditions_met( $action, $entry );
322
-            if ( $stop ) {
323
-                continue;
324
-            }
322
+			if ( $stop ) {
323
+				continue;
324
+			}
325 325
 
326
-            // store actions so they can be triggered with the correct priority
327
-            $stored_actions[ $action->ID ] = $action;
328
-            $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
326
+			// store actions so they can be triggered with the correct priority
327
+			$stored_actions[ $action->ID ] = $action;
328
+			$action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
329 329
 
330 330
 			unset( $action );
331
-        }
331
+		}
332 332
 
333
-        if ( ! empty( $stored_actions ) ) {
333
+		if ( ! empty( $stored_actions ) ) {
334 334
 			asort( $action_priority );
335 335
 
336
-            // make sure hooks are loaded
337
-            new FrmNotification();
336
+			// make sure hooks are loaded
337
+			new FrmNotification();
338 338
 
339
-            foreach ( $action_priority as $action_id => $priority ) {
340
-                $action = $stored_actions[ $action_id ];
339
+			foreach ( $action_priority as $action_id => $priority ) {
340
+				$action = $stored_actions[ $action_id ];
341 341
 				do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
342 342
 				do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
343 343
 
344
-                // If post is created, get updated $entry object
345
-                if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
344
+				// If post is created, get updated $entry object
345
+				if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
346 346
 					$entry = FrmEntry::getOne( $entry->id, true );
347
-                }
348
-            }
349
-        }
350
-    }
347
+				}
348
+			}
349
+		}
350
+	}
351 351
 
352 352
 	public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
353 353
 		if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) {
354
-            // continue if we know which actions to copy
355
-            return;
356
-        }
354
+			// continue if we know which actions to copy
355
+			return;
356
+		}
357 357
 
358 358
 		$action_controls = self::get_form_actions();
359 359
 
360
-        foreach ( $action_controls as $action_control ) {
361
-            $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
362
-            unset( $action_control );
363
-        }
364
-    }
360
+		foreach ( $action_controls as $action_control ) {
361
+			$action_control->duplicate_form_actions( $form_id, $args['old_id'] );
362
+			unset( $action_control );
363
+		}
364
+	}
365 365
 
366
-    public static function limit_by_type( $where ) {
367
-        global $frm_vars, $wpdb;
366
+	public static function limit_by_type( $where ) {
367
+		global $frm_vars, $wpdb;
368 368
 
369
-        if ( ! isset( $frm_vars['action_type'] ) ) {
370
-            return $where;
371
-        }
369
+		if ( ! isset( $frm_vars['action_type'] ) ) {
370
+			return $where;
371
+		}
372 372
 
373
-        $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
374
-        return $where;
375
-    }
373
+		$where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
374
+		return $where;
375
+	}
376 376
 }
377 377
 
378 378
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 		foreach ( $keys as $key ) {
400 400
 			// don't register new action if old action with the same id is already registered
401 401
 			if ( ! isset( $this->actions[ $key ] ) ) {
402
-			    $this->actions[ $key ]->_register();
402
+				$this->actions[ $key ]->_register();
403 403
 			}
404 404
 		}
405 405
 	}
Please login to merge, or discard this patch.