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