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