Completed
Push — master ( ab0612...d38262 )
by Jamie
03:40
created

FrmFormAction::prepare_logic_value()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 11
rs 9.4285
1
<?php
2
3
class FrmFormAction {
4
5
	public $id_base;			// Root id for all actions of this type.
6
	public $name;				// Name for this action type.
7
	public $option_name;
8
	public $action_options;     // Option array passed to wp_register_sidebar_widget()
9
	public $control_options;	// Option array passed to wp_register_widget_control()
10
11
    public $form_id;        // The ID of the form to evaluate
12
	public $number = false;	// Unique ID number of the current instance.
13
	public $id = '';		// Unique ID string of the current instance (id_base-number)
14
	public $updated = false;	// Set true when we update the data after a POST submit - makes sure we don't do it twice.
15
16
	// Member functions that you must over-ride.
17
18
	/**
19
	 * This function should check that $new_instance is set correctly.
20
	 * The newly calculated value of $instance should be returned.
21
	 * If "false" is returned, the instance won't be saved/updated.
22
	 *
23
	 * @param array $new_instance New settings for this instance as input by the user via form()
24
	 * @param array $old_instance Old settings for this instance
25
	 * @return array Settings to save or bool false to cancel saving
26
	 */
27
	public function update( $new_instance, $old_instance ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old_instance is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
		return $new_instance;
29
	}
30
31
	/**
32
     * Echo the settings update form
33
	 *
34
	 * @param array $instance Current settings
35
	 */
36
	public function form( $instance, $args = array() ) {
37
		echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
38
		return 'noform';
39
	}
40
41
	/**
42
	 * @return array of the default options
43
	 */
44
	public function get_defaults() {
45
	    return array();
46
	}
47
48
	public function get_switch_fields() {
49
	    return array();
50
	}
51
52
	public function migrate_values( $action, $form ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
	    return $action;
54
	}
55
56
	// Functions you'll need to call.
57
58
	/**
59
	 * PHP5 constructor
60
	 *
61
	 * @param string $id_base Optional Base ID for the widget, lower case,
62
	 * if left empty a portion of the widget's class name will be used. Has to be unique.
63
	 * @param string $name Name for the widget displayed on the configuration page.
64
	 * @param array $action_options Optional Passed to wp_register_sidebar_widget()
65
	 *	 - description: shown on the configuration page
66
	 *	 - classname
67
	 * @param array $control_options Optional Passed to wp_register_widget_control()
68
	 *	 - width: required if more than 250px
69
	 *	 - height: currently not used but may be needed in the future
70
	 */
71
	public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
72
	    if ( ! defined('ABSPATH') ) {
73
            die('You are not allowed to call this page directly.');
74
        }
75
76
		$this->id_base = strtolower($id_base);
77
		$this->name = $name;
78
		$this->option_name = 'frm_' . $this->id_base . '_action';
79
80
        $default_options = array(
81
            'classes'   => '',
82
            'active'    => true,
83
			'event'     => array( 'create' ),
84
            'limit'     => 1,
85
            'force_event' => false,
86
            'priority'  => 20,
87
            'ajax_load' => true,
88
            'tooltip'   => $name,
89
        );
90
91
		$action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
92
		$this->action_options = wp_parse_args( $action_options, $default_options );
93
		$this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
94
	}
95
96
	/**
97
	 * @param string $id_base
98
	 */
99
	public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) {
100
		FrmFormAction::__construct( $id_base, $name, $action_options, $control_options );
101
	}
102
103
	/**
104
	 * Constructs name attributes for use in form() fields
105
	 *
106
	 * This function should be used in form() methods to create name attributes for fields to be saved by update()
107
	 *
108
	 * @param string $field_name Field name
109
	 * @return string Name attribute for $field_name
110
	 */
111
	public function get_field_name( $field_name, $post_field = 'post_content' ) {
112
		$name = $this->option_name . '[' . $this->number . ']';
113
		$name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
114
		$name .= '[' . $field_name . ']';
115
		return $name;
116
	}
117
118
	/**
119
	 * Constructs id attributes for use in form() fields
120
	 *
121
	 * This function should be used in form() methods to create id attributes for fields to be saved by update()
122
	 *
123
	 * @param string $field_name Field name
124
	 * @return string ID attribute for $field_name
125
	 */
126
	public function get_field_id( $field_name ) {
127
		return $field_name . '_' . $this->number;
128
	}
129
130
	// Private Function. Don't worry about this.
131
132
	public function _set( $number ) {
133
		$this->number = $number;
134
		$this->id = $this->id_base . '-' . $number;
135
	}
136
137
	public function prepare_new( $form_id = false ) {
138
        if ( $form_id ) {
139
            $this->form_id = $form_id;
140
        }
141
142
        $post_content = array();
143
        $default_values = $this->get_global_defaults();
144
145
        // fill default values
146
        $post_content = wp_parse_args( $post_content, $default_values);
147
148
        if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
149
            $post_content['event'] = array( reset($this->action_options['event']) );
150
        }
151
152
        $form_action = array(
153
            'post_title'    => $this->name,
154
            'post_content'  => $post_content,
155
            'post_excerpt'  => $this->id_base,
156
            'ID'            => '',
157
            'post_status'   => 'publish',
158
            'post_type'     => FrmFormActionsController::$action_post_type,
159
			'post_name'     => $this->form_id . '_' . $this->id_base . '_' . $this->number,
160
            'menu_order'    => $this->form_id,
161
        );
162
        unset($post_content);
163
164
        return (object) $form_action;
165
    }
166
167
	public function create( $form_id ) {
168
        $this->form_id = $form_id;
169
170
        $action = $this->prepare_new();
171
172
        return $this->save_settings($action);
173
    }
174
175
	public function duplicate_form_actions( $form_id, $old_id ) {
176
        if ( $form_id == $old_id ) {
177
            // don't duplicate the actions if this is a template getting updated
178
            return;
179
        }
180
181
        $this->form_id = $old_id;
182
        $actions = $this->get_all( $old_id );
183
184
        $this->form_id = $form_id;
185
        foreach ( $actions as $action ) {
186
            $this->duplicate_one($action, $form_id);
187
            unset($action);
188
        }
189
    }
190
191
    /* Check if imported action should be created or updated
192
    *
193
    * Since 2.0
194
    *
195
    * @param array $action
196
    * @return integer $post_id
197
    */
198
    public function maybe_create_action( $action, $forms ) {
199
		if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
200
            // Update action only
201
            $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
202
            $post_id = $this->save_settings( $action );
203
        } else {
204
            // Create action
205
            $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
206
            $post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
207
        }
208
        return $post_id;
209
    }
210
211
	public function duplicate_one( $action, $form_id ) {
212
        global $frm_duplicate_ids;
213
214
        $action->menu_order = $form_id;
215
        $switch = $this->get_global_switch_fields();
216
        foreach ( (array) $action->post_content as $key => $val ) {
217
			if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
218
				$action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
219
            } else if ( ! is_array( $val ) ) {
220
				$action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
221
			} else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
222
                // loop through each value if empty
223
				if ( empty( $switch[ $key ] ) ) {
224
					$switch[ $key ] = array_keys( $val );
225
				}
226
227
				foreach ( $switch[ $key ] as $subkey ) {
228
					$action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
229
                }
230
            }
231
232
            unset($key, $val);
233
        }
234
        unset($action->ID);
235
236
        return $this->save_settings($action);
237
    }
238
239
	private function duplicate_array_walk( $action, $subkey, $val ) {
240
        global $frm_duplicate_ids;
241
242
        if ( is_array($subkey) ) {
243
            foreach ( $subkey as $subkey2 ) {
244
                foreach ( (array) $val as $ck => $cv ) {
245
                    if ( is_array($cv) ) {
246
						$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
247
					} else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
248
						$action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
249
                    }
250
                }
251
            }
252
        } else {
253
            foreach ( (array) $val as $ck => $cv ) {
254
                if ( is_array($cv) ) {
255
					$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
256
				} else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
257
					$action[ $ck ] = $frm_duplicate_ids[ $cv ];
258
                }
259
            }
260
        }
261
262
        return $action;
263
    }
264
265
	/**
266
	 * Deal with changed settings.
267
	 *
268
	 * Do NOT over-ride this function
269
	 *
270
	 */
271
 	public function update_callback( $form_id ) {
272
        $this->form_id = $form_id;
273
274
 		$all_instances = $this->get_settings();
275
276
 		// We need to update the data
277
 		if ( $this->updated ) {
278
 			return;
279
 		}
280
281
		if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
282
			$settings = $_POST[ $this->option_name ];
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
283
 		} else {
284
 			return;
285
 		}
286
287
        $action_ids = array();
288
289
 		foreach ( $settings as $number => $new_instance ) {
290
 			$this->_set($number);
291
292
 			if ( ! isset($new_instance['post_title']) ) {
293
 			    // settings were never opened, so don't update
294
 			    $action_ids[] = $new_instance['ID'];
295
         		$this->updated = true;
296
         		continue;
297
 			}
298
299
			$old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
300
301
 			$new_instance['post_type']  = FrmFormActionsController::$action_post_type;
302
			$new_instance['post_name']  = $this->form_id . '_' . $this->id_base . '_' . $this->number;
303
            $new_instance['menu_order']   = $this->form_id;
304
            $new_instance['post_status']  = 'publish';
305
            $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
306
307
 			$instance = $this->update( $new_instance, $old_instance );
308
309
			/**
310
			 * Filter an action's settings before saving.
311
			 *
312
			 * Returning false will effectively short-circuit the widget's ability
313
			 * to update settings.
314
			 *
315
			 * @since 2.0
316
			 *
317
			 * @param array     $instance     The current widget instance's settings.
318
			 * @param array     $new_instance Array of new widget settings.
319
			 * @param array     $old_instance Array of old widget settings.
320
			 * @param WP_Widget $this         The current widget instance.
321
			 */
322
			$instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
323
324
			$instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this);
325
			$instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this );
326
327
			if ( false !== $instance ) {
328
				$all_instances[ $number ] = $instance;
329
			}
330
331
            $action_ids[] = $this->save_settings($instance);
332
333
     		$this->updated = true;
334
 		}
335
336
 		return $action_ids;
337
 	}
338
339
	public function save_settings( $settings ) {
340
		self::clear_cache();
341
		return FrmAppHelper::save_settings( $settings, 'frm_actions' );
342
	}
343
344
	public function get_single_action( $id ) {
345
	    $action = get_post($id);
346
		if ( $action ) {
347
			$action = $this->prepare_action( $action );
348
			$this->_set( $id );
349
		}
350
	    return $action;
351
	}
352
353
	public function get_one( $form_id ) {
354
	    return $this->get_all($form_id, 1);
355
	}
356
357
    public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) {
358
        $action_controls = FrmFormActionsController::get_form_actions( $type );
359
        if ( empty($action_controls) ) {
360
            // don't continue if there are no available actions
361
            return array();
362
        }
363
364
        if ( 'all' != $type ) {
365
            return $action_controls->get_all( $form_id, $limit );
366
        }
367
368
		$args = self::action_args( $form_id, $limit );
369
		$actions = FrmAppHelper::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
0 ignored issues
show
Documentation introduced by
$args is of type array<string,string|integer>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
370
371
        if ( ! $actions ) {
372
            return array();
373
        }
374
375
        $settings = array();
376
        foreach ( $actions as $action ) {
377
			// some plugins/themes are formatting the post_excerpt
378
			$action->post_excerpt = sanitize_title( $action->post_excerpt );
379
380
			if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
381
                continue;
382
            }
383
384
            $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
385
			$settings[ $action->ID ] = $action;
386
387
			if ( count( $settings ) >= $limit ) {
388
				break;
389
			}
390
        }
391
392
        if ( 1 === $limit ) {
393
            $settings = reset($settings);
394
        }
395
396
        return $settings;
397
    }
398
399
	/**
400
	 * @param int $action_id
401
	 */
402
	public static function get_single_action_type( $action_id, $type ) {
403
		$action_control = FrmFormActionsController::get_form_actions( $type );
404
		return $action_control->get_single_action( $action_id );
405
	}
406
407
	/**
408
	 * @param int $form_id
409
	 * @return bool
410
	 */
411
	public static function form_has_action_type( $form_id, $type ) {
412
		$payment_actions = self::get_action_for_form( $form_id, $type );
413
		return ! empty( $payment_actions );
414
	}
415
416
	public function get_all( $form_id = false, $limit = 99 ) {
417
	    if ( $form_id ) {
418
	        $this->form_id = $form_id;
419
	    }
420
421
	    $type = $this->id_base;
422
423
	    global $frm_vars;
424
	    $frm_vars['action_type'] = $type;
425
426
	    add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
427
		$query = self::action_args( $form_id, $limit );
0 ignored issues
show
Documentation introduced by
$form_id is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
428
        $query['post_status']      = 'any';
429
        $query['suppress_filters'] = false;
430
431
		$actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
0 ignored issues
show
Documentation introduced by
$query is of type array<string,string|inte...ress_filters":"false"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
432
        unset($query);
433
434
        remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
435
436
        if ( empty($actions) ) {
437
            return array();
438
        }
439
440
        $settings = array();
441
        foreach ( $actions as $action ) {
442
            if ( count($settings) >= $limit ) {
443
                continue;
444
            }
445
446
            $action = $this->prepare_action($action);
447
448
			$settings[ $action->ID ] = $action;
449
        }
450
451
        if ( 1 === $limit ) {
452
            $settings = reset($settings);
453
        }
454
455
        return $settings;
456
	}
457
458
	public static function action_args( $form_id = 0, $limit = 99 ) {
459
		$args = array(
460
			'post_type'   => FrmFormActionsController::$action_post_type,
461
			'post_status' => 'publish',
462
			'numberposts' => $limit,
463
			'orderby'     => 'title',
464
			'order'       => 'ASC',
465
		);
466
467
		if ( $form_id && $form_id != 'all' ) {
468
			$args['menu_order'] = $form_id;
469
		}
470
471
		return $args;
472
	}
473
474
	public function prepare_action( $action ) {
475
		$action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content);
476
		$action->post_excerpt = sanitize_title( $action->post_excerpt );
477
478
        $default_values = $this->get_global_defaults();
479
480
        // fill default values
481
        $action->post_content += $default_values;
482
483
        foreach ( $default_values as $k => $vals ) {
484
            if ( is_array($vals) && ! empty($vals) ) {
485
				if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
486
                    continue;
487
                }
488
				$action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
489
            }
490
        }
491
492
        if ( ! is_array($action->post_content['event']) ) {
493
            $action->post_content['event'] = explode(',', $action->post_content['event']);
494
        }
495
496
        return $action;
497
	}
498
499
	public function destroy( $form_id = false, $type = 'default' ) {
500
	    global $wpdb;
501
502
	    $this->form_id = $form_id;
503
504
	    $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
505
	    if ( $form_id ) {
506
	        $query['menu_order'] = $form_id;
507
	    }
508
	    if ( 'all' != $type ) {
509
	        $query['post_excerpt'] = $this->id_base;
510
	    }
511
512
        $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
513
514
        foreach ( $post_ids as $id ) {
515
            wp_delete_post($id);
516
        }
517
		self::clear_cache();
518
	}
519
520
	/**
521
	 * Delete the action cache when a form action is created, deleted, or updated
522
	 *
523
	 * @since 2.0.5
524
	 */
525
	public static function clear_cache() {
526
		FrmAppHelper::cache_delete_group( 'frm_actions' );
527
	}
528
529
	public function get_settings() {
530
		return self::get_action_for_form( $this->form_id, $this->id_base );
531
	}
532
533
	public function get_global_defaults() {
534
	    $defaults = $this->get_defaults();
535
536
	    if ( ! isset($defaults['event']) ) {
537
			$defaults['event'] = array( 'create' );
538
	    }
539
540
	    if ( ! isset($defaults['conditions']) ) {
541
	        $defaults['conditions'] = array(
542
                'send_stop' => '',
543
                'any_all'   => '',
544
            );
545
        }
546
547
        return $defaults;
548
	}
549
550
	public function get_global_switch_fields() {
551
	    $switch = $this->get_switch_fields();
552
		$switch['conditions'] = array( 'hide_field' );
553
	    return $switch;
554
	}
555
556
	/**
557
	 * Migrate settings from form->options into new action.
558
	 */
559
	public function migrate_to_2( $form, $update = 'update' ) {
560
        $action = $this->prepare_new($form->id);
561
        $form->options = maybe_unserialize($form->options);
562
563
        // fill with existing options
564
        foreach ( $action->post_content as $name => $val ) {
565
			if ( isset( $form->options[ $name ] ) ) {
566
				$action->post_content[ $name ] = $form->options[ $name ];
567
				unset( $form->options[ $name ] );
568
            }
569
        }
570
571
        $action = $this->migrate_values($action, $form);
572
573
        // check if action already exists
574
        $post_id = get_posts( array(
575
            'name'          => $action->post_name,
576
            'post_type'     => FrmFormActionsController::$action_post_type,
577
            'post_status'   => $action->post_status,
578
            'numberposts'   => 1,
579
        ) );
580
581
        if ( empty($post_id) ) {
582
            // create action now
583
            $post_id = $this->save_settings($action);
584
        }
585
586
        if ( $post_id && 'update' == $update ) {
587
            global $wpdb;
588
            $form->options = maybe_serialize($form->options);
589
590
            // update form options
591
			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
592
            wp_cache_delete( $form->id, 'frm_form');
593
        }
594
595
        return $post_id;
596
    }
597
598
	public static function action_conditions_met( $action, $entry ) {
599
		$notification = $action->post_content;
600
		$stop = false;
601
		$met = array();
602
603
		if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
604
			return $stop;
605
		}
606
607
		foreach ( $notification['conditions'] as $k => $condition ) {
608
			if ( ! is_numeric( $k ) ) {
609
				continue;
610
			}
611
612 View Code Duplication
			if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
613
				continue;
614
			}
615
616
			self::prepare_logic_value( $condition['hide_opt'] );
617
618
			$observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
619
620
			$stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']);
621
622
			if ( $notification['conditions']['send_stop'] == 'send' ) {
623
				$stop = $stop ? false : true;
624
			}
625
626
			$met[ $stop ] = $stop;
627
		}
628
629
		if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
630
			$stop = ($notification['conditions']['send_stop'] == 'send');
631 View Code Duplication
		} else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
632
			$stop = false;
633
		}
634
635
		return $stop;
636
	}
637
638
	/**
639
	 * Prepare the logic value for comparison against the entered value
640
	 *
641
	 * @since 2.01.02
642
	 * @param array|string $logic_value
643
	 */
644
	private static function prepare_logic_value( &$logic_value ) {
645
		if ( is_array( $logic_value ) ) {
646
			$logic_value = reset( $logic_value );
647
		}
648
649
		$logic_value = wp_kses_post( $logic_value );
650
651
		if ( $logic_value == 'current_user' ) {
652
			$logic_value = get_current_user_id();
653
		}
654
	}
655
656
657
/**
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 1 tabs, found 0
Loading history...
658
	 * Get the value from a specific field and entry
659
	 *
660
	 * @since 2.01.02
661
	 * @param object $entry
662
	 * @param int $field_id
663
	 * @return array|bool|mixed|string
664
	 */
665
	private static function get_value_from_entry( $entry, $field_id ) {
666
		$observed_value = '';
667
668
		if ( isset( $entry->metas[ $field_id ] ) ) {
669
			$observed_value = $entry->metas[ $field_id ];
670
		} else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
671
			$field = FrmField::getOne( $field_id );
672
			$observed_value = FrmProEntryMetaHelper::get_post_or_meta_value( $entry, $field, array( 'links' => false, 'truncate' => false ) );
673
		}
674
675
		return $observed_value;
676
	}
677
678
	public static function default_action_opts( $class = '' ) {
679
		return array(
680
			'classes'   => 'frm_icon_font ' . $class,
681
			'active'    => false,
682
			'limit'     => 0,
683
		);
684
	}
685
686
	public static function trigger_labels() {
687
		return apply_filters( 'frm_action_triggers', array(
688
			'draft'  => __( 'Save Draft', 'formidable' ),
689
			'create' => __( 'Create', 'formidable' ),
690
			'update' => __( 'Update', 'formidable' ),
691
			'delete' => __( 'Delete', 'formidable' ),
692
			'import' => __( 'Import', 'formidable' ),
693
		) );
694
	}
695
}
696