PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2
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
formidable / classes / models / FrmFormAction.php

FrmFormAction.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.2, at classes/models/FrmFormAction.php

871 lines 24.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmFormAction {
7
8 public $id_base; // Root id for all actions of this type.
9 public $name; // Name for this action type.
10 public $option_name;
11 public $action_options; // Option array passed to wp_register_sidebar_widget()
12 public $control_options; // Option array passed to wp_register_widget_control()
13
14 public $form_id; // The ID of the form to evaluate
15 public $number = false; // Unique ID number of the current instance.
16 public $id = ''; // Unique ID string of the current instance (id_base-number)
17 public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.
18
19 // Member functions that you must over-ride.
20
21 /**
22 * This function should check that $new_instance is set correctly.
23 * The newly calculated value of $instance should be returned.
24 * If "false" is returned, the instance won't be saved/updated.
25 *
26 * @param array $new_instance New settings for this instance as input by the user via form()
27 * @param array $old_instance Old settings for this instance
28 *
29 * @return array Settings to save or bool false to cancel saving
30 */
31 public function update( $new_instance, $old_instance ) {
32 return $new_instance;
33 }
34
35 /**
36 * Echo the settings update form
37 *
38 * @param array $instance Current settings
39 */
40 public function form( $instance, $args = array() ) {
41 echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
42
43 return 'noform';
44 }
45
46 /**
47 * @return array of the default options
48 */
49 public function get_defaults() {
50 return array();
51 }
52
53 public function get_switch_fields() {
54 return array();
55 }
56
57 public function migrate_values( $action, $form ) {
58 return $action;
59 }
60
61 // Functions you'll need to call.
62
63 /**
64 * PHP5 constructor
65 *
66 * @param string $id_base Optional Base ID for the widget, lower case,
67 * if left empty a portion of the widget's class name will be used. Has to be unique.
68 * @param string $name Name for the widget displayed on the configuration page.
69 * @param array $action_options Optional Passed to wp_register_sidebar_widget()
70 * - description: shown on the configuration page
71 * - classname
72 * @param array $control_options Optional Passed to wp_register_widget_control()
73 * - width: required if more than 250px
74 * - height: currently not used but may be needed in the future
75 */
76 public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
77 if ( ! defined( 'ABSPATH' ) ) {
78 die( 'You are not allowed to call this page directly.' );
79 }
80
81 $this->id_base = strtolower( $id_base );
82 $this->name = $name;
83 $this->option_name = 'frm_' . $this->id_base . '_action';
84
85 $default_options = array(
86 'classes' => '',
87 'active' => true,
88 'event' => array( 'create' ),
89 'limit' => 1,
90 'force_event' => false,
91 'priority' => 20,
92 'ajax_load' => true,
93 'plugin' => $this->id_base,
94 'tooltip' => $name,
95 'group' => $id_base,
96 'color' => '',
97 );
98
99 $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
100 $group = $this->get_group( $action_options );
101 $action_options['group'] = $group['id'];
102
103 if ( ! isset( $action_options['color'] ) ) {
104 $colors = array( 'green', 'orange', 'purple' );
105 shuffle( $colors );
106 $action_options['color'] = 'var(--' . reset( $colors ) . ')';
107 }
108
109 $upgrade_class = $action_options['classes'] === 'frm_show_upgrade';
110 if ( $action_options['group'] === $id_base ) {
111 $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
112 $action_options['classes'] = $group['icon'];
113 } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) {
114 $action_options['classes'] = $group['icon'];
115 }
116
117 if ( $upgrade_class ) {
118 $action_options['classes'] .= ' frm_show_upgrade';
119 }
120
121 $this->action_options = wp_parse_args( $action_options, $default_options );
122 $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
123 }
124
125 /**
126 * @param string $id_base
127 */
128 public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) {
129 self::__construct( $id_base, $name, $action_options, $control_options );
130 }
131
132 /**
133 * Help to switch old field id by new field id for duplicate form
134 *
135 * @param string $action id of the field that needs to be switched
136 *
137 * @return string
138 */
139 public function maybe_switch_field_ids( $action ) {
140 $updated_action = apply_filters( 'frm_maybe_switch_field_ids', $action );
141 if ( $updated_action === $action ) {
142 $updated_action = FrmFieldsHelper::switch_field_ids( $action );
143 }
144 return $updated_action;
145 }
146
147 /**
148 * @since 4.0
149 */
150 protected function get_group( $action_options ) {
151 $groups = FrmFormActionsController::form_action_groups();
152 $group = 'misc';
153
154 if ( isset( $action_options['group'] ) && isset( $groups[ $action_options['group'] ] ) ) {
155 $group = $action_options['group'];
156 } elseif ( isset( $groups[ $this->id_base ] ) ) {
157 $group = $this->id_base;
158 } else {
159 foreach ( $groups as $name => $check_group ) {
160 if ( isset( $check_group['actions'] ) && in_array( $this->id_base, $check_group['actions'] ) ) {
161 $group = $name;
162 break;
163 }
164 }
165 }
166
167 $groups[ $group ]['id'] = $group;
168 return $groups[ $group ];
169 }
170
171 /**
172 * Constructs name attributes for use in form() fields
173 *
174 * This function should be used in form() methods to create name attributes for fields to be saved by update()
175 *
176 * @param string $field_name Field name
177 *
178 * @return string Name attribute for $field_name
179 */
180 public function get_field_name( $field_name, $post_field = 'post_content' ) {
181 $name = $this->option_name . '[' . $this->number . ']';
182 $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
183 $name .= '[' . $field_name . ']';
184
185 return $name;
186 }
187
188 /**
189 * Constructs id attributes for use in form() fields
190 *
191 * This function should be used in form() methods to create id attributes for fields to be saved by update()
192 *
193 * @param string $field_name Field name
194 *
195 * @return string ID attribute for $field_name
196 */
197 public function get_field_id( $field_name ) {
198 return $field_name . '_' . $this->number;
199 }
200
201 // Private Function. Don't worry about this.
202
203 public function _set( $number ) {
204 $this->number = $number;
205 $this->id = $this->id_base . '-' . $number;
206 }
207
208 public function prepare_new( $form_id = false ) {
209 if ( $form_id ) {
210 $this->form_id = $form_id;
211 }
212
213 $post_content = array();
214 $default_values = $this->get_global_defaults();
215
216 // fill default values
217 $post_content = wp_parse_args( $post_content, $default_values );
218
219 if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) {
220 $post_content['event'] = array( reset( $this->action_options['event'] ) );
221 }
222
223 $form_action = array(
224 'post_title' => $this->name,
225 'post_content' => $post_content,
226 'post_excerpt' => $this->id_base,
227 'ID' => '',
228 'post_status' => 'publish',
229 'post_type' => FrmFormActionsController::$action_post_type,
230 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number,
231 'menu_order' => $this->form_id,
232 );
233 unset( $post_content );
234
235 return (object) $form_action;
236 }
237
238 public function create( $form_id ) {
239 $this->form_id = $form_id;
240
241 $action = $this->prepare_new();
242
243 return $this->save_settings( $action );
244 }
245
246 public function duplicate_form_actions( $form_id, $old_id ) {
247 if ( $form_id == $old_id ) {
248 // don't duplicate the actions if this is a template getting updated
249 return;
250 }
251
252 $this->form_id = $old_id;
253 $actions = $this->get_all( $old_id );
254
255 $this->form_id = $form_id;
256 foreach ( $actions as $action ) {
257 $this->duplicate_one( $action, $form_id );
258 unset( $action );
259 }
260 }
261
262 /* Check if imported action should be created or updated
263 *
264 * @since 2.0
265 *
266 * @param array $action
267 * @return integer $post_id
268 */
269 public function maybe_create_action( $action, $forms ) {
270 if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
271 // Update action only
272 $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
273 $post_id = $this->save_settings( $action );
274 } else {
275 // Create action
276 $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
277 $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
278 }
279
280 return $post_id;
281 }
282
283 public function duplicate_one( $action, $form_id ) {
284 global $frm_duplicate_ids;
285
286 $action->menu_order = $form_id;
287 $switch = $this->get_global_switch_fields();
288
289 foreach ( (array) $action->post_content as $key => $val ) {
290 if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
291 $action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
292 } elseif ( ! is_array( $val ) ) {
293 $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
294 } elseif ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
295 // loop through each value if empty
296 if ( empty( $switch[ $key ] ) ) {
297 $switch[ $key ] = array_keys( $val );
298 }
299
300 foreach ( $switch[ $key ] as $subkey ) {
301 $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
302 }
303 }
304
305 unset( $key, $val );
306 }
307 unset( $action->ID );
308
309 return $this->save_settings( $action );
310 }
311
312 private function duplicate_array_walk( $action, $subkey, $val ) {
313 global $frm_duplicate_ids;
314
315 if ( is_array( $subkey ) ) {
316 foreach ( $subkey as $subkey2 ) {
317 foreach ( (array) $val as $ck => $cv ) {
318 if ( is_array( $cv ) ) {
319 $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
320 } elseif ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
321 $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
322 }
323 }
324 }
325 } else {
326 foreach ( (array) $val as $ck => $cv ) {
327 if ( is_array( $cv ) ) {
328 $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
329 } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
330 $action[ $ck ] = $frm_duplicate_ids[ $cv ];
331 } elseif ( $ck == $subkey ) {
332 $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] );
333 }
334 }
335 }
336
337 return $action;
338 }
339
340 /**
341 * Deal with changed settings.
342 *
343 * Do NOT over-ride this function
344 */
345 public function update_callback( $form_id ) {
346 $this->form_id = $form_id;
347
348 $all_instances = $this->get_settings();
349
350 // We need to update the data
351 if ( $this->updated ) {
352 return;
353 }
354
355 // phpcs:ignore WordPress.Security.NonceVerification.Missing
356 if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
357 // Sanitizing removes scripts and <email> type of values.
358 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
359 $settings = wp_unslash( $_POST[ $this->option_name ] );
360 } else {
361 return;
362 }
363
364 $action_ids = array();
365
366 foreach ( $settings as $number => $new_instance ) {
367 $this->_set( $number );
368
369 $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
370
371 if ( ! isset( $new_instance['post_status'] ) ) {
372 $new_instance['post_status'] = 'draft';
373 }
374
375 // settings were never opened, so don't update
376 if ( ! isset( $new_instance['post_title'] ) ) {
377 $this->maybe_update_status( $new_instance, $old_instance );
378 $action_ids[] = $new_instance['ID'];
379 $this->updated = true;
380 continue;
381 }
382
383 $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
384 $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
385 $new_instance['menu_order'] = $this->form_id;
386 $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
387
388 $instance = $this->update( $new_instance, $old_instance );
389
390 /**
391 * Filter an action's settings before saving.
392 *
393 * Returning false will effectively short-circuit the widget's ability
394 * to update settings.
395 *
396 * @since 2.0
397 *
398 * @param array $instance The current widget instance's settings.
399 * @param array $new_instance Array of new widget settings.
400 * @param array $old_instance Array of old widget settings.
401 * @param WP_Widget $this The current widget instance.
402 */
403 $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
404
405 $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
406 $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this );
407
408 if ( false !== $instance ) {
409 $all_instances[ $number ] = $instance;
410 }
411
412 $action_ids[] = $this->save_settings( $instance );
413
414 $this->updated = true;
415 }
416
417 return $action_ids;
418 }
419
420 /**
421 * If the status of the action has changed, update it
422 *
423 * @since 3.04
424 */
425 protected function maybe_update_status( $new_instance, $old_instance ) {
426 if ( $new_instance['post_status'] !== $old_instance->post_status ) {
427 self::clear_cache();
428 wp_update_post(
429 array(
430 'ID' => $new_instance['ID'],
431 'post_status' => $new_instance['post_status'],
432 )
433 );
434 }
435 }
436
437 public function save_settings( $settings ) {
438 self::clear_cache();
439
440 return FrmDb::save_settings( $settings, 'frm_actions' );
441 }
442
443 public function get_single_action( $id ) {
444 $action = get_post( $id );
445 if ( $action ) {
446 $action = $this->prepare_action( $action );
447 $this->_set( $id );
448 }
449
450 return $action;
451 }
452
453 public function get_one( $form_id ) {
454 return $this->get_all( $form_id, 1 );
455 }
456
457 public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
458 $action_controls = FrmFormActionsController::get_form_actions( $type );
459 if ( empty( $action_controls ) ) {
460 // don't continue if there are no available actions
461 return array();
462 }
463
464 if ( 'all' != $type ) {
465 return $action_controls->get_all( $form_id, $atts );
466 }
467
468 self::prepare_get_action( $atts );
469
470 $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
471
472 $args = self::action_args( $form_id, $limit );
473 $args['post_status'] = $atts['post_status'];
474 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
475
476 if ( ! $actions ) {
477 return array();
478 }
479
480 $settings = array();
481 foreach ( $actions as $action ) {
482 // some plugins/themes are formatting the post_excerpt
483 $action->post_excerpt = sanitize_title( $action->post_excerpt );
484
485 if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
486 continue;
487 }
488
489 $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
490 $settings[ $action->ID ] = $action;
491
492 if ( count( $settings ) >= $limit ) {
493 break;
494 }
495 }
496
497 if ( 1 === $limit ) {
498 $settings = reset( $settings );
499 }
500
501 return $settings;
502 }
503
504 /**
505 * @since 3.04
506 * @param array $args
507 * @param string $default_status
508 */
509 protected static function prepare_get_action( &$args, $default_status = 'publish' ) {
510 if ( is_numeric( $args ) ) {
511 // for reverse compatibility. $limit was changed to $args
512 $args = array(
513 'limit' => $args,
514 );
515 }
516 $defaults = array(
517 'limit' => 99,
518 'post_status' => $default_status,
519 );
520 $args = wp_parse_args( $args, $defaults );
521 }
522
523 /**
524 * @param int $action_id
525 */
526 public static function get_single_action_type( $action_id, $type ) {
527 if ( ! $type ) {
528 return false;
529 }
530 $action_control = FrmFormActionsController::get_form_actions( $type );
531
532 return $action_control->get_single_action( $action_id );
533 }
534
535 /**
536 * @param int $form_id
537 *
538 * @return bool
539 */
540 public static function form_has_action_type( $form_id, $type ) {
541 $payment_actions = self::get_action_for_form( $form_id, $type );
542
543 return ! empty( $payment_actions );
544 }
545
546 public function get_all( $form_id = false, $atts = array() ) {
547 self::prepare_get_action( $atts, 'any' );
548 $limit = $atts['limit'];
549
550 if ( $form_id ) {
551 $this->form_id = $form_id;
552 }
553
554 $type = $this->id_base;
555
556 global $frm_vars;
557 $frm_vars['action_type'] = $type;
558
559 add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
560 $query = self::action_args( $form_id, $limit );
561 $query['post_status'] = $atts['post_status'];
562 $query['suppress_filters'] = false;
563
564 $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
565 unset( $query );
566
567 remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
568
569 if ( empty( $actions ) ) {
570 return array();
571 }
572
573 $settings = array();
574 foreach ( $actions as $action ) {
575 if ( count( $settings ) >= $limit ) {
576 continue;
577 }
578
579 $action = $this->prepare_action( $action );
580
581 $settings[ $action->ID ] = $action;
582 }
583
584 if ( 1 === $limit ) {
585 $settings = reset( $settings );
586 }
587
588 return $settings;
589 }
590
591 public static function action_args( $form_id = 0, $limit = 99 ) {
592 $args = array(
593 'post_type' => FrmFormActionsController::$action_post_type,
594 'post_status' => 'publish',
595 'numberposts' => $limit,
596 'orderby' => 'title',
597 'order' => 'ASC',
598 );
599
600 if ( $form_id && $form_id != 'all' ) {
601 $args['menu_order'] = $form_id;
602 }
603
604 return $args;
605 }
606
607 public function prepare_action( $action ) {
608 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
609 $action->post_excerpt = sanitize_title( $action->post_excerpt );
610
611 $default_values = $this->get_global_defaults();
612
613 // fill default values
614 $action->post_content += $default_values;
615
616 foreach ( $default_values as $k => $vals ) {
617 if ( is_array( $vals ) && ! empty( $vals ) ) {
618 if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
619 continue;
620 }
621 $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
622 }
623 }
624
625 if ( ! is_array( $action->post_content['event'] ) ) {
626 $action->post_content['event'] = explode( ',', $action->post_content['event'] );
627 }
628
629 return $action;
630 }
631
632 public function destroy( $form_id = false, $type = 'default' ) {
633 global $wpdb;
634
635 $this->form_id = $form_id;
636
637 $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
638 if ( $form_id ) {
639 $query['menu_order'] = $form_id;
640 }
641 if ( 'all' != $type ) {
642 $query['post_excerpt'] = $this->id_base;
643 }
644
645 $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
646
647 foreach ( $post_ids as $id ) {
648 wp_delete_post( $id );
649 }
650 self::clear_cache();
651 }
652
653 /**
654 * Delete the action cache when a form action is created, deleted, or updated
655 *
656 * @since 2.0.5
657 */
658 public static function clear_cache() {
659 FrmDb::cache_delete_group( 'frm_actions' );
660 }
661
662 public function get_settings() {
663 return self::get_action_for_form( $this->form_id, $this->id_base );
664 }
665
666 public function get_global_defaults() {
667 $defaults = $this->get_defaults();
668
669 if ( ! isset( $defaults['event'] ) ) {
670 $defaults['event'] = array( 'create' );
671 }
672
673 if ( ! isset( $defaults['conditions'] ) ) {
674 $defaults['conditions'] = array(
675 'send_stop' => '',
676 'any_all' => '',
677 );
678 }
679
680 return $defaults;
681 }
682
683 public function get_global_switch_fields() {
684 $switch = $this->get_switch_fields();
685 $switch['conditions'] = array( 'hide_field' );
686
687 $switch = apply_filters( 'frm_global_switch_fields', $switch );
688
689 return $switch;
690 }
691
692 /**
693 * Migrate settings from form->options into new action.
694 */
695 public function migrate_to_2( $form, $update = 'update' ) {
696 $action = $this->prepare_new( $form->id );
697 FrmAppHelper::unserialize_or_decode( $form->options );
698
699 // fill with existing options
700 foreach ( $action->post_content as $name => $val ) {
701 if ( isset( $form->options[ $name ] ) ) {
702 $action->post_content[ $name ] = $form->options[ $name ];
703 unset( $form->options[ $name ] );
704 }
705 }
706
707 $action = $this->migrate_values( $action, $form );
708
709 // check if action already exists
710 $post_id = get_posts(
711 array(
712 'name' => $action->post_name,
713 'post_type' => FrmFormActionsController::$action_post_type,
714 'post_status' => $action->post_status,
715 'numberposts' => 1,
716 )
717 );
718
719 if ( empty( $post_id ) ) {
720 // create action now
721 $post_id = $this->save_settings( $action );
722 }
723
724 if ( $post_id && 'update' == $update ) {
725 global $wpdb;
726 $form->options = maybe_serialize( $form->options );
727
728 // update form options
729 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
730 FrmForm::clear_form_cache();
731 }
732
733 return $post_id;
734 }
735
736 public static function action_conditions_met( $action, $entry ) {
737 if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
738 return FrmProFormActionsController::action_conditions_met( $action, $entry );
739 }
740
741 // This is here for reverse compatibility.
742 $notification = $action->post_content;
743 $stop = false;
744 $met = array();
745
746 if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
747 return $stop;
748 }
749
750 foreach ( $notification['conditions'] as $k => $condition ) {
751 if ( ! is_numeric( $k ) ) {
752 continue;
753 }
754
755 if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
756 continue;
757 }
758
759 self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
760
761 $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
762
763 $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
764
765 if ( $notification['conditions']['send_stop'] == 'send' ) {
766 $stop = $stop ? false : true;
767 }
768
769 $met[ $stop ] = $stop;
770 }
771
772 if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
773 $stop = ( $notification['conditions']['send_stop'] == 'send' );
774 } elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
775 $stop = false;
776 }
777
778 return $stop;
779 }
780
781 /**
782 * Prepare the logic value for comparison against the entered value
783 *
784 * @since 2.01.02
785 * @deprecated 4.06.02
786 *
787 * @param array|string $logic_value
788 */
789 private static function prepare_logic_value( &$logic_value, $action, $entry ) {
790 if ( is_array( $logic_value ) ) {
791 $logic_value = reset( $logic_value );
792 }
793
794 if ( $logic_value == 'current_user' ) {
795 $logic_value = get_current_user_id();
796 }
797
798 $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
799
800 /**
801 * @since 4.04.05
802 */
803 $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
804 }
805
806 /**
807 * Get the value from a specific field and entry
808 *
809 * @since 2.01.02
810 * @deprecated 4.06.02
811 *
812 * @param object $entry
813 * @param int $field_id
814 *
815 * @return array|bool|mixed|string
816 */
817 private static function get_value_from_entry( $entry, $field_id ) {
818 $observed_value = '';
819
820 if ( isset( $entry->metas[ $field_id ] ) ) {
821 $observed_value = $entry->metas[ $field_id ];
822 } elseif ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
823 $field = FrmField::getOne( $field_id );
824 $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value(
825 $entry,
826 $field,
827 array(
828 'links' => false,
829 'truncate' => false,
830 )
831 );
832 }
833
834 return $observed_value;
835 }
836
837 public static function default_action_opts( $class = '' ) {
838 return array(
839 'classes' => 'frm_icon_font ' . $class,
840 'active' => false,
841 'limit' => 0,
842 );
843 }
844
845 public static function trigger_labels() {
846 $triggers = array(
847 'draft' => __( 'Draft is saved', 'formidable' ),
848 'create' => __( 'Entry is created', 'formidable' ),
849 'update' => __( 'Entry is updated', 'formidable' ),
850 'delete' => __( 'Entry is deleted', 'formidable' ),
851 'import' => __( 'Entry is imported', 'formidable' ),
852 );
853
854 return apply_filters( 'frm_action_triggers', $triggers );
855 }
856
857 public function render_conditional_logic_call_to_action() {
858 ?>
859 <h3>
860 <a href="javascript:void(0)" class="frm_show_upgrade frm_noallow" data-upgrade="<?php echo esc_attr( $this->get_upgrade_text() ); ?>" data-medium="conditional-<?php echo esc_attr( $this->id_base ); ?>">
861 <?php esc_html_e( 'Use Conditional Logic', 'formidable' ); ?>
862 </a>
863 </h3>
864 <?php
865 }
866
867 protected function get_upgrade_text() {
868 return __( 'Conditional form actions', 'formidable' );
869 }
870 }
871