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