Completed
Push — master ( fae5f1...b2850e )
by Stephanie
03:05
created

FrmFormAction::maybe_update_status()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
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 ) {
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 ) {
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 ];
283
 		} else {
284
 			return;
285
 		}
286
287
        $action_ids = array();
288
289
 		foreach ( $settings as $number => $new_instance ) {
290
 			$this->_set( $number );
291
292
			$old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
293
294
			if ( ! isset( $new_instance['post_status'] ) ) {
295
				$new_instance['post_status'] = 'draft';
296
			}
297
298
			// settings were never opened, so don't update
299
 			if ( ! isset( $new_instance['post_title'] ) ) {
300
				$this->maybe_update_status( $new_instance, $old_instance );
301
 			    $action_ids[] = $new_instance['ID'];
302
         		$this->updated = true;
303
         		continue;
304
 			}
305
306
			$new_instance['post_type']  = FrmFormActionsController::$action_post_type;
307
			$new_instance['post_name']  = $this->form_id . '_' . $this->id_base . '_' . $this->number;
308
			$new_instance['menu_order'] = $this->form_id;
309
			$new_instance['post_date']  = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
310
311
 			$instance = $this->update( $new_instance, $old_instance );
312
313
			/**
314
			 * Filter an action's settings before saving.
315
			 *
316
			 * Returning false will effectively short-circuit the widget's ability
317
			 * to update settings.
318
			 *
319
			 * @since 2.0
320
			 *
321
			 * @param array     $instance     The current widget instance's settings.
322
			 * @param array     $new_instance Array of new widget settings.
323
			 * @param array     $old_instance Array of old widget settings.
324
			 * @param WP_Widget $this         The current widget instance.
325
			 */
326
			$instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
327
328
			$instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
329
			$instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this );
330
331
			if ( false !== $instance ) {
332
				$all_instances[ $number ] = $instance;
333
			}
334
335
			$action_ids[] = $this->save_settings( $instance );
336
337
     		$this->updated = true;
338
 		}
339
340
 		return $action_ids;
341
 	}
342
343
	/**
344
	 * If the status of the action has changed, update it
345
	 *
346
	 * @since 3.04
347
	 */
348
	protected function maybe_update_status( $new_instance, $old_instance ) {
349
		if ( $new_instance['post_status'] !== $old_instance->post_status ) {
350
			self::clear_cache();
351
			wp_update_post(
352
				array(
353
					'ID'          =>  $new_instance['ID'],
0 ignored issues
show
introduced by
Expected 1 space after "=>"; 2 found
Loading history...
354
					'post_status' =>  $new_instance['post_status'],
0 ignored issues
show
introduced by
Expected 1 space after "=>"; 2 found
Loading history...
355
				)
356
			);
357
		}
358
	}
359
360
	public function save_settings( $settings ) {
361
		self::clear_cache();
362
		return FrmDb::save_settings( $settings, 'frm_actions' );
363
	}
364
365
	public function get_single_action( $id ) {
366
		$action = get_post( $id );
367
		if ( $action ) {
368
			$action = $this->prepare_action( $action );
369
			$this->_set( $id );
370
		}
371
	    return $action;
372
	}
373
374
	public function get_one( $form_id ) {
375
		return $this->get_all( $form_id, 1 );
376
	}
377
378
    public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
379
        $action_controls = FrmFormActionsController::get_form_actions( $type );
380
		if ( empty( $action_controls ) ) {
381
            // don't continue if there are no available actions
382
            return array();
383
        }
384
385
		self::prepare_get_action( $atts );
386
387
		$limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
388
389
        if ( 'all' != $type ) {
390
            return $action_controls->get_all( $form_id, $limit );
391
        }
392
393
		$args = self::action_args( $form_id, $limit );
394
		$args['post_status'] = $atts['post_status'];
395
		$actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
396
397
        if ( ! $actions ) {
398
            return array();
399
        }
400
401
        $settings = array();
402
        foreach ( $actions as $action ) {
403
			// some plugins/themes are formatting the post_excerpt
404
			$action->post_excerpt = sanitize_title( $action->post_excerpt );
405
406
			if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
407
                continue;
408
            }
409
410
            $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
411
			$settings[ $action->ID ] = $action;
412
413
			if ( count( $settings ) >= $limit ) {
414
				break;
415
			}
416
        }
417
418
        if ( 1 === $limit ) {
419
			$settings = reset( $settings );
420
        }
421
422
        return $settings;
423
    }
424
425
	/**
426
	 * @since 3.04
427
	 */
428
	protected static function prepare_get_action( &$args ) {
429
		if ( is_numeric( $args ) ) {
430
			// for reverse compatibility. $limit was changed to $args
431
			$args = array(
432
				'limit' => $args,
433
			);
434
		}
435
		$defaults = array(
436
			'limit'       => 99,
437
			'post_status' => 'publish',
438
		);
439
		$args = wp_parse_args( $args, $defaults );
440
	}
441
442
	/**
443
	 * @param int $action_id
444
	 */
445
	public static function get_single_action_type( $action_id, $type ) {
446
		if ( ! $type ) {
447
			return false;
448
		}
449
		$action_control = FrmFormActionsController::get_form_actions( $type );
450
		return $action_control->get_single_action( $action_id );
451
	}
452
453
	/**
454
	 * @param int $form_id
455
	 * @return bool
456
	 */
457
	public static function form_has_action_type( $form_id, $type ) {
458
		$payment_actions = self::get_action_for_form( $form_id, $type );
459
		return ! empty( $payment_actions );
460
	}
461
462
	public function get_all( $form_id = false, $limit = 99 ) {
463
	    if ( $form_id ) {
464
	        $this->form_id = $form_id;
465
	    }
466
467
	    $type = $this->id_base;
468
469
	    global $frm_vars;
470
	    $frm_vars['action_type'] = $type;
471
472
		add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
473
		$query = self::action_args( $form_id, $limit );
474
        $query['post_status']      = 'any';
475
        $query['suppress_filters'] = false;
476
477
		$actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
478
		unset( $query );
479
480
		remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
481
482
		if ( empty( $actions ) ) {
483
            return array();
484
        }
485
486
        $settings = array();
487
        foreach ( $actions as $action ) {
488
			if ( count( $settings ) >= $limit ) {
489
                continue;
490
            }
491
492
			$action = $this->prepare_action( $action );
493
494
			$settings[ $action->ID ] = $action;
495
        }
496
497
        if ( 1 === $limit ) {
498
			$settings = reset( $settings );
499
        }
500
501
        return $settings;
502
	}
503
504
	public static function action_args( $form_id = 0, $limit = 99 ) {
505
		$args = array(
506
			'post_type'   => FrmFormActionsController::$action_post_type,
507
			'post_status' => 'publish',
508
			'numberposts' => $limit,
509
			'orderby'     => 'title',
510
			'order'       => 'ASC',
511
		);
512
513
		if ( $form_id && $form_id != 'all' ) {
514
			$args['menu_order'] = $form_id;
515
		}
516
517
		return $args;
518
	}
519
520
	public function prepare_action( $action ) {
521
		$action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
522
		$action->post_excerpt = sanitize_title( $action->post_excerpt );
523
524
        $default_values = $this->get_global_defaults();
525
526
        // fill default values
527
        $action->post_content += $default_values;
528
529
        foreach ( $default_values as $k => $vals ) {
530
			if ( is_array( $vals ) && ! empty( $vals ) ) {
531
				if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
532
                    continue;
533
                }
534
				$action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
535
            }
536
        }
537
538
		if ( ! is_array( $action->post_content['event'] ) ) {
539
			$action->post_content['event'] = explode( ',', $action->post_content['event'] );
540
		}
541
542
        return $action;
543
	}
544
545
	public function destroy( $form_id = false, $type = 'default' ) {
546
	    global $wpdb;
547
548
	    $this->form_id = $form_id;
549
550
	    $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
551
	    if ( $form_id ) {
552
	        $query['menu_order'] = $form_id;
553
	    }
554
	    if ( 'all' != $type ) {
555
	        $query['post_excerpt'] = $this->id_base;
556
	    }
557
558
        $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
559
560
        foreach ( $post_ids as $id ) {
0 ignored issues
show
Bug introduced by
The expression $post_ids of type array|null|string|object is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
561
			wp_delete_post( $id );
562
        }
563
		self::clear_cache();
564
	}
565
566
	/**
567
	 * Delete the action cache when a form action is created, deleted, or updated
568
	 *
569
	 * @since 2.0.5
570
	 */
571
	public static function clear_cache() {
572
		FrmDb::cache_delete_group( 'frm_actions' );
573
	}
574
575
	public function get_settings() {
576
		return self::get_action_for_form( $this->form_id, $this->id_base );
577
	}
578
579
	public function get_global_defaults() {
580
	    $defaults = $this->get_defaults();
581
582
		if ( ! isset( $defaults['event'] ) ) {
583
			$defaults['event'] = array( 'create' );
584
	    }
585
586
		if ( ! isset( $defaults['conditions'] ) ) {
587
	        $defaults['conditions'] = array(
588
                'send_stop' => '',
589
                'any_all'   => '',
590
            );
591
        }
592
593
        return $defaults;
594
	}
595
596
	public function get_global_switch_fields() {
597
	    $switch = $this->get_switch_fields();
598
		$switch['conditions'] = array( 'hide_field' );
599
	    return $switch;
600
	}
601
602
	/**
603
	 * Migrate settings from form->options into new action.
604
	 */
605
	public function migrate_to_2( $form, $update = 'update' ) {
606
		$action = $this->prepare_new( $form->id );
607
		$form->options = maybe_unserialize( $form->options );
608
609
        // fill with existing options
610
        foreach ( $action->post_content as $name => $val ) {
611
			if ( isset( $form->options[ $name ] ) ) {
612
				$action->post_content[ $name ] = $form->options[ $name ];
613
				unset( $form->options[ $name ] );
614
            }
615
        }
616
617
		$action = $this->migrate_values( $action, $form );
618
619
        // check if action already exists
620
		$post_id = get_posts(
621
			array(
622
				'name'          => $action->post_name,
623
				'post_type'     => FrmFormActionsController::$action_post_type,
624
				'post_status'   => $action->post_status,
625
				'numberposts'   => 1,
626
			)
627
		);
628
629
		if ( empty( $post_id ) ) {
630
			// create action now
631
			$post_id = $this->save_settings( $action );
632
		}
633
634
        if ( $post_id && 'update' == $update ) {
635
            global $wpdb;
636
			$form->options = maybe_serialize( $form->options );
637
638
            // update form options
639
			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
640
	        FrmForm::clear_form_cache();
641
        }
642
643
        return $post_id;
644
    }
645
646
	public static function action_conditions_met( $action, $entry ) {
647
		$notification = $action->post_content;
648
		$stop = false;
649
		$met = array();
650
651
		if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
652
			return $stop;
653
		}
654
655
		foreach ( $notification['conditions'] as $k => $condition ) {
656
			if ( ! is_numeric( $k ) ) {
657
				continue;
658
			}
659
660
			if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
661
				continue;
662
			}
663
664
			self::prepare_logic_value( $condition['hide_opt'] );
665
666
			$observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
667
668
			$stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
669
670
			if ( $notification['conditions']['send_stop'] == 'send' ) {
671
				$stop = $stop ? false : true;
672
			}
673
674
			$met[ $stop ] = $stop;
675
		}
676
677
		if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
678
			$stop = ( $notification['conditions']['send_stop'] == 'send' );
679
		} elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
680
			$stop = false;
681
		}
682
683
		return $stop;
684
	}
685
686
	/**
687
	 * Prepare the logic value for comparison against the entered value
688
	 *
689
	 * @since 2.01.02
690
	 * @param array|string $logic_value
691
	 */
692
	private static function prepare_logic_value( &$logic_value ) {
693
		if ( is_array( $logic_value ) ) {
694
			$logic_value = reset( $logic_value );
695
		}
696
697
		if ( $logic_value == 'current_user' ) {
698
			$logic_value = get_current_user_id();
699
		}
700
	}
701
702
703
	/**
704
	 * Get the value from a specific field and entry
705
	 *
706
	 * @since 2.01.02
707
	 * @param object $entry
708
	 * @param int $field_id
709
	 * @return array|bool|mixed|string
710
	 */
711
	private static function get_value_from_entry( $entry, $field_id ) {
712
		$observed_value = '';
713
714
		if ( isset( $entry->metas[ $field_id ] ) ) {
715
			$observed_value = $entry->metas[ $field_id ];
716
		} else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
717
			$field = FrmField::getOne( $field_id );
718
			$observed_value = FrmProEntryMetaHelper::get_post_or_meta_value(
719
				$entry,
720
				$field,
721
				array(
722
					'links'    => false,
723
					'truncate' => false,
724
				)
725
			);
726
		}
727
728
		return $observed_value;
729
	}
730
731
	public static function default_action_opts( $class = '' ) {
732
		return array(
733
			'classes'   => 'frm_icon_font ' . $class,
734
			'active'    => false,
735
			'limit'     => 0,
736
		);
737
	}
738
739
	public static function trigger_labels() {
740
		$triggers = array(
741
			'draft'  => __( 'Save Draft', 'formidable' ),
742
			'create' => __( 'Create', 'formidable' ),
743
			'update' => __( 'Update', 'formidable' ),
744
			'delete' => __( 'Delete', 'formidable' ),
745
			'import' => __( 'Import', 'formidable' ),
746
		);
747
		return apply_filters( 'frm_action_triggers', $triggers );
748
	}
749
}
750