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