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