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