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