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