PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.2.6
JetFormBuilder — Dynamic Blocks Form Builder v1.2.6
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 / presets / sources / preset-source-post.php
jetformbuilder / includes / presets / sources Last commit date
base-source.php 4 years ago preset-source-post.php 4 years ago preset-source-query-var.php 4 years ago preset-source-user.php 4 years ago
preset-source-post.php
170 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Presets\Sources;
5
6
7 class Preset_Source_Post extends Base_Source {
8
9 private $array_allowed;
10
11 public function get_id() {
12 return 'post';
13 }
14
15 public function after_init() {
16 $this->set_array_allowed();
17 }
18
19 private function set_array_allowed() {
20 if ( isset( $this->field_args['type'] ) ) {
21 $this->array_allowed = 'checkbox-field' === $this->field_args['type'];
22 }
23 }
24
25 public function on_sanitize() {
26 if ( ! is_user_logged_in() ) {
27 return false;
28 }
29
30 if ( absint( $this->src()->post_author ) !== get_current_user_id() && ! current_user_can( 'edit_others_posts' ) ) {
31 return false;
32 }
33
34 return true;
35 }
36
37 public function query_source() {
38 $post_from = ! empty( $this->preset_data['post_from'] ) ? $this->preset_data['post_from'] : 'current_post';
39
40 if ( 'current_post' === $post_from ) {
41 $post_id = get_the_ID();
42 } else {
43 $var = ! empty( $this->preset_data['query_var'] ) ? $this->preset_data['query_var'] : '';
44 $post_id = ( $var && isset( $_REQUEST[ $var ] ) ) ? $_REQUEST[ $var ] : false;
45 }
46
47 if ( $post_id ) {
48 return get_post( $post_id );
49 }
50 }
51
52
53 protected function can_get_preset() {
54 return ( parent::can_get_preset() &&
55 (
56 absint( $this->src()->post_author ) === get_current_user_id()
57 || current_user_can( 'edit_others_posts' )
58 )
59 );
60 }
61
62 public function _source__post_meta() {
63 if ( empty( $this->field_data['key'] ) ) {
64 return self::EMPTY;
65 }
66
67 $value = get_post_meta( $this->src()->ID, $this->field_data['key'], true );
68
69 if ( $this->is_repeater_val( $value ) ) {
70
71 $prepared_value = array();
72
73 foreach ( $value as $index => $row ) {
74
75 $prepared_row = array();
76
77 foreach ( $row as $item_key => $item_value ) {
78
79 $item_key = $this->get_key_from_map( $item_key );
80
81 $prepared_row[ $item_key ] = $item_value;
82 }
83
84 $prepared_value[] = $prepared_row;
85
86 }
87 $value = $prepared_value;
88 } else if ( function_exists( 'jet_engine' )
89 && jet_engine()->relations
90 && jet_engine()->relations->is_relation_key( $this->field_data['key'] ) ) {
91
92 $info = jet_engine()->relations->get_relation_info( $this->field_data['key'] );
93
94 if ( ! $info ) {
95 return self::EMPTY;
96 }
97
98 $args = array(
99 'post_id' => $this->src()->ID,
100 'post_type_1' => $info['post_type_1'],
101 'post_type_2' => $info['post_type_2'],
102 );
103
104 if ( $this->src()->post_type === $info['post_type_1'] ) {
105 $args['from'] = $info['post_type_2'];
106 } else {
107 $args['from'] = $info['post_type_1'];
108 }
109
110 $value = jet_engine()->relations->get_related_posts( $args );
111
112 }
113
114 return $value;
115 }
116
117 public function _source__post_terms() {
118 if ( empty( $this->field_data['key'] ) ) {
119 return self::EMPTY;
120 }
121
122 $value = wp_get_post_terms( $this->src()->ID, $this->field_data['key'] );
123
124 if ( empty( $value ) || is_wp_error( $value ) ) {
125 return '';
126 } else {
127 if ( $this->array_allowed ) {
128 $value = array_map( function ( $term ) {
129 return strval( $term->term_id );
130 }, $value );
131 } else {
132 $value = $value[0];
133 $value = $value->term_id;
134 }
135 }
136
137 return $value;
138 }
139
140 public function _source__post_thumb() {
141 return get_post_thumbnail_id( $this->src()->ID );
142 }
143
144 public function is_repeater_val( $value ) {
145 if ( is_array( $value ) && ! empty( $value ) ) {
146 $value = array_values( $value );
147
148 return is_array( $value[0] );
149 } else {
150 return false;
151 }
152 }
153
154 public function get_key_from_map( $repeater_key ) {
155
156 foreach ( $this->fields_map as $field => $data ) {
157
158 if ( 'post_meta' === $this->prop
159 && ! empty( $this->preset_data['key'] )
160 && $repeater_key == $this->preset_data['key'] ) {
161 return $field;
162 }
163
164 }
165
166 return $repeater_key;
167 }
168
169
170 }