PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.4
JetFormBuilder — Dynamic Blocks Form Builder v2.1.4
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 3 years ago post-modifier.php 3 years ago
post-modifier-core.php
114 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 public $global_status = false;
18
19
20 /**
21 * @param bool $suppress
22 *
23 * @return $this
24 */
25 public function suppress_filters( bool $suppress ) {
26 $this->suppress_filters = $suppress;
27
28 return $this;
29 }
30
31 public function get_action() {
32 if ( is_null( $this->action ) ) {
33 $this->action = 'insert';
34 }
35
36 return parent::get_action();
37 }
38
39 /**
40 * @param $post_type
41 *
42 * @return Post_Modifier_Core
43 * @throws Action_Exception
44 */
45 public function set_post_type( $post_type ): Post_Modifier_Core {
46 if ( $post_type && post_type_exists( $post_type ) ) {
47 $this->source_arr['post_type'] = $post_type;
48
49 return $this;
50 }
51
52 throw new Action_Exception(
53 'failed',
54 array(
55 'post_type' => $post_type,
56 )
57 );
58 }
59
60 /**
61 * @param string $action
62 *
63 * @return Post_Modifier_Core
64 * @throws Silence_Exception
65 */
66 public function set_action_once( string $action ) {
67 if ( 'insert' !== $this->get_action() ) {
68 return $this;
69 }
70
71 return $this->set_action( $action );
72 }
73
74 public function set_meta( $meta ) {
75 if ( empty( $this->source_arr['meta_input'] ) || ! is_array( $this->source_arr['meta_input'] ) ) {
76 $this->source_arr['meta_input'] = array();
77 }
78
79 foreach ( $meta as $meta_key => $meta_row ) {
80 if ( ! empty( $meta_row['key'] ) ) {
81 $meta[ $meta_row['key'] ] = $meta_row['value'];
82 unset( $meta[ $meta_key ] );
83 }
84 }
85
86 $this->source_arr['meta_input'] = array_merge( $this->source_arr['meta_input'], $meta );
87
88 return $this;
89 }
90
91
92
93 /**
94 * @throws Silence_Exception
95 */
96 public function pre_check() {
97 if ( $this->suppress_filters ) {
98 return;
99 }
100
101 $pre_post_check = apply_filters(
102 'jet-form-builder/action/insert-post/pre-check',
103 true,
104 $this->source_arr,
105 jet_form_builder()->form_handler->action_handler->get_current_action()
106 );
107
108 if ( ! $pre_post_check ) {
109 throw new Silence_Exception( 'Pre check filter has returned FALSE.' );
110 }
111 }
112
113
114 }