PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.07.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.07.01
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmFormActionsController.php +52 -329 6.264.07.01 View file →
@@ -3,17 +3,9 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmFormActionsController {
7 -
8 - /**
9 - * @var string
10 - */
11 7 public static $action_post_type = 'frm_form_actions';
12 -
13 - /**
14 - * @var array|null
15 - */
16 8 public static $registered_actions;
17 9
18 10 /**
19 11 * Variables saved in the post:
@@ -46,47 +38,33 @@
46 38 self::register_actions();
47 39 do_action( 'frm_form_actions_init' );
48 40 }
49 41
50 - /**
51 - * @return void
52 - */
53 42 public static function register_actions() {
54 43 $action_classes = array(
55 - 'on_submit' => 'FrmOnSubmitAction',
56 - 'email' => 'FrmEmailAction',
57 - 'wppost' => 'FrmDefPostAction',
58 - 'register' => 'FrmDefRegAction',
59 - 'paypal' => 'FrmDefPayPalAction',
60 - 'payment' => 'FrmTransLiteAction',
61 - 'quiz' => 'FrmDefQuizAction',
62 - 'quiz_outcome' => 'FrmDefQuizOutcomeAction',
63 - 'mailchimp' => 'FrmDefMlcmpAction',
64 - 'api' => 'FrmDefApiAction',
65 - 'salesforce' => 'FrmDefSalesforceAction',
66 - 'activecampaign' => 'FrmDefActiveCampaignAction',
67 - 'constantcontact' => 'FrmDefConstContactAction',
68 - 'getresponse' => 'FrmDefGetResponseAction',
69 - 'hubspot' => 'FrmDefHubspotAction',
70 - 'zapier' => 'FrmDefZapierAction',
71 - 'n8n' => 'FrmDefN8NAction',
72 - 'twilio' => 'FrmDefTwilioAction',
73 - 'highrise' => 'FrmDefHighriseAction',
74 - 'mailpoet' => 'FrmDefMailpoetAction',
75 - 'aweber' => 'FrmDefAweberAction',
76 - 'convertkit' => 'FrmDefConvertKitAction',
77 - 'googlespreadsheet' => 'FrmDefGoogleSpreadsheetAction',
44 + 'email' => 'FrmEmailAction',
45 + 'wppost' => 'FrmDefPostAction',
46 + 'register' => 'FrmDefRegAction',
47 + 'paypal' => 'FrmDefPayPalAction',
48 + 'payment' => 'FrmDefHrsAction',
49 + 'mailchimp' => 'FrmDefMlcmpAction',
50 + 'api' => 'FrmDefApiAction',
51 +
52 + 'salesforce' => 'FrmDefSalesforceAction',
53 + 'activecampaign' => 'FrmDefActiveCampaignAction',
54 + 'constantcontact' => 'FrmDefConstContactAction',
55 + 'getresponse' => 'FrmDefGetResponseAction',
56 + 'hubspot' => 'FrmDefHubspotAction',
57 + 'twilio' => 'FrmDefTwilioAction',
58 + 'highrise' => 'FrmDefHighriseAction',
59 + 'mailpoet' => 'FrmDefMailpoetAction',
60 + 'aweber' => 'FrmDefAweberAction',
78 61 );
79 62
80 - if ( ! FrmAppHelper::show_new_feature( 'n8n' ) ) {
81 - unset( $action_classes['n8n'] );
82 - }
83 -
84 63 $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes );
85 - $action_classes = self::maybe_unset_highrise( $action_classes );
86 64
87 - include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php';
88 - include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php';
65 + include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php' );
66 + include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php' );
89 67
90 68 foreach ( $action_classes as $action_class ) {
91 69 self::$registered_actions->register( $action_class );
92 70 }
@@ -92,24 +70,8 @@
92 70 }
93 71 }
94 72
95 73 /**
96 - * Remove the Highrise action if it is not registered.
97 - *
98 - * @since 6.23
99 - *
100 - * @param array $action_classes
101 - *
102 - * @return array
103 - */
104 - private static function maybe_unset_highrise( $action_classes ) {
105 - if ( 'FrmDefHighriseAction' === ( $action_classes['highrise'] ?? '' ) ) {
106 - unset( $action_classes['highrise'] );
107 - }
108 - return $action_classes;
109 - }
110 -
111 - /**
112 74 * @since 4.0
113 75 *
114 76 * @param array $values
115 77 */
@@ -121,9 +83,9 @@
121 83 self::maybe_add_action_to_group( $action_controls, $groups );
122 84
123 85 $allowed = self::active_actions( $action_controls );
124 86
125 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/settings.php';
87 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/settings.php' );
126 88 }
127 89
128 90 /**
129 91 * Add unknown actions to a group.
@@ -128,17 +90,11 @@
128 90 /**
129 91 * Add unknown actions to a group.
130 92 *
131 93 * @since 4.0
132 - *
133 - * @param array $action_controls
134 - * @param array $groups
135 - *
136 - * @return void
137 94 */
138 95 private static function maybe_add_action_to_group( $action_controls, &$groups ) {
139 96 $grouped = array();
140 -
141 97 foreach ( $groups as $group ) {
142 98 if ( isset( $group['actions'] ) ) {
143 99 $grouped = array_merge( $grouped, $group['actions'] );
144 100 }
@@ -149,9 +105,8 @@
149 105 continue;
150 106 }
151 107
152 108 $this_group = $action->action_options['group'];
153 -
154 109 if ( ! isset( $groups[ $this_group ] ) ) {
155 110 $this_group = 'misc';
156 111 }
157 112
@@ -170,9 +125,9 @@
170 125 * @return array
171 126 */
172 127 public static function form_action_groups() {
173 128 $groups = array(
174 - 'misc' => array(
129 + 'misc' => array(
175 130 'name' => '',
176 131 'icon' => 'frm_icon_font frm_shuffle_icon',
177 132 'actions' => array(
178 133 'email',
@@ -177,10 +132,8 @@
177 132 'actions' => array(
178 133 'email',
179 134 'wppost',
180 135 'register',
181 - 'quiz',
182 - 'quiz_outcome',
183 136 'twilio',
184 137 ),
185 138 ),
186 139 'payment' => array(
@@ -200,15 +153,18 @@
200 153 'constantcontact',
201 154 'getresponse',
202 155 'aweber',
203 156 'mailpoet',
204 - 'convertkit',
205 157 ),
206 158 ),
207 159 'crm' => array(
208 160 'name' => __( 'CRM', 'formidable' ),
209 161 'icon' => 'frm_icon_font frm_address_card_icon',
210 - 'actions' => self::get_crm_actions(),
162 + 'actions' => array(
163 + 'salesforce',
164 + 'hubspot',
165 + 'highrise',
166 + ),
211 167 ),
212 168 );
213 169
214 170 return apply_filters( 'frm_action_groups', $groups );
@@ -214,41 +170,16 @@
214 170 return apply_filters( 'frm_action_groups', $groups );
215 171 }
216 172
217 173 /**
218 - * Get the actions to include in the CRM section.
219 - *
220 - * @since 6.23
221 - *
222 - * @return array
223 - */
224 - private static function get_crm_actions() {
225 - $crm_actions = array(
226 - 'salesforce',
227 - 'hubspot',
228 - );
229 -
230 - // Only include Highrise when the add-on is active.
231 - // This is because Highrise is deprecated. We don't want to show it in Lite.
232 - if ( class_exists( 'FrmHrsSettings' ) ) {
233 - $crm_actions[] = 'highrise';
234 - }
235 -
236 - return $crm_actions;
237 - }
238 -
239 - /**
240 174 * Get the number of currently active form actions.
241 175 *
242 176 * @since 4.0
243 177 *
244 - * @param array $action_controls
245 - *
246 178 * @return array
247 179 */
248 180 private static function active_actions( $action_controls ) {
249 181 $allowed = array();
250 -
251 182 foreach ( $action_controls as $action_control ) {
252 183 if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) {
253 184 $allowed[] = $action_control->id_base;
254 185 }
@@ -259,9 +190,8 @@
259 190 /**
260 191 * For each add-on, add an li, class, and javascript function. If active, add an additional class.
261 192 *
262 193 * @since 4.0
263 - *
264 194 * @param object $action_control
265 195 * @param array $allowed
266 196 */
267 197 public static function show_action_icon_link( $action_control, $allowed ) {
@@ -272,9 +202,9 @@
272 202
273 203 /* translators: %s: Name of form action */
274 204 $upgrade_label = sprintf( esc_html__( '%s form actions', 'formidable' ), $action_control->action_options['tooltip'] );
275 205
276 - $default_shown = array( 'wppost', 'register', 'payment', 'quiz', 'hubspot' );
206 + $default_shown = array( 'wppost', 'register', 'paypal', 'payment', 'mailchimp' );
277 207 $default_shown = array_values( array_diff( $default_shown, $allowed ) );
278 208 $default_position = array_search( $action_control->id_base, $default_shown );
279 209 $allowed_count = count( $allowed );
280 210
@@ -281,9 +211,8 @@
281 211 if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) {
282 212 $classes .= ' frm_active_action';
283 213 } else {
284 214 $classes .= ' frm_inactive_action';
285 -
286 215 if ( $default_position !== false && ( $allowed_count + $default_position ) < 6 ) {
287 216 $group_class .= ' frm-default-show';
288 217 }
289 218
@@ -290,44 +219,26 @@
290 219 $data['data-upgrade'] = $upgrade_label;
291 220 $data['data-medium'] = 'settings-' . $action_control->id_base;
292 221
293 222 $upgrading = FrmAddonsController::install_link( $action_control->action_options['plugin'] );
294 -
295 223 if ( isset( $upgrading['url'] ) ) {
296 224 $data['data-oneclick'] = json_encode( $upgrading );
297 225 }
226 + }
298 227
299 - if ( isset( $action_control->action_options['message'] ) ) {
300 - $data['data-message'] = $action_control->action_options['message'];
301 - }
302 -
303 - $requires = FrmFormsHelper::get_plan_required( $upgrading );
304 -
305 - if ( $requires && 'free' !== $requires ) {
306 - $data['data-requires'] = $requires;
307 - }
308 - }//end if
309 -
310 228 // HTML to include on the icon.
311 229 $icon_atts = array();
312 -
313 - if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) {
230 + if ( $action_control->action_options['color'] !== 'var(--primary-hover)' ) {
314 231 $icon_atts = array(
315 - 'style' => '--primary-700:' . $action_control->action_options['color'],
232 + 'style' => '--primary-hover:' . $action_control->action_options['color'],
316 233 );
317 234 }
318 235
319 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
236 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php' );
320 237 }
321 238
322 - /**
323 - * @param string $action
324 - *
325 - * @return array|FrmFormAction A single form action is returned when a specific $action value is requested.
326 - */
327 239 public static function get_form_actions( $action = 'all' ) {
328 240 $temp_actions = self::$registered_actions;
329 -
330 241 if ( empty( $temp_actions ) ) {
331 242 self::actions_init();
332 243 $temp_actions = self::$registered_actions->actions;
333 244 } else {
@@ -336,9 +247,9 @@
336 247
337 248 $actions = array();
338 249
339 250 foreach ( $temp_actions as $a ) {
340 - if ( 'all' !== $action && $a->id_base == $action ) {
251 + if ( 'all' != $action && $a->id_base == $action ) {
341 252 return $a;
342 253 }
343 254
344 255 $actions[ $a->id_base ] = $a;
@@ -348,13 +259,8 @@
348 259 }
349 260
350 261 /**
351 262 * @since 2.0
352 - *
353 - * @param object $form
354 - * @param array $values
355 - *
356 - * @return void
357 263 */
358 264 public static function list_actions( $form, $values ) {
359 265 if ( empty( $form ) ) {
360 266 return;
@@ -371,11 +277,8 @@
371 277 'post_status' => 'all',
372 278 );
373 279 $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters );
374 280
375 - /**
376 - * @var array
377 - */
378 281 $action_controls = self::get_form_actions();
379 282
380 283 $action_map = array();
381 284
@@ -382,10 +285,8 @@
382 285 foreach ( $action_controls as $key => $control ) {
383 286 $action_map[ $control->id_base ] = $key;
384 287 }
385 288
386 - self::maybe_show_limit_warning( $form->id, $form_actions );
387 -
388 289 foreach ( $form_actions as $action ) {
389 290 if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
390 291 // don't try and show settings if action no longer exists
391 292 continue;
@@ -394,60 +295,14 @@
394 295 self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
395 296 }
396 297 }
397 298
398 - /**
399 - * Show a warning before the form actions list if there are 99 actions, and the limit is set to 99.
400 - * If it is filtered, the warning is still shown when applicable, just using the new limit.
401 - *
402 - * @since 6.17
403 - *
404 - * @param int|string $form_id
405 - * @param array $form_actions
406 - *
407 - * @return void
408 - */
409 - private static function maybe_show_limit_warning( $form_id, $form_actions ) {
410 - $count = count( $form_actions );
411 -
412 - if ( $count < 99 ) {
413 - return;
414 - }
415 -
416 - $limit = FrmFormAction::get_action_limit( $form_id );
417 -
418 - if ( $limit < 99 || $count < $limit ) {
419 - return;
420 - }
421 -
422 - $documentation_url = 'https://formidableforms.com/knowledgebase/frm_form_action_limit/#kb-increase-limit-of-form-actions';
423 -
424 - echo '<div class="frm_warning_style">';
425 - FrmAppHelper::icon_by_class( 'frm_icon_font frm_alert_icon' );
426 - echo '&nbsp;';
427 - printf(
428 - // translators: %s: URL to documentation
429 - esc_html__( 'You have reached your form action limit. To increase this limit, you will require additional code. Visit our documentation at %s.', 'formidable' ),
430 - '<a href="' . esc_url( $documentation_url ) . '" target="_blank">' . esc_html( $documentation_url ) . '</a>'
431 - );
432 - echo '</div>';
433 - }
434 -
435 - /**
436 - * @param WP_Post $form_action
437 - * @param object $form
438 - * @param int $action_key Action ID.
439 - * @param FrmFormAction $action_control
440 - * @param array $values
441 - *
442 - * @return void
443 - */
444 299 public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
445 300 $action_control->_set( $action_key );
446 301
447 302 $use_logging = self::should_show_log_message( $form_action->post_excerpt );
448 303
449 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php';
304 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
450 305 }
451 306
452 307 public static function add_form_action() {
453 308 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -457,11 +312,8 @@
457 312
458 313 $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' );
459 314 $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' );
460 315
461 - /**
462 - * @var FrmFormAction
463 - */
464 316 $action_control = self::get_form_actions( $action_type );
465 317 $action_control->_set( $action_key );
466 318
467 319 $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' );
@@ -471,9 +323,9 @@
471 323
472 324 $values = array();
473 325 $form = self::fields_to_values( $form_id, $values );
474 326
475 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php';
327 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
476 328 wp_die();
477 329 }
478 330
479 331 public static function fill_action() {
@@ -483,9 +335,8 @@
483 335 $action_key = FrmAppHelper::get_param( 'action_id', '', 'post', 'absint' );
484 336 $action_type = FrmAppHelper::get_param( 'action_type', '', 'post', 'sanitize_text_field' );
485 337
486 338 $action_control = self::get_form_actions( $action_type );
487 -
488 339 if ( empty( $action_control ) ) {
489 340 wp_die();
490 341 }
491 342
@@ -495,30 +346,21 @@
495 346 $form = self::fields_to_values( $form_action->menu_order, $values );
496 347
497 348 $use_logging = self::should_show_log_message( $action_type );
498 349
499 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php';
350 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' );
500 351 wp_die();
501 352 }
502 353
503 354 /**
504 355 * @since 3.06.04
505 - *
506 - * @param string $action_type
507 - *
508 356 * @return bool
509 357 */
510 358 private static function should_show_log_message( $action_type ) {
511 359 $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
512 - return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' );
360 + return in_array( $action_type, $logging ) && ! function_exists( 'frm_log_autoloader' );
513 361 }
514 362
515 - /**
516 - * @param int|string $form_id
517 - * @param array $values
518 - *
519 - * @return object
520 - */
521 363 private static function fields_to_values( $form_id, array &$values ) {
522 364 $form = FrmForm::getOne( $form_id );
523 365
524 366 $values = array(
@@ -526,14 +368,12 @@
526 368 'id' => $form->id,
527 369 );
528 370
529 371 $fields = FrmField::get_all_for_form( $form->id );
530 -
531 372 foreach ( $fields as $k => $f ) {
532 373 $f = (array) $f;
533 374 $opts = (array) $f['field_options'];
534 375 $f = array_merge( $opts, $f );
535 -
536 376 if ( ! isset( $f['post_field'] ) ) {
537 377 $f['post_field'] = '';
538 378 }
539 379 $values['fields'][] = $f;
@@ -542,33 +382,13 @@
542 382
543 383 return $form;
544 384 }
545 385
546 - /**
547 - * @param int $form_id
548 - *
549 - * @return void
550 - */
551 386 public static function update_settings( $form_id ) {
552 387 FrmAppHelper::permission_check( 'frm_edit_forms' );
553 388 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
554 -
555 389 if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
556 - $frm_settings = FrmAppHelper::get_settings();
557 - $error_args = array(
558 - 'title' => __( 'Verification failed', 'formidable' ),
559 - 'body' => $frm_settings->admin_permission,
560 - 'cancel_url' => add_query_arg(
561 - array(
562 - 'page' => 'formidable',
563 - 'frm_action' => 'settings',
564 - 'id' => $form_id,
565 - ),
566 - admin_url( 'admin.php?' )
567 - ),
568 - );
569 - FrmAppController::show_error_modal( $error_args );
570 - return;
390 + wp_die( esc_html__( 'You do not have permission to do that', 'formidable' ) );
571 391 }
572 392
573 393 global $wpdb;
574 394
@@ -585,9 +405,8 @@
585 405 $new_actions = array();
586 406
587 407 foreach ( $registered_actions as $registered_action ) {
588 408 $action_ids = $registered_action->update_callback( $form_id );
589 -
590 409 if ( ! empty( $action_ids ) ) {
591 410 $new_actions[] = $action_ids;
592 411 }
593 412 }
@@ -595,21 +414,13 @@
595 414 // Only use array_merge if there are new actions.
596 415 if ( ! empty( $new_actions ) ) {
597 416 $new_actions = call_user_func_array( 'array_merge', $new_actions );
598 417 }
599 -
600 418 $old_actions = array_diff( $old_actions, $new_actions );
601 419
602 420 self::delete_missing_actions( $old_actions );
603 -
604 - FrmOnSubmitHelper::save_on_submit_settings( $form_id );
605 421 }
606 422
607 - /**
608 - * @param array $old_actions
609 - *
610 - * @return void
611 - */
612 423 public static function delete_missing_actions( $old_actions ) {
613 424 if ( ! empty( $old_actions ) ) {
614 425 foreach ( $old_actions as $old_id ) {
615 426 wp_delete_post( $old_id );
@@ -617,46 +428,26 @@
617 428 FrmDb::cache_delete_group( 'frm_actions' );
618 429 }
619 430 }
620 431
621 - /**
622 - * @param int|string $entry_id
623 - * @param int|string $form_id
624 - * @param array $args
625 - *
626 - * @return void
627 - */
628 432 public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) {
629 433 $filter_args = $args;
630 434 $filter_args['entry_id'] = $entry_id;
631 435 $filter_args['form_id'] = $form_id;
632 436
633 - /**
634 - * @since 2.0.23
635 - * @since 6.11.2 $filter_args is now passed instead of $args. It includes additional ID data.
636 - *
637 - * @param string $event 'create' by default. Pro may filter this value to 'draft' instead.
638 - * @param array $filter_args
639 - */
640 - $event = apply_filters( 'frm_trigger_create_action', 'create', $filter_args );
437 + $event = apply_filters( 'frm_trigger_create_action', 'create', $args );
641 438
642 439 self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
643 440 }
644 441
645 442 /**
646 - * @param string $event
647 - * @param int|object|string $form
648 - * @param int|string $entry
649 - * @param string $type
650 - * @param array $args
651 - *
652 - * @return void
443 + * @param string $event
653 444 */
654 445 public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
655 446 $action_status = array(
656 447 'post_status' => 'publish',
657 448 );
658 - $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
449 + $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
659 450
660 451 if ( empty( $form_actions ) ) {
661 452 return;
662 453 }
@@ -662,15 +453,10 @@
662 453 }
663 454
664 455 FrmForm::maybe_get_form( $form );
665 456
666 - if ( ! is_object( $form ) ) {
667 - return;
668 - }
669 -
670 457 $link_settings = self::get_form_actions( $type );
671 -
672 - if ( 'all' !== $type ) {
458 + if ( 'all' != $type ) {
673 459 $link_settings = array( $type => $link_settings );
674 460 }
675 461
676 462 $stored_actions = array();
@@ -675,9 +461,9 @@
675 461
676 462 $stored_actions = array();
677 463 $action_priority = array();
678 464
679 - if ( in_array( $event, array( 'create', 'update' ), true ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
465 + if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
680 466 $this_event = 'import';
681 467 } else {
682 468 $this_event = $event;
683 469 }
@@ -683,11 +469,10 @@
683 469 }
684 470
685 471 foreach ( $form_actions as $action ) {
686 472
687 - $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt;
473 + $skip_this_action = ( ! in_array( $this_event, $action->post_content['event'] ) );
688 474 $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
689 -
690 475 if ( $skip_this_action ) {
691 476 continue;
692 477 }
693 478
@@ -694,18 +479,17 @@
694 479 if ( ! is_object( $entry ) ) {
695 480 $entry = FrmEntry::getOne( $entry, true );
696 481 }
697 482
698 - if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) {
483 + if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) {
699 484 continue;
700 485 }
701 486
702 - $child_entry = ( is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ( $entry && ( $entry->form_id != $form->id || $entry->parent_item_id ) ) || ! empty( $args['is_child'] );
487 + $child_entry = ( ( is_object( $form ) && is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ( $entry && ( $entry->form_id != $form->id || $entry->parent_item_id ) ) || ( isset( $args['is_child'] ) && $args['is_child'] ) );
703 488
704 489 if ( $child_entry ) {
705 490 // maybe trigger actions for sub forms
706 491 $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) );
707 -
708 492 if ( ! $trigger_children ) {
709 493 continue;
710 494 }
711 495 }
@@ -711,9 +495,8 @@
711 495 }
712 496
713 497 // Check conditional logic.
714 498 $stop = FrmFormAction::action_conditions_met( $action, $entry );
715 -
716 499 if ( $stop ) {
717 500 continue;
718 501 }
719 502
@@ -721,9 +504,9 @@
721 504 $stored_actions[ $action->ID ] = $action;
722 505 $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
723 506
724 507 unset( $action );
725 - }//end foreach
508 + }
726 509
727 510 if ( ! empty( $stored_actions ) ) {
728 511 asort( $action_priority );
729 512
@@ -731,49 +514,25 @@
731 514 new FrmNotification();
732 515
733 516 foreach ( $action_priority as $action_id => $priority ) {
734 517 $action = $stored_actions[ $action_id ];
518 + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
519 + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
735 520
736 - /**
737 - * Allows custom form action trigger.
738 - *
739 - * @since 6.10
740 - *
741 - * @param bool $skip Skip default trigger.
742 - * @param object $action Action object.
743 - * @param object $entry Entry object.
744 - * @param object $form Form object.
745 - * @param string $event Event ('create' or 'update').
746 - */
747 - if ( false === apply_filters( 'frm_custom_trigger_action', false, $action, $entry, $form, $event ) ) {
748 - do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
749 - do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
750 - }
751 -
752 521 // If post is created, get updated $entry object.
753 - if ( $action->post_excerpt === 'wppost' && $event === 'create' ) {
522 + if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
754 523 $entry = FrmEntry::getOne( $entry->id, true );
755 524 }
756 - }//end foreach
757 - }//end if
525 + }
526 + }
758 527 }
759 528
760 - /**
761 - * @param int|string $form_id
762 - * @param array $values
763 - * @param array $args
764 - *
765 - * @return void
766 - */
767 529 public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
768 - if ( empty( $args['old_id'] ) ) {
530 + if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) {
769 531 // Continue if we know which actions to copy.
770 532 return;
771 533 }
772 534
773 - /**
774 - * @var array
775 - */
776 535 $action_controls = self::get_form_actions();
777 536
778 537 foreach ( $action_controls as $action_control ) {
779 538 $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
@@ -780,13 +539,8 @@
780 539 unset( $action_control );
781 540 }
782 541 }
783 542
784 - /**
785 - * @param string $where
786 - *
787 - * @return string
788 - */
789 543 public static function limit_by_type( $where ) {
790 544 global $frm_vars, $wpdb;
791 545
792 546 if ( ! isset( $frm_vars['action_type'] ) ) {
@@ -796,32 +550,11 @@
796 550 $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
797 551
798 552 return $where;
799 553 }
800 -
801 - /**
802 - * Prevent WPML from filtering form actions based on the active language.
803 - *
804 - * @since 6.20
805 - *
806 - * @param bool|null $null
807 - * @param string $post_type
808 - *
809 - * @return bool|null
810 - */
811 - public static function prevent_wpml_translations( $null, $post_type ) {
812 - if ( self::$action_post_type === $post_type ) {
813 - return false;
814 - }
815 - return $null;
816 - }
817 554 }
818 555
819 556 class Frm_Form_Action_Factory {
820 -
821 - /**
822 - * @var array
823 - */
824 557 public $actions = array();
825 558
826 559 public function __construct() {
827 560 add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
@@ -826,22 +559,12 @@
826 559 public function __construct() {
827 560 add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
828 561 }
829 562
830 - /**
831 - * @param string $action_class
832 - *
833 - * @return void
834 - */
835 563 public function register( $action_class ) {
836 564 $this->actions[ $action_class ] = new $action_class();
837 565 }
838 566
839 - /**
840 - * @param string $action_class
841 - *
842 - * @return void
843 - */
844 567 public function unregister( $action_class ) {
845 568 if ( isset( $this->actions[ $action_class ] ) ) {
846 569 unset( $this->actions[ $action_class ] );
847 570 }