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