PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.23
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.23
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 -569 6.356.23 View file →
@@ -3,16 +3,12 @@
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 8
13 9 /**
14 - * @var Frm_Form_Action_Factory|null
10 + * @var array|null
15 11 */
16 12 public static $registered_actions;
17 13
18 14 /**
@@ -37,9 +33,8 @@
37 33 'has_archive' => false,
38 34 )
39 35 );
40 36
41 - self::maybe_setup_unlicensed_action_gate();
42 37 self::actions_init();
43 38 }
44 39
45 40 public static function actions_init() {
@@ -54,33 +49,28 @@
54 49 public static function register_actions() {
55 50 $action_classes = array(
56 51 'on_submit' => 'FrmOnSubmitAction',
57 52 'email' => 'FrmEmailAction',
58 - 'gated_content' => 'FrmGatedContentAction',
59 53 'wppost' => 'FrmDefPostAction',
60 54 'register' => 'FrmDefRegAction',
61 - 'stripe' => 'FrmStripeLiteAction',
62 - 'square' => 'FrmSquareAction',
63 - 'paypal' => 'FrmPayPalLiteAction',
64 - 'paypal-legacy' => 'FrmDefPayPalLegacyAction',
55 + 'paypal' => 'FrmDefPayPalAction',
65 56 'payment' => 'FrmTransLiteAction',
66 57 'quiz' => 'FrmDefQuizAction',
67 58 'quiz_outcome' => 'FrmDefQuizOutcomeAction',
59 + 'mailchimp' => 'FrmDefMlcmpAction',
68 60 'api' => 'FrmDefApiAction',
69 - 'mailchimp' => 'FrmDefMlcmpAction',
61 + 'salesforce' => 'FrmDefSalesforceAction',
70 62 'activecampaign' => 'FrmDefActiveCampaignAction',
71 63 'constantcontact' => 'FrmDefConstContactAction',
72 64 'getresponse' => 'FrmDefGetResponseAction',
65 + 'hubspot' => 'FrmDefHubspotAction',
66 + 'zapier' => 'FrmDefZapierAction',
67 + 'twilio' => 'FrmDefTwilioAction',
68 + 'highrise' => 'FrmDefHighriseAction',
73 69 'mailpoet' => 'FrmDefMailpoetAction',
70 + 'aweber' => 'FrmDefAweberAction',
74 71 'convertkit' => 'FrmDefConvertKitAction',
75 - 'aweber' => 'FrmDefAweberAction',
76 - 'twilio' => 'FrmDefTwilioAction',
77 - 'salesforce' => 'FrmDefSalesforceAction',
78 - 'hubspot' => 'FrmDefHubspotAction',
79 - 'highrise' => 'FrmDefHighriseAction',
80 - 'zapier' => 'FrmDefZapierAction',
81 72 'googlespreadsheet' => 'FrmDefGoogleSpreadsheetAction',
82 - 'n8n' => 'FrmDefN8NAction',
83 73 );
84 74
85 75 $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes );
86 76 $action_classes = self::maybe_unset_highrise( $action_classes );
@@ -87,72 +77,19 @@
87 77
88 78 include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php';
89 79 include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php';
90 80
91 - // This needs to be called after we include default_actions.php or FrmDefPayPalLegacyAction will never exist.
92 - if ( 'FrmPayPalLiteAction' === $action_classes['paypal'] || ! class_exists( 'FrmPaymentAction' ) || ! class_exists( 'FrmDefPayPalLegacyAction' ) ) {
93 - unset( $action_classes['paypal-legacy'] );
94 - }
95 -
96 81 foreach ( $action_classes as $action_class ) {
97 82 self::$registered_actions->register( $action_class );
98 83 }
99 -
100 - self::apply_default_action_descriptions();
101 84 }
102 85
103 86 /**
104 - * Sets default descriptions on registered actions from a central list.
105 - *
106 - * Keeps the description when an add-on replaces a base action class without its own.
107 - *
108 - * @since 6.31
109 - *
110 - * @return void
111 - */
112 - private static function apply_default_action_descriptions() {
113 - $descriptions = array(
114 - 'on_submit' => __( 'Success messages', 'formidable' ),
115 - 'email' => __( 'Autoresponder alerts', 'formidable' ),
116 - 'wppost' => __( 'Content publishing', 'formidable' ),
117 - 'register' => __( 'Account creation', 'formidable' ),
118 - 'payment' => __( 'Transaction alerts', 'formidable' ),
119 - 'stripe' => __( 'Payment gateway', 'formidable' ),
120 - 'square' => __( 'Payment gateway', 'formidable' ),
121 - 'paypal' => __( 'Payment gateway', 'formidable' ),
122 - 'quiz' => __( 'Automated grading', 'formidable' ),
123 - 'quiz_outcome' => __( 'Result logic', 'formidable' ),
124 - 'aweber' => __( 'List triggers', 'formidable' ),
125 - 'mailchimp' => __( 'Subscription confirmation', 'formidable' ),
126 - 'zapier' => __( 'App automation', 'formidable' ),
127 - 'n8n' => __( 'Workflow automation', 'formidable' ),
128 - 'twilio' => __( 'Text notifications', 'formidable' ),
129 - 'activecampaign' => __( 'Contact automation', 'formidable' ),
130 - 'salesforce' => __( 'Lead automation', 'formidable' ),
131 - 'constantcontact' => __( 'Content distribution', 'formidable' ),
132 - 'getresponse' => __( 'Success notifications', 'formidable' ),
133 - 'hubspot' => __( 'CRM alerts', 'formidable' ),
134 - 'mailpoet' => __( 'Plugin automation', 'formidable' ),
135 - 'api' => __( 'System integration', 'formidable' ),
136 - 'googlespreadsheet' => __( 'Spreadsheet sync', 'formidable' ),
137 - 'convertkit' => __( 'Broadcast publishing', 'formidable' ),
138 - 'gated_content' => __( 'Access control', 'formidable' ),
139 - );
140 -
141 - foreach ( self::$registered_actions->actions as $action ) {
142 - if ( $action->action_options['description'] === '' && isset( $descriptions[ $action->id_base ] ) ) {
143 - $action->action_options['description'] = $descriptions[ $action->id_base ];
144 - }
145 - }
146 - }
147 -
148 - /**
149 87 * Remove the Highrise action if it is not registered.
150 88 *
151 89 * @since 6.23
152 90 *
153 91 * @param array $action_classes
154 - *
155 92 * @return array
156 93 */
157 94 private static function maybe_unset_highrise( $action_classes ) {
158 95 if ( 'FrmDefHighriseAction' === ( $action_classes['highrise'] ?? '' ) ) {
@@ -166,10 +103,11 @@
166 103 *
167 104 * @param array $values
168 105 */
169 106 public static function email_settings( $values ) {
170 - $form = FrmForm::getOne( $values['id'] );
171 - $groups = self::form_action_groups();
107 + $form = FrmForm::getOne( $values['id'] );
108 + $groups = self::form_action_groups();
109 +
172 110 $action_controls = self::get_form_actions();
173 111 self::maybe_add_action_to_group( $action_controls, $groups );
174 112
175 113 $allowed = self::active_actions( $action_controls );
@@ -180,41 +118,23 @@
180 118 /**
181 119 * Add unknown actions to a group.
182 120 *
183 121 * @since 4.0
184 - *
185 - * @param array $action_controls
186 - * @param array $groups
187 - *
188 - * @return void
189 122 */
190 123 private static function maybe_add_action_to_group( $action_controls, &$groups ) {
191 124 $grouped = array();
192 -
193 125 foreach ( $groups as $group ) {
194 126 if ( isset( $group['actions'] ) ) {
195 127 $grouped = array_merge( $grouped, $group['actions'] );
196 128 }
197 -
198 - // Also collect actions from sections
199 - if ( ! isset( $group['sections'] ) ) {
200 - continue;
201 - }
202 -
203 - foreach ( $group['sections'] as $section ) {
204 - if ( isset( $section['actions'] ) ) {
205 - $grouped = array_merge( $grouped, $section['actions'] );
206 - }
207 - }
208 129 }
209 130
210 131 foreach ( $action_controls as $action ) {
211 - if ( isset( $groups[ $action->id_base ] ) || in_array( $action->id_base, $grouped, true ) ) {
132 + if ( isset( $groups[ $action->id_base ] ) || in_array( $action->id_base, $grouped ) ) {
212 133 continue;
213 134 }
214 135
215 136 $this_group = $action->action_options['group'];
216 -
217 137 if ( ! isset( $groups[ $this_group ] ) ) {
218 138 $this_group = 'misc';
219 139 }
220 140
@@ -232,48 +152,32 @@
232 152 *
233 153 * @return array
234 154 */
235 155 public static function form_action_groups() {
236 - // Get all action controls to check which are active
237 - $action_controls = self::get_form_actions();
238 -
239 - // Determine which actions are currently available
240 - $available_actions = self::get_available_my_actions( $action_controls );
241 -
242 - // Featured actions are add-ons that are NOT currently available
243 - $all_addon_actions = array(
244 - 'api',
245 - 'register',
246 - 'n8n',
247 - 'quiz',
248 - 'quiz_outcome',
249 - 'googlespreadsheet',
250 - );
251 - $featured_actions = array_diff( $all_addon_actions, $available_actions );
252 -
253 156 $groups = array(
254 - 'my_actions' => array(
255 - 'name' => __( 'My Actions', 'formidable' ),
256 - 'icon' => 'frmfont frm_shuffle_icon',
257 - 'sections' => array(
258 - 'active' => array(
259 - 'name' => '',
260 - 'actions' => $available_actions,
261 - ),
262 - 'featured' => array(
263 - 'name' => __( 'Featured', 'formidable' ),
264 - 'actions' => array_values( $featured_actions ),
265 - ),
157 + 'misc' => array(
158 + 'name' => '',
159 + 'icon' => 'frm_icon_font frm_shuffle_icon',
160 + 'actions' => array(
161 + 'email',
162 + 'wppost',
163 + 'register',
164 + 'quiz',
165 + 'quiz_outcome',
166 + 'twilio',
266 167 ),
267 168 ),
268 - 'payment' => array(
269 - 'name' => __( 'E-Commerce', 'formidable' ),
270 - 'icon' => 'frmfont frm_credit_card_alt_icon',
271 - 'actions' => self::get_payment_actions( $action_controls ),
169 + 'payment' => array(
170 + 'name' => __( 'eCommerce', 'formidable' ),
171 + 'icon' => 'frm_icon_font frm_credit_card_alt_icon',
172 + 'actions' => array(
173 + 'paypal',
174 + 'payment',
175 + ),
272 176 ),
273 - 'marketing' => array(
274 - 'name' => __( 'Marketing', 'formidable' ),
275 - 'icon' => 'frmfont frm_mail_bulk_icon',
177 + 'marketing' => array(
178 + 'name' => __( 'Email Marketing', 'formidable' ),
179 + 'icon' => 'frm_icon_font frm_mail_bulk_icon',
276 180 'actions' => array(
277 181 'mailchimp',
278 182 'activecampaign',
279 183 'constantcontact',
@@ -279,22 +183,15 @@
279 183 'constantcontact',
280 184 'getresponse',
281 185 'aweber',
282 186 'mailpoet',
283 - 'convertkit',
284 - 'twilio',
285 187 ),
286 188 ),
287 - 'crm' => array(
189 + 'crm' => array(
288 190 'name' => __( 'CRM', 'formidable' ),
289 - 'icon' => 'frmfont frm_address_card_icon',
191 + 'icon' => 'frm_icon_font frm_address_card_icon',
290 192 'actions' => self::get_crm_actions(),
291 193 ),
292 - 'misc' => array(
293 - 'name' => __( 'Misc', 'formidable' ),
294 - 'icon' => 'frmfont frm_shuffle_icon',
295 - 'actions' => self::get_misc_actions( $action_controls ),
296 - ),
297 194 );
298 195
299 196 return apply_filters( 'frm_action_groups', $groups );
300 197 }
@@ -299,102 +196,8 @@
299 196 return apply_filters( 'frm_action_groups', $groups );
300 197 }
301 198
302 199 /**
303 - * Get the actions that are currently available (active) for My Actions section.
304 - *
305 - * @since 6.31
306 - *
307 - * @param array $action_controls The registered action controls.
308 - *
309 - * @return array
310 - */
311 - private static function get_available_my_actions( $action_controls ) {
312 - $available = array(
313 - 'on_submit',
314 - 'email',
315 - 'stripe',
316 - 'square',
317 - 'paypal',
318 - );
319 -
320 - // Include all actions that are marked as active, including custom actions.
321 - // This ensures custom actions appear in "My Actions" when enabled.
322 - foreach ( $action_controls as $action_id => $action_control ) {
323 - if ( ! in_array( $action_id, $available, true ) && ! empty( $action_control->action_options['active'] ) ) {
324 - $available[] = $action_id;
325 - }
326 - }
327 -
328 - return $available;
329 - }
330 -
331 - /**
332 - * Get the actions to include in the Misc section.
333 - *
334 - * @since 6.31
335 - *
336 - * @param array $action_controls The registered action controls.
337 - *
338 - * @return array
339 - */
340 - private static function get_misc_actions( $action_controls ) {
341 - $misc_actions = array(
342 - 'on_submit',
343 - 'email',
344 - 'wppost',
345 - 'register',
346 - 'api',
347 - 'n8n',
348 - 'quiz',
349 - 'quiz_outcome',
350 - 'googlespreadsheet',
351 - );
352 -
353 - // Include all active actions that aren't in specific groups (payment, marketing, crm).
354 - // This ensures custom actions appear in "Misc" when enabled.
355 - $payment_actions = self::get_payment_actions( $action_controls );
356 - $marketing_actions = array( 'mailchimp', 'activecampaign', 'constantcontact', 'getresponse', 'aweber', 'mailpoet', 'convertkit', 'twilio' );
357 -
358 - $excluded_actions = array_merge( $payment_actions, $marketing_actions, self::get_crm_actions() );
359 -
360 - foreach ( $action_controls as $action_id => $action_control ) {
361 - if ( ! in_array( $action_id, $misc_actions, true ) && ! in_array( $action_id, $excluded_actions, true ) && ! empty( $action_control->action_options['active'] ) ) {
362 - $misc_actions[] = $action_id;
363 - }
364 - }
365 -
366 - return $misc_actions;
367 - }
368 -
369 - /**
370 - * Get the actions to include in the E-Commerce section.
371 - *
372 - * @since 6.33
373 - *
374 - * @param array $action_controls
375 - *
376 - * @return array
377 - */
378 - private static function get_payment_actions( $action_controls ) {
379 - $payment_actions = array(
380 - 'paypal',
381 - 'stripe',
382 - 'square',
383 - );
384 -
385 - if ( isset( $action_controls['paypal-legacy'] ) ) {
386 - $payment_actions[] = 'paypal-legacy';
387 - }
388 -
389 - if ( isset( $action_controls['payment'] ) ) {
390 - $payment_actions[] = 'payment';
391 - }
392 -
393 - return $payment_actions;
394 - }
395 -
396 - /**
397 200 * Get the actions to include in the CRM section.
398 201 *
399 202 * @since 6.23
400 203 *
@@ -403,9 +206,8 @@
403 206 private static function get_crm_actions() {
404 207 $crm_actions = array(
405 208 'salesforce',
406 209 'hubspot',
407 - 'zapier',
408 210 );
409 211
410 212 // Only include Highrise when the add-on is active.
411 213 // This is because Highrise is deprecated. We don't want to show it in Lite.
@@ -420,21 +222,17 @@
420 222 * Get the number of currently active form actions.
421 223 *
422 224 * @since 4.0
423 225 *
424 - * @param array $action_controls
425 - *
426 226 * @return array
427 227 */
428 228 private static function active_actions( $action_controls ) {
429 229 $allowed = array();
430 -
431 230 foreach ( $action_controls as $action_control ) {
432 - if ( ! empty( $action_control->action_options['active'] ) ) {
231 + if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) {
433 232 $allowed[] = $action_control->id_base;
434 233 }
435 234 }
436 -
437 235 return $allowed;
438 236 }
439 237
440 238 /**
@@ -440,15 +238,15 @@
440 238 /**
441 239 * For each add-on, add an li, class, and javascript function. If active, add an additional class.
442 240 *
443 241 * @since 4.0
444 - *
445 242 * @param object $action_control
446 243 * @param array $allowed
447 244 */
448 245 public static function show_action_icon_link( $action_control, $allowed ) {
449 - $data = array();
450 - $classes = ' frm_' . $action_control->id_base . '_action frm_single_action';
246 + $data = array();
247 + $classes = ' frm_' . $action_control->id_base . '_action frm_single_action';
248 +
451 249 $group_class = ' frm-group-' . $action_control->action_options['group'];
452 250
453 251 /* translators: %s: Name of form action */
454 252 $upgrade_label = sprintf( esc_html__( '%s form actions', 'formidable' ), $action_control->action_options['tooltip'] );
@@ -454,20 +252,15 @@
454 252 $upgrade_label = sprintf( esc_html__( '%s form actions', 'formidable' ), $action_control->action_options['tooltip'] );
455 253
456 254 $default_shown = array( 'wppost', 'register', 'payment', 'quiz', 'hubspot' );
457 255 $default_shown = array_values( array_diff( $default_shown, $allowed ) );
458 - $default_position = array_search( $action_control->id_base, $default_shown, true );
256 + $default_position = array_search( $action_control->id_base, $default_shown );
459 257 $allowed_count = count( $allowed );
460 258
461 - if ( ! empty( $action_control->action_options['active'] ) ) {
259 + if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) {
462 260 $classes .= ' frm_active_action';
463 261 } else {
464 262 $classes .= ' frm_inactive_action';
465 -
466 - if ( str_contains( $action_control->action_options['classes'], 'frm_show_expired_modal' ) ) {
467 - $classes .= ' frm_show_expired_modal';
468 - }
469 -
470 263 if ( $default_position !== false && ( $allowed_count + $default_position ) < 6 ) {
471 264 $group_class .= ' frm-default-show';
472 265 }
473 266
@@ -474,9 +267,8 @@
474 267 $data['data-upgrade'] = $upgrade_label;
475 268 $data['data-medium'] = 'settings-' . $action_control->id_base;
476 269
477 270 $upgrading = FrmAddonsController::install_link( $action_control->action_options['plugin'] );
478 -
479 271 if ( isset( $upgrading['url'] ) ) {
480 272 $data['data-oneclick'] = json_encode( $upgrading );
481 273 }
482 274
@@ -484,67 +276,41 @@
484 276 $data['data-message'] = $action_control->action_options['message'];
485 277 }
486 278
487 279 $requires = FrmFormsHelper::get_plan_required( $upgrading );
488 -
489 280 if ( $requires && 'free' !== $requires ) {
490 281 $data['data-requires'] = $requires;
491 282 }
492 -
493 - $learn_more_slug = ! empty( $action_control->action_options['learn-more'] )
494 - ? $action_control->action_options['learn-more']
495 - : self::get_learn_more_slug( $action_control->id_base );
496 -
497 - if ( $learn_more_slug ) {
498 - $data['data-learn-more'] = FrmAppHelper::get_doc_url(
499 - $learn_more_slug,
500 - 'settings-' . $action_control->id_base,
501 - ! str_contains( $learn_more_slug, '/' )
502 - );
503 - }
504 283 }//end if
505 284
506 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
507 - }
508 -
509 - /**
510 - * Get the HTML attributes for the action icon.
511 - *
512 - * @since 6.31
513 - *
514 - * @param object $action_control
515 - *
516 - * @return array
517 - */
518 - public static function get_action_icon_atts( $action_control ) {
519 - if ( 'var(--primary-700)' !== $action_control->action_options['color'] ) {
520 - return array(
285 + // HTML to include on the icon.
286 + $icon_atts = array();
287 + if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) {
288 + $icon_atts = array(
521 289 'style' => '--primary-700:' . $action_control->action_options['color'],
522 290 );
523 291 }
524 292
525 - return array();
293 + include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
526 294 }
527 295
528 296 /**
529 297 * @param string $action
530 - *
531 298 * @return array|FrmFormAction A single form action is returned when a specific $action value is requested.
532 299 */
533 300 public static function get_form_actions( $action = 'all' ) {
534 301 $temp_actions = self::$registered_actions;
535 -
536 - if ( $temp_actions ) {
537 - $temp_actions = $temp_actions->actions;
538 - } else {
302 + if ( empty( $temp_actions ) ) {
539 303 self::actions_init();
540 304 $temp_actions = self::$registered_actions->actions;
305 + } else {
306 + $temp_actions = $temp_actions->actions;
541 307 }
542 308
543 309 $actions = array();
544 310
545 311 foreach ( $temp_actions as $a ) {
546 - if ( 'all' !== $action && $a->id_base === $action ) {
312 + if ( 'all' !== $action && $a->id_base == $action ) {
547 313 return $a;
548 314 }
549 315
550 316 $actions[ $a->id_base ] = $a;
@@ -554,16 +320,11 @@
554 320 }
555 321
556 322 /**
557 323 * @since 2.0
558 - *
559 - * @param object $form
560 - * @param array $values
561 - *
562 - * @return void
563 324 */
564 325 public static function list_actions( $form, $values ) {
565 - if ( ! $form ) {
326 + if ( empty( $form ) ) {
566 327 return;
567 328 }
568 329
569 330 /**
@@ -590,15 +351,11 @@
590 351 }
591 352
592 353 self::maybe_show_limit_warning( $form->id, $form_actions );
593 354
594 - echo '<p class="frm-mb-lg frm-no-actions-message' . ( $form_actions ? ' frm_hidden' : '' ) . '"> '
595 - . esc_html__( 'No actions have been added yet. Select an action above to get started.', 'formidable' )
596 - . '</p>';
597 -
598 355 foreach ( $form_actions as $action ) {
599 356 if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
600 - // Don't try and show settings if action no longer exists
357 + // don't try and show settings if action no longer exists
601 358 continue;
602 359 }
603 360
604 361 self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
@@ -612,20 +369,17 @@
612 369 * @since 6.17
613 370 *
614 371 * @param int|string $form_id
615 372 * @param array $form_actions
616 - *
617 373 * @return void
618 374 */
619 375 private static function maybe_show_limit_warning( $form_id, $form_actions ) {
620 376 $count = count( $form_actions );
621 -
622 377 if ( $count < 99 ) {
623 378 return;
624 379 }
625 380
626 381 $limit = FrmFormAction::get_action_limit( $form_id );
627 -
628 382 if ( $limit < 99 || $count < $limit ) {
629 383 return;
630 384 }
631 385
@@ -631,9 +385,9 @@
631 385
632 386 $documentation_url = 'https://formidableforms.com/knowledgebase/frm_form_action_limit/#kb-increase-limit-of-form-actions';
633 387
634 388 echo '<div class="frm_warning_style">';
635 - FrmAppHelper::icon_by_class( 'frmfont frm_alert_icon' );
389 + FrmAppHelper::icon_by_class( 'frm_icon_font frm_alert_icon' );
636 390 echo '&nbsp;';
637 391 printf(
638 392 // translators: %s: URL to documentation
639 393 esc_html__( 'You have reached your form action limit. To increase this limit, you will require additional code. Visit our documentation at %s.', 'formidable' ),
@@ -641,17 +395,8 @@
641 395 );
642 396 echo '</div>';
643 397 }
644 398
645 - /**
646 - * @param WP_Post $form_action
647 - * @param object $form
648 - * @param int $action_key Action ID.
649 - * @param FrmFormAction $action_control
650 - * @param array $values
651 - *
652 - * @return void
653 - */
654 399 public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
655 400 $action_control->_set( $action_key );
656 401
657 402 $use_logging = self::should_show_log_message( $form_action->post_excerpt );
@@ -662,18 +407,13 @@
662 407 public static function add_form_action() {
663 408 FrmAppHelper::permission_check( 'frm_edit_forms' );
664 409 check_ajax_referer( 'frm_ajax', 'nonce' );
665 410
666 - $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' );
667 - $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' );
668 - $lite_actions = array_fill_keys( self::get_lite_actions(), true );
411 + global $frm_vars;
669 412
670 - if ( ! FrmAppHelper::pro_is_connected() && ! isset( $lite_actions[ $action_type ] ) ) {
671 - wp_die();
672 - }
413 + $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' );
414 + $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' );
673 415
674 - global $frm_vars;
675 -
676 416 /**
677 417 * @var FrmFormAction
678 418 */
679 419 $action_control = self::get_form_actions( $action_type );
@@ -678,60 +418,37 @@
678 418 */
679 419 $action_control = self::get_form_actions( $action_type );
680 420 $action_control->_set( $action_key );
681 421
682 - $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' );
683 - $form_action = $action_control->prepare_new( $form_id );
684 - $existing_titles = (array) FrmAppHelper::get_post_param( 'existing_titles', array(), 'sanitize_text_field' );
422 + $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' );
685 423
686 - if ( $existing_titles ) {
687 - $form_action->post_title = self::get_unique_action_title( $form_action->post_title, $existing_titles );
688 - }
424 + $form_action = $action_control->prepare_new( $form_id );
425 + $use_logging = self::should_show_log_message( $action_type );
689 426
690 - $use_logging = self::should_show_log_message( $action_type );
691 - $values = array();
692 - $form = self::fields_to_values( $form_id, $values );
427 + $values = array();
428 + $form = self::fields_to_values( $form_id, $values );
693 429
694 430 include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php';
695 431 wp_die();
696 432 }
697 433
698 - /**
699 - * Returns the first available title not in $existing_titles, appending " (2)", " (3)", etc. if needed.
700 - *
701 - * @since 6.31
702 - *
703 - * @param string $base_title Default action title from the action type.
704 - * @param string[] $existing_titles Titles currently visible in the form editor.
705 - *
706 - * @return string
707 - */
708 - private static function get_unique_action_title( $base_title, array $existing_titles ) {
709 - $taken = array_flip( $existing_titles );
710 - $title = $base_title;
711 -
712 - for ( $n = 2; isset( $taken[ $title ] ); $n++ ) {
713 - $title = $base_title . ' (' . $n . ')';
714 - }
715 -
716 - return $title;
717 - }
718 -
719 434 public static function fill_action() {
720 435 FrmAppHelper::permission_check( 'frm_edit_forms' );
721 436 check_ajax_referer( 'frm_ajax', 'nonce' );
722 437
723 - $action_key = FrmAppHelper::get_param( 'action_id', '', 'post', 'absint' );
724 - $action_type = FrmAppHelper::get_param( 'action_type', '', 'post', 'sanitize_text_field' );
438 + $action_key = FrmAppHelper::get_param( 'action_id', '', 'post', 'absint' );
439 + $action_type = FrmAppHelper::get_param( 'action_type', '', 'post', 'sanitize_text_field' );
440 +
725 441 $action_control = self::get_form_actions( $action_type );
726 -
727 - if ( ! $action_control ) {
442 + if ( empty( $action_control ) ) {
728 443 wp_die();
729 444 }
730 445
731 446 $form_action = $action_control->get_single_action( $action_key );
732 - $values = array();
733 - $form = self::fields_to_values( $form_action->menu_order, $values );
447 +
448 + $values = array();
449 + $form = self::fields_to_values( $form_action->menu_order, $values );
450 +
734 451 $use_logging = self::should_show_log_message( $action_type );
735 452
736 453 include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php';
737 454 wp_die();
@@ -738,40 +455,15 @@
738 455 }
739 456
740 457 /**
741 458 * @since 3.06.04
742 - *
743 - * @param string $action_type
744 - *
745 459 * @return bool
746 460 */
747 461 private static function should_show_log_message( $action_type ) {
748 - $logging = array(
749 - 'activecampaign',
750 - 'api',
751 - 'aweber',
752 - 'campaignmonitor',
753 - 'constantcontact',
754 - 'convertkit',
755 - 'getresponse',
756 - 'googlespreadsheet',
757 - 'hubspot',
758 - 'mailchimp',
759 - 'mailpoet',
760 - 'n8n',
761 - 'salesforce',
762 - 'twilio',
763 - 'zapier',
764 - );
462 + $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
765 463 return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' );
766 464 }
767 465
768 - /**
769 - * @param int|string $form_id
770 - * @param array $values
771 - *
772 - * @return object
773 - */
774 466 private static function fields_to_values( $form_id, array &$values ) {
775 467 $form = FrmForm::getOne( $form_id );
776 468
777 469 $values = array(
@@ -779,14 +471,12 @@
779 471 'id' => $form->id,
780 472 );
781 473
782 474 $fields = FrmField::get_all_for_form( $form->id );
783 -
784 475 foreach ( $fields as $k => $f ) {
785 476 $f = (array) $f;
786 477 $opts = (array) $f['field_options'];
787 478 $f = array_merge( $opts, $f );
788 -
789 479 if ( ! isset( $f['post_field'] ) ) {
790 480 $f['post_field'] = '';
791 481 }
792 482 $values['fields'][] = $f;
@@ -797,15 +487,13 @@
797 487 }
798 488
799 489 /**
800 490 * @param int $form_id
801 - *
802 491 * @return void
803 492 */
804 493 public static function update_settings( $form_id ) {
805 494 FrmAppHelper::permission_check( 'frm_edit_forms' );
806 495 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
807 -
808 496 if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
809 497 $frm_settings = FrmAppHelper::get_settings();
810 498 $error_args = array(
811 499 'title' => __( 'Verification failed', 'formidable' ),
@@ -838,19 +526,17 @@
838 526 $new_actions = array();
839 527
840 528 foreach ( $registered_actions as $registered_action ) {
841 529 $action_ids = $registered_action->update_callback( $form_id );
842 -
843 - if ( $action_ids ) {
530 + if ( ! empty( $action_ids ) ) {
844 531 $new_actions[] = $action_ids;
845 532 }
846 533 }
847 534
848 535 // Only use array_merge if there are new actions.
849 - if ( $new_actions ) {
536 + if ( ! empty( $new_actions ) ) {
850 537 $new_actions = call_user_func_array( 'array_merge', $new_actions );
851 538 }
852 -
853 539 $old_actions = array_diff( $old_actions, $new_actions );
854 540
855 541 self::delete_missing_actions( $old_actions );
856 542
@@ -856,32 +542,17 @@
856 542
857 543 FrmOnSubmitHelper::save_on_submit_settings( $form_id );
858 544 }
859 545
860 - /**
861 - * @param array $old_actions
862 - *
863 - * @return void
864 - */
865 546 public static function delete_missing_actions( $old_actions ) {
866 - if ( ! $old_actions ) {
867 - return;
547 + if ( ! empty( $old_actions ) ) {
548 + foreach ( $old_actions as $old_id ) {
549 + wp_delete_post( $old_id );
550 + }
551 + FrmDb::cache_delete_group( 'frm_actions' );
868 552 }
869 -
870 - foreach ( $old_actions as $old_id ) {
871 - wp_delete_post( $old_id );
872 - }
873 -
874 - FrmDb::cache_delete_group( 'frm_actions' );
875 553 }
876 554
877 - /**
878 - * @param int|string $entry_id
879 - * @param int|string $form_id
880 - * @param array $args
881 - *
882 - * @return void
883 - */
884 555 public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) {
885 556 $filter_args = $args;
886 557 $filter_args['entry_id'] = $entry_id;
887 558 $filter_args['form_id'] = $form_id;
@@ -898,34 +569,26 @@
898 569 self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
899 570 }
900 571
901 572 /**
902 - * @param string $event
903 - * @param int|object|string $form
904 - * @param int|object|string $entry
905 - * @param string $type
906 - * @param array $args
907 - *
908 - * @return void
573 + * @param string $event
909 574 */
910 - public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
575 + public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
911 576 $action_status = array(
912 577 'post_status' => 'publish',
913 578 );
914 - $form_actions = FrmFormAction::get_action_for_form( is_object( $form ) ? $form->id : $form, $type, $action_status );
579 + $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
915 580
916 - if ( ! $form_actions ) {
581 + if ( empty( $form_actions ) ) {
917 582 return;
918 583 }
919 584
920 585 FrmForm::maybe_get_form( $form );
921 -
922 586 if ( ! is_object( $form ) ) {
923 587 return;
924 588 }
925 589
926 590 $link_settings = self::get_form_actions( $type );
927 -
928 591 if ( 'all' !== $type ) {
929 592 $link_settings = array( $type => $link_settings );
930 593 }
931 594
@@ -938,11 +601,11 @@
938 601 $this_event = $event;
939 602 }
940 603
941 604 foreach ( $form_actions as $action ) {
605 +
942 606 $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt;
943 607 $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
944 -
945 608 if ( $skip_this_action ) {
946 609 continue;
947 610 }
948 611
@@ -949,18 +612,17 @@
949 612 if ( ! is_object( $entry ) ) {
950 613 $entry = FrmEntry::getOne( $entry, true );
951 614 }
952 615
953 - if ( ! $entry || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) {
616 + if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) {
954 617 continue;
955 618 }
956 619
957 - $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
620 + $child_entry = ( is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ( $entry && ( $entry->form_id != $form->id || $entry->parent_item_id ) ) || ! empty( $args['is_child'] );
958 621
959 622 if ( $child_entry ) {
960 - // Maybe trigger actions for sub forms
623 + // maybe trigger actions for sub forms
961 624 $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) );
962 -
963 625 if ( ! $trigger_children ) {
964 626 continue;
965 627 }
966 628 }
@@ -966,9 +628,8 @@
966 628 }
967 629
968 630 // Check conditional logic.
969 631 $stop = FrmFormAction::action_conditions_met( $action, $entry );
970 -
971 632 if ( $stop ) {
972 633 continue;
973 634 }
974 635
@@ -978,9 +639,9 @@
978 639
979 640 unset( $action );
980 641 }//end foreach
981 642
982 - if ( $stored_actions ) {
643 + if ( ! empty( $stored_actions ) ) {
983 644 asort( $action_priority );
984 645
985 646 // Make sure hooks are loaded.
986 647 new FrmNotification();
@@ -1011,15 +672,8 @@
1011 672 }//end foreach
1012 673 }//end if
1013 674 }
1014 675
1015 - /**
1016 - * @param int|string $form_id
1017 - * @param array $values
1018 - * @param array $args
1019 - *
1020 - * @return void
1021 - */
1022 676 public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
1023 677 if ( empty( $args['old_id'] ) ) {
1024 678 // Continue if we know which actions to copy.
1025 679 return;
@@ -1035,13 +689,8 @@
1035 689 unset( $action_control );
1036 690 }
1037 691 }
1038 692
1039 - /**
1040 - * @param string $where
1041 - *
1042 - * @return string
1043 - */
1044 693 public static function limit_by_type( $where ) {
1045 694 global $frm_vars, $wpdb;
1046 695
1047 696 if ( ! isset( $frm_vars['action_type'] ) ) {
@@ -1047,9 +696,11 @@
1047 696 if ( ! isset( $frm_vars['action_type'] ) ) {
1048 697 return $where;
1049 698 }
1050 699
1051 - return $where . $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
700 + $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
701 +
702 + return $where;
1052 703 }
1053 704
1054 705 /**
1055 706 * Prevent WPML from filtering form actions based on the active language.
@@ -1057,136 +708,19 @@
1057 708 * @since 6.20
1058 709 *
1059 710 * @param bool|null $null
1060 711 * @param string $post_type
1061 - *
1062 712 * @return bool|null
1063 713 */
1064 714 public static function prevent_wpml_translations( $null, $post_type ) {
1065 - return self::$action_post_type === $post_type ? false : $null;
1066 - }
1067 -
1068 - /**
1069 - * If Pro is not connected, hook a filter that will force all non-Lite
1070 - * actions to inactive so the upgrade popup is shown instead.
1071 - *
1072 - * @since 6.31
1073 - *
1074 - * @return void
1075 - */
1076 - private static function maybe_setup_unlicensed_action_gate() {
1077 - if ( FrmAppHelper::pro_is_connected() ) {
1078 - return;
715 + if ( self::$action_post_type === $post_type ) {
716 + return false;
1079 717 }
1080 -
1081 - add_filter( 'frm_registered_form_actions', array( self::class, 'disable_unlicensed_actions' ), 100 );
718 + return $null;
1082 719 }
1083 -
1084 - /**
1085 - * For every registered action that is not a Lite action, add a per-action
1086 - * options filter that forces it to inactive with the upgrade class.
1087 - *
1088 - * Runs inside apply_filters('frm_registered_form_actions') at priority 100,
1089 - * so the per-key option filters are in place before the class constructors
1090 - * run in the foreach loop that follows.
1091 - *
1092 - * @since 6.31
1093 - *
1094 - * @param array $actions Map of action_key => class_name.
1095 - *
1096 - * @return array
1097 - */
1098 - public static function disable_unlicensed_actions( $actions ) {
1099 - $lite_actions = array_fill_keys( self::get_lite_actions(), true );
1100 -
1101 - foreach ( array_keys( $actions ) as $key ) {
1102 - if ( isset( $lite_actions[ $key ] ) ) {
1103 - continue;
1104 - }
1105 -
1106 - add_filter(
1107 - 'frm_' . $key . '_action_options',
1108 - function ( $options ) {
1109 - $options['active'] = false;
1110 -
1111 - if ( ! str_contains( $options['classes'], 'frm_show_upgrade' ) ) {
1112 - $options['classes'] .= ' frm_show_upgrade';
1113 - }
1114 -
1115 - return $options;
1116 - }
1117 - );
1118 - }//end foreach
1119 -
1120 - return $actions;
1121 - }
1122 -
1123 - /**
1124 - * Get action keys that are available in Lite without a Pro license.
1125 - *
1126 - * @since 6.31
1127 - *
1128 - * @return string[]
1129 - */
1130 - public static function get_lite_actions() {
1131 - return apply_filters( 'frm_lite_form_actions', array( 'on_submit', 'email', 'payment', 'stripe', 'square', 'paypal', 'gated_content' ) );
1132 - }
1133 -
1134 - /**
1135 - * Single source of truth for learn-more URL slugs used in
1136 - * upgrade modals for non-Lite form actions.
1137 - *
1138 - * Slugs without '/' are KB doc slugs (knowledgebase/ prefix is added).
1139 - * Slugs with '/' are direct paths (e.g. features/) used as-is.
1140 - *
1141 - * @since 6.31
1142 - *
1143 - * @return array<string,string> Map of action_key => URL slug.
1144 - */
1145 - public static function get_action_learn_more_links() {
1146 - return array(
1147 - 'wppost' => 'features/user-submitted-posts-wordpress-forms',
1148 - 'register' => 'user-registration',
1149 - 'paypal' => 'features/paypal-wordpress-payments',
1150 - 'quiz' => 'quiz-maker-forms',
1151 - 'quiz_outcome' => 'quiz-maker-forms',
1152 - 'aweber' => 'features/aweber-addon',
1153 - 'mailchimp' => 'features/mailchimp-addon',
1154 - 'zapier' => 'features/form-entry-routing-with-zapier',
1155 - 'twilio' => 'features/twilio-sms-form-notifications',
1156 - 'activecampaign' => 'features/entries-to-activecampaign',
1157 - 'salesforce' => 'features/form-entries-to-salesforce',
1158 - 'constantcontact' => 'features/entries-to-constant-contact',
1159 - 'getresponse' => 'features/form-entries-to-getresponse',
1160 - 'hubspot' => 'features/form-entries-to-hubspot',
1161 - 'mailpoet' => 'features/mailpoet-newsletters-addon',
1162 - 'api' => 'features/wordpress-form-api',
1163 - 'googlespreadsheet' => 'features/google-sheets',
1164 - 'n8n' => 'features/connect-your-forms-to-any-app-with-n8n',
1165 - 'convertkit' => 'features/convertkit',
1166 - );
1167 - }
1168 -
1169 - /**
1170 - * Look up the learn-more doc slug for a given action key.
1171 - *
1172 - * @since 6.31
1173 - *
1174 - * @param string $action_key Action identifier (e.g. 'register').
1175 - *
1176 - * @return string Doc slug or empty string.
1177 - */
1178 - private static function get_learn_more_slug( $action_key ) {
1179 - $links = self::get_action_learn_more_links();
1180 - return $links[ $action_key ] ?? '';
1181 - }
1182 720 }
1183 721
1184 722 class Frm_Form_Action_Factory {
1185 -
1186 - /**
1187 - * @var array
1188 - */
1189 723 public $actions = array();
1190 724
1191 725 public function __construct() {
1192 726 add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
@@ -1191,22 +725,12 @@
1191 725 public function __construct() {
1192 726 add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
1193 727 }
1194 728
1195 - /**
1196 - * @param string $action_class
1197 - *
1198 - * @return void
1199 - */
1200 729 public function register( $action_class ) {
1201 730 $this->actions[ $action_class ] = new $action_class();
1202 731 }
1203 732
1204 - /**
1205 - * @param string $action_class
1206 - *
1207 - * @return void
1208 - */
1209 733 public function unregister( $action_class ) {
1210 734 if ( isset( $this->actions[ $action_class ] ) ) {
1211 735 unset( $this->actions[ $action_class ] );
1212 736 }
@@ -1215,9 +739,9 @@
1215 739 public function _register_actions() {
1216 740 $keys = array_keys( $this->actions );
1217 741
1218 742 foreach ( $keys as $key ) {
1219 - // Don't register new action if old action with the same id is already registered
743 + // don't register new action if old action with the same id is already registered
1220 744 if ( ! isset( $this->actions[ $key ] ) ) {
1221 745 $this->actions[ $key ]->_register();
1222 746 }
1223 747 }