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