PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.0.3
JetFormBuilder — Dynamic Blocks Form Builder v2.0.3
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / actions / methods / post-modification / post-modifier-core.php
jetformbuilder / includes / actions / methods / post-modification Last commit date
post-modifier-core.php 4 years ago post-modifier.php 4 years ago
post-modifier-core.php
113 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Actions\Methods\Post_Modification;
5
6
7 use Jet_Form_Builder\Actions\Methods\Abstract_Modifier;
8 use Jet_Form_Builder\Exceptions\Action_Exception;
9 use Jet_Form_Builder\Exceptions\Silence_Exception;
10
11 abstract class Post_Modifier_Core extends Abstract_Modifier {
12
13 /** @var int|\WP_Error */
14 public $inserted_post_id;
15
16 public $suppress_filters = true;
17
18
19 /**
20 * @param bool $suppress
21 *
22 * @return $this
23 */
24 public function suppress_filters( bool $suppress ) {
25 $this->suppress_filters = $suppress;
26
27 return $this;
28 }
29
30 public function get_action() {
31 if ( is_null( $this->action ) ) {
32 $this->action = 'insert';
33 }
34
35 return parent::get_action();
36 }
37
38 /**
39 * @param $post_type
40 *
41 * @return Post_Modifier_Core
42 * @throws Action_Exception
43 */
44 public function set_post_type( $post_type ) {
45 if ( $post_type && post_type_exists( $post_type ) ) {
46 $this->source_arr['post_type'] = $post_type;
47
48 return $this;
49 }
50
51 throw new Action_Exception(
52 'failed',
53 array(
54 'post_type' => $post_type,
55 )
56 );
57 }
58
59 /**
60 * @param string $action
61 *
62 * @return Post_Modifier_Core
63 * @throws Silence_Exception
64 */
65 public function set_action_once( string $action ) {
66 if ( 'insert' !== $this->get_action() ) {
67 return $this;
68 }
69
70 return $this->set_action( $action );
71 }
72
73 public function set_meta( $meta ) {
74 if ( empty( $this->source_arr['meta_input'] ) || ! is_array( $this->source_arr['meta_input'] ) ) {
75 $this->source_arr['meta_input'] = array();
76 }
77
78 foreach ( $meta as $meta_key => $meta_row ) {
79 if ( ! empty( $meta_row['key'] ) ) {
80 $meta[ $meta_row['key'] ] = $meta_row['value'];
81 unset( $meta[ $meta_key ] );
82 }
83 }
84
85 $this->source_arr['meta_input'] = array_merge( $this->source_arr['meta_input'], $meta );
86
87 return $this;
88 }
89
90
91
92 /**
93 * @throws Silence_Exception
94 */
95 public function pre_check() {
96 if ( $this->suppress_filters ) {
97 return;
98 }
99
100 $pre_post_check = apply_filters(
101 'jet-form-builder/action/insert-post/pre-check',
102 true,
103 $this->source_arr,
104 jet_form_builder()->form_handler->action_handler->get_current_action()
105 );
106
107 if ( ! $pre_post_check ) {
108 throw new Silence_Exception( 'Pre check filter has returned FALSE.' );
109 }
110 }
111
112
113 }