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