1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package Pods |
4
|
|
|
*/ |
5
|
|
|
class PodsMeta { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @var PodsMeta |
9
|
|
|
*/ |
10
|
|
|
static $instance = null; |
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var PodsAPI |
14
|
|
|
*/ |
15
|
|
|
private $api; |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var Pods |
19
|
|
|
*/ |
20
|
|
|
private static $current_pod; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private static $current_pod_data; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Pods |
29
|
|
|
*/ |
30
|
|
|
private static $current_field_pod; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var int |
34
|
|
|
*/ |
35
|
|
|
public static $object_identifier = -1; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
public static $advanced_content_types = array(); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
public static $post_types = array(); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
public static $taxonomies = array(); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
public static $media = array(); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
public static $user = array(); |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var array |
64
|
|
|
*/ |
65
|
|
|
public static $comment = array(); |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var array |
69
|
|
|
*/ |
70
|
|
|
public static $settings = array(); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var array |
74
|
|
|
*/ |
75
|
|
|
public static $queue = array(); |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var array |
79
|
|
|
*/ |
80
|
|
|
public static $groups = array(); |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var string |
84
|
|
|
*/ |
85
|
|
|
public static $old_post_status = ''; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Singleton handling for a basic pods_meta() request |
89
|
|
|
* |
90
|
|
|
* @return \PodsMeta |
91
|
|
|
* |
92
|
|
|
* @since 2.3.5 |
93
|
|
|
*/ |
94
|
|
|
public static function init () { |
95
|
|
|
if ( !is_object( self::$instance ) ) |
96
|
|
|
self::$instance = new PodsMeta(); |
97
|
|
|
|
98
|
|
|
return self::$instance; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return \PodsMeta |
|
|
|
|
103
|
|
|
* |
104
|
|
|
* @since 2.0 |
105
|
|
|
*/ |
106
|
|
|
function __construct () { |
|
|
|
|
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return \PodsMeta |
112
|
|
|
*/ |
113
|
|
|
public function core () { |
114
|
|
|
self::$advanced_content_types = pods_api()->load_pods( array( 'type' => 'pod' ) ); |
115
|
|
|
self::$post_types = pods_api()->load_pods( array( 'type' => 'post_type' ) ); |
116
|
|
|
self::$taxonomies = pods_api()->load_pods( array( 'type' => 'taxonomy' ) ); |
117
|
|
|
self::$media = pods_api()->load_pods( array( 'type' => 'media' ) ); |
118
|
|
|
self::$user = pods_api()->load_pods( array( 'type' => 'user' ) ); |
119
|
|
|
self::$comment = pods_api()->load_pods( array( 'type' => 'comment' ) ); |
120
|
|
|
self::$settings = pods_api()->load_pods( array( 'type' => 'settings' ) ); |
121
|
|
|
|
122
|
|
|
// Handle Post Type Editor (needed for Pods core) |
123
|
|
|
|
124
|
|
|
// Loop through and add meta boxes for individual types (can't use this, Tabify doesn't pick it up) |
125
|
|
|
/* |
|
|
|
|
126
|
|
|
foreach ( self::$post_types as $post_type ) { |
127
|
|
|
$post_type_name = $post_type[ 'name' ]; |
128
|
|
|
|
129
|
|
|
if ( !empty( $post_type[ 'object' ] ) ) |
130
|
|
|
$post_type_name = $post_type[ 'object' ]; |
131
|
|
|
|
132
|
|
|
add_action( 'add_meta_boxes_' . $post_type_name, array( $this, 'meta_post_add' ) ); |
133
|
|
|
} |
134
|
|
|
*/ |
135
|
|
|
|
136
|
|
|
add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) ); |
137
|
|
|
add_action( 'transition_post_status', array( $this, 'save_post_detect_new' ), 10, 3 ); |
138
|
|
|
add_action( 'save_post', array( $this, 'save_post' ), 10, 3 ); |
139
|
|
|
|
140
|
|
View Code Duplication |
if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) { |
141
|
|
|
// Handle *_post_meta |
142
|
|
|
if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) { |
143
|
|
|
add_filter( 'get_post_metadata', array( $this, 'get_post_meta' ), 10, 4 ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
if ( !pods_tableless() ) { |
147
|
|
|
add_filter( 'add_post_metadata', array( $this, 'add_post_meta' ), 10, 5 ); |
148
|
|
|
add_filter( 'update_post_metadata', array( $this, 'update_post_meta' ), 10, 5 ); |
149
|
|
|
add_filter( 'delete_post_metadata', array( $this, 'delete_post_meta' ), 10, 5 ); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
add_action( 'delete_post', array( $this, 'delete_post' ), 10, 1 ); |
154
|
|
|
|
155
|
|
|
if ( !empty( self::$taxonomies ) ) { |
156
|
|
|
$has_fields = false; |
157
|
|
|
|
158
|
|
|
// Handle Taxonomy Editor |
159
|
|
|
foreach ( self::$taxonomies as $taxonomy ) { |
|
|
|
|
160
|
|
|
if ( empty( $taxonomy[ 'fields' ] ) ) { |
161
|
|
|
continue; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$has_fields = true; |
165
|
|
|
|
166
|
|
|
$taxonomy_name = $taxonomy[ 'name' ]; |
167
|
|
|
|
168
|
|
|
if ( !empty( $taxonomy[ 'object' ] ) ) |
169
|
|
|
$taxonomy_name = $taxonomy[ 'object' ]; |
170
|
|
|
|
171
|
|
|
add_action( $taxonomy_name . '_edit_form_fields', array( $this, 'meta_taxonomy' ), 10, 2 ); |
172
|
|
|
add_action( $taxonomy_name . '_add_form_fields', array( $this, 'meta_taxonomy' ), 10, 1 ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
if ( $has_fields ) { |
176
|
|
|
// Handle Term Editor |
177
|
|
|
add_action( 'edited_term', array( $this, 'save_taxonomy' ), 10, 3 ); |
178
|
|
|
add_action( 'create_term', array( $this, 'save_taxonomy' ), 10, 3 ); |
179
|
|
|
|
180
|
|
|
if ( apply_filters( 'pods_meta_handler', true, 'term' ) ) { |
181
|
|
|
// Handle *_term_meta |
182
|
|
|
if ( apply_filters( 'pods_meta_handler_get', true, 'term' ) ) { |
183
|
|
|
add_filter( 'get_term_metadata', array( $this, 'get_term_meta' ), 10, 4 ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
if ( !pods_tableless() ) { |
187
|
|
|
add_filter( 'add_term_metadata', array( $this, 'add_term_meta' ), 10, 5 ); |
188
|
|
|
add_filter( 'update_term_metadata', array( $this, 'update_term_meta' ), 10, 5 ); |
189
|
|
|
add_filter( 'delete_term_metadata', array( $this, 'delete_term_meta' ), 10, 5 ); |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Fires after a previously shared taxonomy term is split into two separate terms. |
197
|
|
|
* |
198
|
|
|
* @since 4.2.0 |
199
|
|
|
* |
200
|
|
|
* @param int $term_id ID of the formerly shared term. |
201
|
|
|
* @param int $new_term_id ID of the new term created for the $term_taxonomy_id. |
202
|
|
|
* @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. |
203
|
|
|
* @param string $taxonomy Taxonomy for the split term. |
204
|
|
|
*/ |
205
|
|
|
add_action( 'split_shared_term', array( $this, 'split_shared_term' ), 10, 4 ); |
206
|
|
|
|
207
|
|
|
// Handle Delete |
208
|
|
|
add_action( 'delete_term_taxonomy', array( $this, 'delete_taxonomy' ), 10, 1 ); |
209
|
|
|
|
210
|
|
|
if ( !empty( self::$media ) ) { |
211
|
|
View Code Duplication |
if ( pods_version_check( 'wp', '3.5' ) ) { |
212
|
|
|
add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) ); |
213
|
|
|
add_action( 'wp_ajax_save-attachment-compat', array( $this, 'save_media_ajax' ), 0 ); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
add_filter( 'attachment_fields_to_edit', array( $this, 'meta_media' ), 10, 2 ); |
217
|
|
|
|
218
|
|
|
add_filter( 'attachment_fields_to_save', array( $this, 'save_media' ), 10, 2 ); |
219
|
|
|
add_filter( 'wp_update_attachment_metadata', array( $this, 'save_media' ), 10, 2 ); |
220
|
|
|
|
221
|
|
|
if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) { |
222
|
|
|
// Handle *_post_meta |
223
|
|
View Code Duplication |
if ( !has_filter( 'get_post_metadata', array( $this, 'get_post_meta' ) ) ) { |
224
|
|
|
if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) { |
225
|
|
|
add_filter( 'get_post_metadata', array( $this, 'get_post_meta' ), 10, 4 ); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
if ( !pods_tableless() ) { |
229
|
|
|
add_filter( 'add_post_metadata', array( $this, 'add_post_meta' ), 10, 5 ); |
230
|
|
|
add_filter( 'update_post_metadata', array( $this, 'update_post_meta' ), 10, 5 ); |
231
|
|
|
add_filter( 'delete_post_metadata', array( $this, 'delete_post_meta' ), 10, 5 ); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
// Handle Delete |
238
|
|
|
add_action( 'delete_attachment', array( $this, 'delete_media' ), 10, 1 ); |
239
|
|
|
|
240
|
|
|
if ( !empty( self::$user ) ) { |
241
|
|
|
// Handle User Editor |
242
|
|
|
add_action( 'show_user_profile', array( $this, 'meta_user' ) ); |
243
|
|
|
add_action( 'edit_user_profile', array( $this, 'meta_user' ) ); |
244
|
|
|
//add_action( 'user_register', array( $this, 'save_user' ) ); |
|
|
|
|
245
|
|
|
add_action( 'profile_update', array( $this, 'save_user' ) ); |
246
|
|
|
|
247
|
|
|
if ( apply_filters( 'pods_meta_handler', true, 'user' ) ) { |
248
|
|
|
// Handle *_user_meta |
249
|
|
|
if ( apply_filters( 'pods_meta_handler_get', true, 'user' ) ) { |
250
|
|
|
add_filter( 'get_user_metadata', array( $this, 'get_user_meta' ), 10, 4 ); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
if ( !pods_tableless() ) { |
254
|
|
|
add_filter( 'add_user_metadata', array( $this, 'add_user_meta' ), 10, 5 ); |
255
|
|
|
add_filter( 'update_user_metadata', array( $this, 'update_user_meta' ), 10, 5 ); |
256
|
|
|
add_filter( 'delete_user_metadata', array( $this, 'delete_user_meta' ), 10, 5 ); |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
// Handle Delete |
262
|
|
|
add_action( 'delete_user', array( $this, 'delete_user' ), 10, 1 ); |
263
|
|
|
|
264
|
|
|
if ( !empty( self::$comment ) ) { |
265
|
|
|
// Handle Comment Form / Editor |
266
|
|
|
add_action( 'comment_form_logged_in_after', array( $this, 'meta_comment_new_logged_in' ), 10, 2 ); |
267
|
|
|
add_filter( 'comment_form_default_fields', array( $this, 'meta_comment_new' ) ); |
268
|
|
|
add_action( 'add_meta_boxes_comment', array( $this, 'meta_comment_add' ) ); |
269
|
|
|
add_filter( 'pre_comment_approved', array( $this, 'validate_comment' ), 10, 2 ); |
270
|
|
|
add_action( 'comment_post', array( $this, 'save_comment' ) ); |
271
|
|
|
add_action( 'edit_comment', array( $this, 'save_comment' ) ); |
272
|
|
|
|
273
|
|
|
if ( apply_filters( 'pods_meta_handler', true, 'comment' ) ) { |
274
|
|
|
// Handle *_comment_meta |
275
|
|
|
add_filter( 'get_comment_metadata', array( $this, 'get_comment_meta' ), 10, 4 ); |
276
|
|
|
|
277
|
|
|
if ( !pods_tableless() ) { |
278
|
|
|
add_filter( 'add_comment_metadata', array( $this, 'add_comment_meta' ), 10, 5 ); |
279
|
|
|
add_filter( 'update_comment_metadata', array( $this, 'update_comment_meta' ), 10, 5 ); |
280
|
|
|
add_filter( 'delete_comment_metadata', array( $this, 'delete_comment_meta' ), 10, 5 ); |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
// Handle Delete |
286
|
|
|
add_action( 'delete_comment', array( $this, 'delete_comment' ), 10, 1 ); |
287
|
|
|
|
288
|
|
|
// @todo Patch core to provide $option back in filters, patch core to add filter pre_add_option to add_option |
289
|
|
|
/*if ( !empty( self::$settings ) ) { |
|
|
|
|
290
|
|
|
foreach ( self::$settings as $setting_pod ) { |
291
|
|
|
foreach ( $setting_pod[ 'fields' ] as $option ) { |
292
|
|
|
add_filter( 'pre_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( $this, 'get_option' ), 10, 1 ); |
293
|
|
|
add_action( 'add_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( $this, 'add_option' ), 10, 2 ); |
294
|
|
|
add_filter( 'pre_update_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( $this, 'update_option' ), 10, 2 ); |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
}*/ |
298
|
|
|
|
299
|
|
|
if ( is_admin() ) |
300
|
|
|
$this->integrations(); |
301
|
|
|
|
302
|
|
|
add_action( 'init', array( $this, 'enqueue' ), 9 ); |
303
|
|
|
|
304
|
|
|
if ( function_exists( 'pll_current_language' ) ) |
305
|
|
|
add_action( 'init', array( $this, 'cache_pods' ), 101 ); |
306
|
|
|
|
307
|
|
|
do_action( 'pods_meta_init' ); |
308
|
|
|
|
309
|
|
|
return $this; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
public static function enqueue () { |
313
|
|
|
foreach ( self::$queue as $type => $objects ) { |
314
|
|
|
foreach ( $objects as $pod_name => $pod ) { |
315
|
|
|
pods_transient_set( 'pods_pod_' . $pod_name, $pod ); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
self::$$type = array_merge( self::$$type, $objects ); |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Go back through and cache the Pods now that Polylang has loaded |
324
|
|
|
*/ |
325
|
|
|
public function cache_pods () { |
326
|
|
|
self::$advanced_content_types = pods_api()->load_pods( array( 'type' => 'pod', 'refresh' => true ) ); |
327
|
|
|
self::$post_types = pods_api()->load_pods( array( 'type' => 'post_type', 'refresh' => true ) ); |
328
|
|
|
self::$taxonomies = pods_api()->load_pods( array( 'type' => 'taxonomy', 'refresh' => true ) ); |
329
|
|
|
self::$media = pods_api()->load_pods( array( 'type' => 'media', 'refresh' => true ) ); |
330
|
|
|
self::$user = pods_api()->load_pods( array( 'type' => 'user', 'refresh' => true ) ); |
331
|
|
|
self::$comment = pods_api()->load_pods( array( 'type' => 'comment', 'refresh' => true ) ); |
332
|
|
|
self::$settings = pods_api()->load_pods( array( 'type' => 'settings', 'refresh' => true ) ); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
public function register ( $type, $pod ) { |
336
|
|
|
$pod_type = $type; |
337
|
|
|
|
338
|
|
|
if ( 'post_type' == $type ) |
339
|
|
|
$type = 'post_types'; |
340
|
|
|
elseif ( 'taxonomy' == $type ) |
341
|
|
|
$type = 'taxonomies'; |
342
|
|
|
elseif ( 'pod' == $type ) |
343
|
|
|
$type = 'advanced_content_types'; |
344
|
|
|
|
345
|
|
|
if ( !isset( self::$queue[ $type ] ) ) |
346
|
|
|
self::$queue[ $type ] = array(); |
347
|
|
|
|
348
|
|
View Code Duplication |
if ( is_array( $pod ) && !empty( $pod ) && !isset( $pod[ 'name' ] ) ) { |
349
|
|
|
$data = array(); |
350
|
|
|
|
351
|
|
|
foreach ( $pod as $p ) { |
352
|
|
|
$data[] = $this->register( $type, $p ); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
return $data; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
$pod[ 'type' ] = $pod_type; |
359
|
|
|
$pod = pods_api()->save_pod( $pod, false, false ); |
360
|
|
|
|
361
|
|
|
if ( !empty( $pod ) ) { |
362
|
|
|
self::$object_identifier--; |
363
|
|
|
|
364
|
|
|
self::$queue[ $type ][ $pod[ 'name' ] ] = $pod; |
365
|
|
|
|
366
|
|
|
return $pod; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
return false; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
public function register_field ( $pod, $field ) { |
373
|
|
View Code Duplication |
if ( is_array( $pod ) && !empty( $pod ) && !isset( $pod[ 'name' ] ) ) { |
374
|
|
|
$data = array(); |
375
|
|
|
|
376
|
|
|
foreach ( $pod as $p ) { |
377
|
|
|
$data[] = $this->register_field( $p, $field ); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
return $data; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
View Code Duplication |
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $pod ) |
384
|
|
|
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $pod ), false ); |
385
|
|
|
|
386
|
|
|
$pod = self::$current_pod_data; |
387
|
|
|
|
388
|
|
|
if ( !empty( $pod ) ) { |
389
|
|
|
$type = $pod[ 'type' ]; |
390
|
|
|
|
391
|
|
|
if ( 'post_type' == $pod[ 'type' ] ) |
392
|
|
|
$type = 'post_types'; |
393
|
|
|
elseif ( 'taxonomy' == $pod[ 'type' ] ) |
394
|
|
|
$type = 'taxonomies'; |
395
|
|
|
elseif ( 'pod' == $pod[ 'type' ] ) |
396
|
|
|
$type = 'advanced_content_types'; |
397
|
|
|
|
398
|
|
|
if ( !isset( self::$queue[ $pod[ 'type' ] ] ) ) |
399
|
|
|
self::$queue[ $type ] = array(); |
400
|
|
|
|
401
|
|
|
$field = pods_api()->save_field( $field, false, false, $pod[ 'id' ] ); |
402
|
|
|
|
403
|
|
|
if ( !empty( $field ) ) { |
404
|
|
|
$pod[ 'fields' ][ $field[ 'name' ] ] = $field; |
405
|
|
|
|
406
|
|
|
self::$queue[ $type ][ $pod[ 'name' ] ] = $pod; |
407
|
|
|
|
408
|
|
|
return $field; |
409
|
|
|
} |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
return false; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
public function integrations () { |
416
|
|
|
// Codepress Admin Columns 2.x |
417
|
|
|
add_filter( 'cac/storage_model/meta_keys', array( $this, 'cpac_meta_keys' ), 10, 2 ); |
418
|
|
|
add_filter( 'cac/post_types', array( $this, 'cpac_post_types' ), 10, 1 ); |
419
|
|
|
add_filter( 'cac/column/meta/value', array( $this, 'cpac_meta_value' ), 10, 3 ); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
|
423
|
|
|
public function cpac_meta_keys ( $meta_fields, $storage_model ) { |
424
|
|
|
$object_type = 'post_type'; |
425
|
|
|
$object = $storage_model->key; |
426
|
|
|
|
427
|
|
|
if ( in_array( $storage_model->key, array( 'wp-links', 'link' ) ) ) { |
428
|
|
|
$object_type = $object = 'link'; |
429
|
|
|
} |
430
|
|
|
elseif ( in_array( $storage_model->key, array( 'wp-media', 'media' ) ) ) { |
431
|
|
|
$object_type = $object = 'media'; |
432
|
|
|
} |
433
|
|
|
elseif ( in_array( $storage_model->key, array( 'wp-users', 'user' ) ) ) { |
434
|
|
|
$object_type = $object = 'user'; |
435
|
|
|
} |
436
|
|
|
elseif ( in_array( $storage_model->key, array( 'wp-comments', 'comment' ) ) ) { |
437
|
|
|
$object_type = $object = 'comment'; |
438
|
|
|
} |
439
|
|
|
elseif ( 'taxonomy' === $storage_model->type ) { |
440
|
|
|
$object_type = 'taxonomy'; |
441
|
|
|
$object = $storage_model->taxonomy; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
View Code Duplication |
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $object ) |
445
|
|
|
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false ); |
446
|
|
|
|
447
|
|
|
$pod = self::$current_pod_data; |
448
|
|
|
|
449
|
|
|
// Add Pods fields |
450
|
|
|
if ( !empty( $pod ) && $object_type == $pod[ 'type' ] ) { |
451
|
|
|
foreach ( $pod[ 'fields' ] as $field => $field_data ) { |
452
|
|
|
if ( !is_array( $meta_fields ) ) |
453
|
|
|
$meta_fields = array(); |
454
|
|
|
|
455
|
|
|
if ( !in_array( $field, $meta_fields ) ) |
456
|
|
|
$meta_fields[] = $field; |
457
|
|
|
} |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
// Remove internal Pods fields |
461
|
|
|
if ( is_array( $meta_fields ) ) { |
462
|
|
|
foreach ( $meta_fields as $k => $meta_field ) { |
463
|
|
|
if ( 0 === strpos( $meta_field, '_pods_' ) ) |
464
|
|
|
unset( $meta_fields[ $k ] ); |
465
|
|
|
} |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
return $meta_fields; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
public function cpac_post_types ( $post_types ) { |
472
|
|
|
// Remove internal Pods post types |
473
|
|
|
foreach ( $post_types as $post_type => $post_type_name ) { |
474
|
|
|
if ( 0 === strpos( $post_type, '_pods_' ) || 0 === strpos( $post_type_name, '_pods_' ) ) |
475
|
|
|
unset( $post_types[ $post_type ] ); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
return $post_types; |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
public function cpac_meta_value ( $meta, $id, $obj ) { |
482
|
|
|
$tableless_field_types = PodsForm::tableless_field_types(); |
483
|
|
|
|
484
|
|
|
$object_type = 'post_type'; |
485
|
|
|
$object = $obj->storage_model->key; |
486
|
|
|
|
487
|
|
|
if ( in_array( $obj->storage_model->type, array( 'wp-links', 'link' ) ) ) { |
488
|
|
|
$object_type = $object = 'link'; |
489
|
|
|
} |
490
|
|
|
elseif ( in_array( $obj->storage_model->type, array( 'wp-media', 'media' ) ) ) { |
491
|
|
|
$object_type = $object = 'media'; |
492
|
|
|
} |
493
|
|
|
elseif ( in_array( $obj->storage_model->type, array( 'wp-users', 'user' ) ) ) { |
494
|
|
|
$object_type = $object = 'user'; |
495
|
|
|
} |
496
|
|
|
elseif ( in_array( $obj->storage_model->type, array( 'wp-comments', 'comment' ) ) ) { |
497
|
|
|
$object_type = $object = 'comment'; |
498
|
|
|
} |
499
|
|
|
elseif ( 'taxonomy' === $obj->storage_model->type ) { |
500
|
|
|
$object_type = 'taxonomy'; |
501
|
|
|
$object = $obj->storage_model->taxonomy; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
$field = substr( $obj->options->field, 0, 10 ) == "cpachidden" ? str_replace( 'cpachidden', '', $obj->options->field ) : $obj->options->field; |
505
|
|
|
$field_type = $obj->options->field_type; |
506
|
|
|
|
507
|
|
View Code Duplication |
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $object ) |
508
|
|
|
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false ); |
509
|
|
|
|
510
|
|
|
$pod = self::$current_pod_data; |
511
|
|
|
|
512
|
|
|
// Add Pods fields |
513
|
|
|
if ( !empty( $pod ) && isset( $pod[ 'fields' ][ $field ] ) ) { |
514
|
|
|
if ( in_array( $pod[ 'type' ], array( 'post_type', 'media', 'taxonomy', 'user', 'comment', 'media' ) ) && ( !empty( $field_type ) || in_array( $pod[ 'fields' ][ $field ][ 'type' ], $tableless_field_types ) ) ) { |
515
|
|
|
$metadata_type = $pod['type']; |
516
|
|
|
|
517
|
|
|
if ( in_array( $metadata_type, array( 'post_type', 'media' ) ) ) { |
518
|
|
|
$metadata_type = 'post'; |
519
|
|
|
} elseif ( 'taxonomy' == $metadata_type ) { |
520
|
|
|
$metadata_type = 'term'; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
if ( 'term' == $metadata_type && ! function_exists( 'get_term_meta' ) ) { |
524
|
|
|
$podterms = pods( $pod['name'], $id ); |
525
|
|
|
|
526
|
|
|
$meta = $podterms->field( $field ); |
527
|
|
|
} else { |
528
|
|
|
$meta = get_metadata( $metadata_type, $id, $field, true ); |
529
|
|
|
} |
530
|
|
|
} |
531
|
|
|
elseif ( 'taxonomy' == $pod['type'] ) { |
532
|
|
|
$podterms = pods( $pod['name'], $id ); |
533
|
|
|
|
534
|
|
|
$meta = $podterms->field( $field ); |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
$meta = PodsForm::field_method( $pod[ 'fields' ][ $field ][ 'type' ], 'ui', $id, $meta, $field, array_merge( $pod[ 'fields' ][ $field ], $pod[ 'fields' ][ $field ][ 'options' ] ), $pod[ 'fields' ], $pod ); |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
return $meta; |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
public function cpac_meta_values ( $meta, $field_type, $field, $type, $id ) { |
544
|
|
|
$tableless_field_types = PodsForm::tableless_field_types(); |
545
|
|
|
|
546
|
|
|
$object = $type; |
547
|
|
|
|
548
|
|
|
if ( 'wp-media' == $type ) |
549
|
|
|
$object = 'media'; |
550
|
|
|
elseif ( 'wp-users' == $type ) |
551
|
|
|
$object = 'user'; |
552
|
|
|
elseif ( 'wp-comments' == $type ) |
553
|
|
|
$object = 'comment'; |
554
|
|
|
|
555
|
|
View Code Duplication |
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $object ) |
556
|
|
|
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false ); |
557
|
|
|
|
558
|
|
|
$pod = self::$current_pod_data; |
559
|
|
|
|
560
|
|
|
// Add Pods fields |
561
|
|
|
if ( !empty( $pod ) && isset( $pod[ 'fields' ][ $field ] ) ) { |
562
|
|
|
if ( in_array( $pod[ 'type' ], array( 'post_type', 'user', 'taxonomy', 'comment', 'media' ) ) && ( !empty( $field_type ) || in_array( $pod[ 'fields' ][ $field ][ 'type' ], $tableless_field_types ) ) ) { |
563
|
|
|
$metadata_type = $pod['type']; |
564
|
|
|
|
565
|
|
|
if ( in_array( $metadata_type, array( 'post_type', 'media' ) ) ) { |
566
|
|
|
$metadata_type = 'post'; |
567
|
|
|
} elseif ( 'taxonomy' == $metadata_type ) { |
568
|
|
|
$metadata_type = 'term'; |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
$meta = get_metadata( $metadata_type, $id, $field, true ); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
$meta = PodsForm::field_method( $pod[ 'fields' ][ $field ][ 'type' ], 'ui', $id, $meta, $field, array_merge( $pod[ 'fields' ][ $field ], $pod[ 'fields' ][ $field ][ 'options' ] ), $pod[ 'fields' ], $pod ); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
return $meta; |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* Add a meta group of fields to add/edit forms |
582
|
|
|
* |
583
|
|
|
* @param string|array $pod The pod or type of element to attach the group to. |
584
|
|
|
* @param string $label Title of the edit screen section, visible to user. |
585
|
|
|
* @param string|array $fields Either a comma separated list of text fields or an associative array containing field infomration. |
586
|
|
|
* @param string $context (optional) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side'). |
587
|
|
|
* @param string $priority (optional) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low'). |
588
|
|
|
* |
589
|
|
|
* @since 2.0 |
590
|
|
|
* |
591
|
|
|
* @return mixed|void |
592
|
|
|
*/ |
593
|
|
|
public function group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default' ) { |
594
|
|
View Code Duplication |
if ( is_array( $pod ) && !empty( $pod ) && !isset( $pod[ 'name' ] ) ) { |
595
|
|
|
foreach ( $pod as $p ) { |
596
|
|
|
$this->group_add( $pod, $label, $fields, $context, $priority ); |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
return true; |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
if ( !is_array( $pod ) ) { |
603
|
|
View Code Duplication |
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $pod ) |
604
|
|
|
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $pod ), false ); |
605
|
|
|
|
606
|
|
|
if ( !empty( self::$current_pod_data ) ) |
607
|
|
|
$pod = self::$current_pod_data; |
608
|
|
|
else { |
609
|
|
|
$type = 'post_type'; |
610
|
|
|
|
611
|
|
|
if ( in_array( $pod, array( 'media', 'user', 'comment' ) ) ) |
612
|
|
|
$type = $pod; |
613
|
|
|
|
614
|
|
|
$pod = array( |
615
|
|
|
'name' => $pod, |
616
|
|
|
'type' => $type |
617
|
|
|
); |
618
|
|
|
} |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
if ( is_array( $pod ) && !isset( $pod[ 'id' ] ) ) { |
622
|
|
|
$defaults = array( |
623
|
|
|
'name' => '', |
624
|
|
|
'type' => 'post_type' |
625
|
|
|
); |
626
|
|
|
|
627
|
|
|
$pod = array_merge( $defaults, $pod ); |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
if ( 'post' == $pod[ 'type' ] ) |
631
|
|
|
$pod[ 'type' ] = 'post_type'; |
632
|
|
|
|
633
|
|
|
if ( empty( $pod[ 'name' ] ) && isset( $pod[ 'object' ] ) && !empty( $pod[ 'object' ] ) ) |
634
|
|
|
$pod[ 'name' ] = $pod[ 'object' ]; |
635
|
|
View Code Duplication |
elseif ( !isset( $pod[ 'object' ] ) || empty( $pod[ 'object' ] ) ) |
636
|
|
|
$pod[ 'object' ] = $pod[ 'name' ]; |
637
|
|
|
|
638
|
|
|
if ( empty( $pod[ 'object' ] ) ) |
639
|
|
|
return pods_error( __( 'Object required to add a Pods meta group', 'pods' ) ); |
640
|
|
|
|
641
|
|
|
$object_name = $pod[ 'object' ]; |
642
|
|
|
|
643
|
|
|
if ( 'pod' == $pod[ 'type' ] ) |
644
|
|
|
$object_name = $pod[ 'name' ]; |
645
|
|
|
|
646
|
|
View Code Duplication |
if ( !isset( self::$groups[ $pod[ 'type' ] ] ) ) |
647
|
|
|
self::$groups[ $pod[ 'type' ] ] = array(); |
648
|
|
|
|
649
|
|
View Code Duplication |
if ( !isset( self::$groups[ $pod[ 'type' ] ][ $object_name ] ) ) |
650
|
|
|
self::$groups[ $pod[ 'type' ] ][ $object_name ] = array(); |
651
|
|
|
|
652
|
|
|
$_fields = array(); |
653
|
|
|
|
654
|
|
|
if ( !is_array( $fields ) ) |
655
|
|
|
$fields = explode( ',', $fields ); |
656
|
|
|
|
657
|
|
|
foreach ( $fields as $k => $field ) { |
658
|
|
|
$name = $k; |
659
|
|
|
|
660
|
|
|
$defaults = array( |
661
|
|
|
'name' => $name, |
662
|
|
|
'label' => $name, |
663
|
|
|
'type' => 'text' |
664
|
|
|
); |
665
|
|
|
|
666
|
|
|
if ( !is_array( $field ) ) { |
667
|
|
|
$name = trim( $field ); |
668
|
|
|
|
669
|
|
|
$field = array( |
670
|
|
|
'name' => $name, |
671
|
|
|
'label' => $name |
672
|
|
|
); |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
$field = array_merge( $defaults, $field ); |
676
|
|
|
|
677
|
|
|
$field[ 'name' ] = trim( $field[ 'name' ] ); |
678
|
|
|
|
679
|
|
View Code Duplication |
if ( isset( $pod[ 'fields' ] ) && isset( $pod[ 'fields' ][ $field[ 'name' ] ] ) ) |
680
|
|
|
$field = array_merge( $field, $pod[ 'fields' ][ $field[ 'name' ] ] ); |
681
|
|
|
|
682
|
|
|
$_fields[ $k ] = $field; |
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
// Setup field options |
686
|
|
|
$fields = PodsForm::fields_setup( $_fields ); |
687
|
|
|
|
688
|
|
|
$group = array( |
689
|
|
|
'pod' => $pod, |
690
|
|
|
'label' => $label, |
691
|
|
|
'fields' => $fields, |
692
|
|
|
'context' => $context, |
693
|
|
|
'priority' => $priority |
694
|
|
|
); |
695
|
|
|
|
696
|
|
|
// Filter group data, pass vars separately for reference down the line (in case array changed by other filter) |
697
|
|
|
$group = apply_filters( 'pods_meta_group_add_' . $pod[ 'type' ] . '_' . $object_name, $group, $pod, $label, $fields ); |
698
|
|
|
$group = apply_filters( 'pods_meta_group_add_' . $pod[ 'type' ], $group, $pod, $label, $fields ); |
699
|
|
|
$group = apply_filters( 'pods_meta_group_add', $group, $pod, $label, $fields ); |
700
|
|
|
|
701
|
|
|
self::$groups[ $pod[ 'type' ] ][ $object_name ][] = $group; |
702
|
|
|
|
703
|
|
|
// Hook it up! |
704
|
|
|
if ( 'post_type' == $pod[ 'type' ] ) { |
705
|
|
|
if ( !has_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) ) ) |
706
|
|
|
add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) ); |
707
|
|
|
|
708
|
|
|
/*if ( !has_action( 'save_post', array( $this, 'save_post' ), 10, 3 ) ) |
|
|
|
|
709
|
|
|
add_action( 'save_post', array( $this, 'save_post' ), 10, 3 );*/ |
710
|
|
|
} |
711
|
|
|
elseif ( 'taxonomy' == $pod[ 'type' ] ) { |
712
|
|
|
if ( !has_action( $pod[ 'object' ] . '_edit_form_fields', array( $this, 'meta_taxonomy' ), 10, 2 ) ) { |
713
|
|
|
add_action( $pod[ 'object' ] . '_edit_form_fields', array( $this, 'meta_taxonomy' ), 10, 2 ); |
714
|
|
|
add_action( $pod[ 'object' ] . '_add_form_fields', array( $this, 'meta_taxonomy' ), 10, 1 ); |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
if ( !has_action( 'edited_term', array( $this, 'save_taxonomy' ), 10, 3 ) ) { |
718
|
|
|
add_action( 'edited_term', array( $this, 'save_taxonomy' ), 10, 3 ); |
719
|
|
|
add_action( 'create_term', array( $this, 'save_taxonomy' ), 10, 3 ); |
720
|
|
|
} |
721
|
|
|
} |
722
|
|
|
elseif ( 'media' == $pod[ 'type' ] ) { |
723
|
|
|
if ( !has_filter( 'wp_update_attachment_metadata', array( $this, 'save_media' ), 10, 2 ) ) { |
724
|
|
View Code Duplication |
if ( pods_version_check( 'wp', '3.5' ) ) { |
725
|
|
|
add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) ); |
726
|
|
|
add_action( 'wp_ajax_save-attachment-compat', array( $this, 'save_media_ajax' ), 0 ); |
727
|
|
|
} |
728
|
|
|
|
729
|
|
|
add_filter( 'attachment_fields_to_edit', array( $this, 'meta_media' ), 10, 2 ); |
730
|
|
|
|
731
|
|
|
add_filter( 'attachment_fields_to_save', array( $this, 'save_media' ), 10, 2 ); |
732
|
|
|
add_filter( 'wp_update_attachment_metadata', array( $this, 'save_media' ), 10, 2 ); |
733
|
|
|
} |
734
|
|
|
} |
735
|
|
|
elseif ( 'user' == $pod[ 'type' ] ) { |
736
|
|
|
if ( !has_action( 'show_user_profile', array( $this, 'meta_user' ) ) ) { |
737
|
|
|
add_action( 'show_user_profile', array( $this, 'meta_user' ) ); |
738
|
|
|
add_action( 'edit_user_profile', array( $this, 'meta_user' ) ); |
739
|
|
|
//add_action( 'user_register', array( $this, 'save_user' ) ); |
|
|
|
|
740
|
|
|
add_action( 'profile_update', array( $this, 'save_user' ) ); |
741
|
|
|
} |
742
|
|
|
} |
743
|
|
|
elseif ( 'comment' == $pod[ 'type' ] ) { |
744
|
|
|
if ( !has_action( 'comment_form_logged_in_after', array( $this, 'meta_comment_new_logged_in' ), 10, 2 ) ) { |
745
|
|
|
add_action( 'comment_form_logged_in_after', array( $this, 'meta_comment_new_logged_in' ), 10, 2 ); |
746
|
|
|
add_filter( 'comment_form_default_fields', array( $this, 'meta_comment_new' ) ); |
747
|
|
|
add_action( 'add_meta_boxes_comment', array( $this, 'meta_comment_add' ) ); |
748
|
|
|
add_action( 'wp_insert_comment', array( $this, 'save_comment' ) ); |
749
|
|
|
add_action( 'edit_comment', array( $this, 'save_comment' ) ); |
750
|
|
|
} |
751
|
|
|
} |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
public function object_get ( $type, $name ) { |
755
|
|
|
$object = self::$post_types; |
756
|
|
|
|
757
|
|
|
if ( 'term' == $type ) { |
758
|
|
|
$type = 'taxonomy'; |
759
|
|
|
} |
760
|
|
|
|
761
|
|
|
if ( 'taxonomy' == $type ) |
762
|
|
|
$object = self::$taxonomies; |
763
|
|
|
elseif ( 'media' == $type ) |
764
|
|
|
$object = self::$media; |
765
|
|
|
elseif ( 'user' == $type ) |
766
|
|
|
$object = self::$user; |
767
|
|
|
elseif ( 'comment' == $type ) |
768
|
|
|
$object = self::$comment; |
769
|
|
|
|
770
|
|
|
if ( 'pod' != $type && !empty( $object ) && is_array( $object ) && isset( $object[ $name ] ) ) |
771
|
|
|
$pod = $object[ $name ]; |
772
|
|
View Code Duplication |
else { |
773
|
|
|
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $name ) |
774
|
|
|
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $name ), false ); |
775
|
|
|
|
776
|
|
|
$pod = self::$current_pod_data; |
777
|
|
|
} |
778
|
|
|
|
779
|
|
|
if ( empty( $pod ) ) |
780
|
|
|
return array(); |
781
|
|
|
|
782
|
|
|
$defaults = array( |
783
|
|
|
'name' => 'post', |
784
|
|
|
'object' => 'post', |
785
|
|
|
'type' => 'post_type' |
786
|
|
|
); |
787
|
|
|
|
788
|
|
|
$pod = array_merge( $defaults, (array) $pod ); |
789
|
|
|
|
790
|
|
View Code Duplication |
if ( empty( $pod[ 'name' ] ) ) |
791
|
|
|
$pod[ 'name' ] = $pod[ 'object' ]; |
792
|
|
|
elseif ( empty( $pod[ 'object' ] ) ) |
793
|
|
|
$pod[ 'object' ] = $pod[ 'name' ]; |
794
|
|
|
|
795
|
|
|
if ( $pod[ 'type' ] != $type ) |
796
|
|
|
return array(); |
797
|
|
|
|
798
|
|
|
return $pod; |
799
|
|
|
} |
800
|
|
|
|
801
|
|
|
/** |
802
|
|
|
* @param $type |
803
|
|
|
* @param $name |
804
|
|
|
* @param $default_fields |
805
|
|
|
* |
806
|
|
|
* @return array |
807
|
|
|
*/ |
808
|
|
|
public function groups_get ( $type, $name, $default_fields = null ) { |
809
|
|
|
if ( 'post_type' == $type && 'attachment' == $name ) { |
810
|
|
|
$type = 'media'; |
811
|
|
|
$name = 'media'; |
812
|
|
|
} elseif ( 'term' == $type ) { |
813
|
|
|
$type = 'taxonomy'; |
814
|
|
|
} |
815
|
|
|
|
816
|
|
|
do_action( 'pods_meta_groups', $type, $name ); |
817
|
|
|
|
818
|
|
|
$pod = array(); |
819
|
|
|
$fields = array(); |
820
|
|
|
|
821
|
|
|
$object = self::$post_types; |
822
|
|
|
|
823
|
|
|
if ( 'taxonomy' == $type ) |
824
|
|
|
$object = self::$taxonomies; |
825
|
|
|
elseif ( 'media' == $type ) |
826
|
|
|
$object = self::$media; |
827
|
|
|
elseif ( 'user' == $type ) |
828
|
|
|
$object = self::$user; |
829
|
|
|
elseif ( 'comment' == $type ) |
830
|
|
|
$object = self::$comment; |
831
|
|
|
elseif ( 'pod' == $type ) |
832
|
|
|
$object = self::$advanced_content_types; |
833
|
|
|
|
834
|
|
|
if ( !empty( $object ) && is_array( $object ) && isset( $object[ $name ] ) ) |
835
|
|
|
$fields = $object[ $name ][ 'fields' ]; |
836
|
|
|
else { |
837
|
|
View Code Duplication |
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $name ) |
838
|
|
|
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $name ), false ); |
839
|
|
|
|
840
|
|
|
$pod = self::$current_pod_data; |
841
|
|
|
|
842
|
|
|
if ( !empty( $pod ) ) |
843
|
|
|
$fields = $pod[ 'fields' ]; |
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
if ( null !== $default_fields ) { |
847
|
|
|
$fields = $default_fields; |
848
|
|
|
} |
849
|
|
|
|
850
|
|
|
$defaults = array( |
851
|
|
|
'name' => 'post', |
852
|
|
|
'object' => 'post', |
853
|
|
|
'type' => 'post_type' |
854
|
|
|
); |
855
|
|
|
|
856
|
|
|
$pod = array_merge( $defaults, (array) $pod ); |
857
|
|
|
|
858
|
|
View Code Duplication |
if ( empty( $pod[ 'name' ] ) ) |
859
|
|
|
$pod[ 'name' ] = $pod[ 'object' ]; |
860
|
|
|
elseif ( empty( $pod[ 'object' ] ) ) |
861
|
|
|
$pod[ 'object' ] = $pod[ 'name' ]; |
862
|
|
|
|
863
|
|
|
if ( $pod[ 'type' ] != $type ) |
864
|
|
|
return array(); |
865
|
|
|
|
866
|
|
|
$groups = array( |
867
|
|
|
array( |
868
|
|
|
'pod' => $pod, |
869
|
|
|
/** |
870
|
|
|
* Filter the title of the Pods Metabox In The Post Editor |
871
|
|
|
* |
872
|
|
|
* @param string $title The title to use, default is 'More Fields' |
873
|
|
|
* @param obj|Pod $pod Current Pods Object |
874
|
|
|
* @param array $fields Array of fields that will go in the metabox |
875
|
|
|
* @param string $type The type of Pod |
876
|
|
|
* @params string $name Name of the Pod |
877
|
|
|
* |
878
|
|
|
* @returns string The title for the metabox. |
879
|
|
|
* |
880
|
|
|
* @since unknown |
881
|
|
|
*/ |
882
|
|
|
'label' => apply_filters( 'pods_meta_default_box_title', __( 'More Fields', 'pods' ), $pod, $fields, $type, $name ), |
883
|
|
|
'fields' => $fields, |
884
|
|
|
'context' => 'normal', |
885
|
|
|
'priority' => 'default' |
886
|
|
|
) |
887
|
|
|
); |
888
|
|
|
|
889
|
|
|
if ( isset( self::$groups[ $type ] ) && isset( self::$groups[ $type ][ $name ] ) ) |
890
|
|
|
$groups = self::$groups[ $type ][ $name ]; |
891
|
|
|
|
892
|
|
|
return $groups; |
893
|
|
|
} |
894
|
|
|
|
895
|
|
|
/** |
896
|
|
|
* @param $post_type |
897
|
|
|
* @param null $post |
898
|
|
|
*/ |
899
|
|
|
public function meta_post_add ( $post_type, $post = null ) { |
900
|
|
|
if ( 'comment' == $post_type ) |
901
|
|
|
return; |
902
|
|
|
|
903
|
|
|
if ( is_object( $post ) ) |
904
|
|
|
$post_type = $post->post_type; |
905
|
|
|
|
906
|
|
|
$groups = $this->groups_get( 'post_type', $post_type ); |
907
|
|
|
$pods_field_found = false; |
908
|
|
|
|
909
|
|
|
foreach ( $groups as $group ) { |
910
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
911
|
|
|
continue; |
912
|
|
|
|
913
|
|
|
$field_found = false; |
914
|
|
|
|
915
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
916
|
|
|
if ( false !== PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ] ) ) { |
917
|
|
|
$field_found = true; |
918
|
|
|
break; |
919
|
|
|
} |
920
|
|
|
} |
921
|
|
|
|
922
|
|
|
if ( empty( $group[ 'label' ] ) ) |
923
|
|
|
$group[ 'label' ] = get_post_type_object( $post_type )->labels->label; |
924
|
|
|
|
925
|
|
View Code Duplication |
if ( $field_found ) { |
926
|
|
|
$pods_field_found = true; |
927
|
|
|
add_meta_box( |
928
|
|
|
'pods-meta-' . sanitize_title( $group[ 'label' ] ), |
929
|
|
|
$group[ 'label' ], |
930
|
|
|
array( $this, 'meta_post' ), |
931
|
|
|
$post_type, |
932
|
|
|
$group[ 'context' ], |
933
|
|
|
$group[ 'priority' ], |
934
|
|
|
array( 'group' => $group ) |
935
|
|
|
); |
936
|
|
|
|
937
|
|
|
} |
938
|
|
|
} |
939
|
|
|
|
940
|
|
|
if ( $pods_field_found ) { |
941
|
|
|
// Only add the classes to forms that actually have pods fields |
942
|
|
|
add_action( 'post_edit_form_tag', array( $this, 'add_class_submittable' ) ); |
943
|
|
|
} |
944
|
|
|
} |
945
|
|
|
|
946
|
|
|
/** |
947
|
|
|
* |
948
|
|
|
* Called by 'post_edit_form_tag' action to include the classes in the <form> tag |
949
|
|
|
* |
950
|
|
|
*/ |
951
|
|
|
public function add_class_submittable () { |
952
|
|
|
echo ' class="pods-submittable pods-form"'; |
953
|
|
|
} |
954
|
|
|
|
955
|
|
|
/** |
956
|
|
|
* @param $post |
957
|
|
|
* @param $metabox |
958
|
|
|
*/ |
959
|
|
|
public function meta_post ( $post, $metabox ) { |
960
|
|
|
wp_enqueue_style( 'pods-form' ); |
961
|
|
|
wp_enqueue_script( 'pods' ); |
962
|
|
|
|
963
|
|
|
$pod_type = 'post'; |
964
|
|
|
|
965
|
|
|
if ( 'attachment' == $post->post_type ) { |
966
|
|
|
$pod_type = 'media'; |
967
|
|
|
} |
968
|
|
|
|
969
|
|
|
do_action( 'pods_meta_' . __FUNCTION__, $post ); |
970
|
|
|
|
971
|
|
|
$hidden_fields = array(); |
972
|
|
|
?> |
973
|
|
|
<table class="form-table pods-metabox pods-admin pods-dependency"> |
974
|
|
|
<?php echo PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_' . $pod_type ), 'hidden' ); ?> |
975
|
|
|
|
976
|
|
|
<?php |
977
|
|
|
$id = null; |
978
|
|
|
|
979
|
|
|
if ( is_object( $post ) && false === strpos( $_SERVER[ 'REQUEST_URI' ], '/post-new.php' ) ) |
980
|
|
|
$id = $post->ID; |
981
|
|
|
|
982
|
|
View Code Duplication |
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod ) || self::$current_pod->pod != $metabox[ 'args' ][ 'group' ][ 'pod' ][ 'name' ] ) |
983
|
|
|
self::$current_pod = pods( $metabox[ 'args' ][ 'group' ][ 'pod' ][ 'name' ], $id, true ); |
984
|
|
|
elseif ( self::$current_pod->id() != $id ) |
985
|
|
|
self::$current_pod->fetch( $id ); |
986
|
|
|
|
987
|
|
|
$pod = self::$current_pod; |
988
|
|
|
|
989
|
|
|
foreach ( $metabox[ 'args' ][ 'group' ][ 'fields' ] as $field ) { |
990
|
|
|
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $metabox[ 'args' ][ 'group' ][ 'fields' ], $pod, $id ) ) { |
991
|
|
|
if ( pods_var( 'hidden', $field[ 'options' ], false ) ) |
992
|
|
|
$field[ 'type' ] = 'hidden'; |
993
|
|
|
else |
994
|
|
|
continue; |
995
|
|
|
} |
996
|
|
|
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) ) |
997
|
|
|
$field[ 'type' ] = 'hidden'; |
998
|
|
|
|
999
|
|
|
$value = ''; |
1000
|
|
|
|
1001
|
|
View Code Duplication |
if ( !empty( $pod ) ) { |
1002
|
|
|
pods_no_conflict_on( 'post' ); |
1003
|
|
|
|
1004
|
|
|
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) ); |
1005
|
|
|
|
1006
|
|
|
pods_no_conflict_off( 'post' ); |
1007
|
|
|
} |
1008
|
|
|
elseif ( !empty( $id ) ) |
1009
|
|
|
$value = get_post_meta( $id, $field[ 'name' ], true ); |
1010
|
|
|
|
1011
|
|
|
if ( 'hidden' == $field[ 'type' ] ) { |
1012
|
|
|
$hidden_fields[] = array( |
1013
|
|
|
'field' => $field, |
1014
|
|
|
'value' => $value |
1015
|
|
|
); |
1016
|
|
|
} |
1017
|
|
|
else { |
1018
|
|
|
$depends = PodsForm::dependencies( $field, 'pods-meta-' ); |
1019
|
|
|
|
1020
|
|
|
do_action( 'pods_meta_' . __FUNCTION__ . '_' . $field[ 'name' ], $post, $field, $pod ); |
1021
|
|
|
?> |
1022
|
|
|
<tr class="form-field pods-field pods-field-input <?php echo esc_attr( 'pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ], true ) ); ?> <?php echo esc_attr( $depends ); ?>"> |
1023
|
|
|
<th scope="row" valign="top"><?php echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?></th> |
1024
|
|
|
<td> |
1025
|
|
|
<?php |
1026
|
|
|
// Remove any extra ? help icons |
1027
|
|
|
if ( isset( $field[ 'help' ] ) ) |
1028
|
|
|
unset( $field[ 'help' ] ); |
1029
|
|
|
?> |
1030
|
|
|
<div class="pods-submittable-fields"> |
1031
|
|
|
<?php echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); ?> |
1032
|
|
|
<?php echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); ?> |
1033
|
|
|
</div> |
1034
|
|
|
</td> |
1035
|
|
|
</tr> |
1036
|
|
|
<?php |
1037
|
|
|
do_action( 'pods_meta_' . __FUNCTION__ . '_' . $field[ 'name' ] . '_post', $post, $field, $pod ); |
1038
|
|
|
} |
1039
|
|
|
} |
1040
|
|
|
?> |
1041
|
|
|
</table> |
1042
|
|
|
|
1043
|
|
|
<?php |
1044
|
|
|
do_action( 'pods_meta_' . __FUNCTION__ . '_post', $post ); |
1045
|
|
|
|
1046
|
|
View Code Duplication |
foreach ( $hidden_fields as $hidden_field ) { |
1047
|
|
|
$field = $hidden_field[ 'field' ]; |
1048
|
|
|
|
1049
|
|
|
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $hidden_field[ 'value' ], 'hidden' ); |
1050
|
|
|
} |
1051
|
|
|
?> |
1052
|
|
|
|
1053
|
|
|
<script type="text/javascript"> |
1054
|
|
|
jQuery( function ( $ ) { |
1055
|
|
|
$( document ).Pods( 'validate' ); |
1056
|
|
|
$( document ).Pods( 'submit_meta' ); |
1057
|
|
|
$( document ).Pods( 'dependency', true ); |
1058
|
|
|
} ); |
1059
|
|
|
</script> |
1060
|
|
|
<?php |
1061
|
|
|
} |
1062
|
|
|
|
1063
|
|
|
/** |
1064
|
|
|
* @param $new_status |
1065
|
|
|
* @param $old_status |
1066
|
|
|
* @param $post |
1067
|
|
|
*/ |
1068
|
|
|
public function save_post_detect_new ( $new_status, $old_status, $post ) { |
|
|
|
|
1069
|
|
|
self::$old_post_status = $old_status; |
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
|
/** |
1073
|
|
|
* @param $post_id |
1074
|
|
|
* @param $post |
1075
|
|
|
* @param $update |
1076
|
|
|
* |
1077
|
|
|
* @return int Post ID |
1078
|
|
|
*/ |
1079
|
|
|
public function save_post ( $post_id, $post, $update = null ) { |
1080
|
|
|
$is_new_item = false; |
1081
|
|
|
|
1082
|
|
|
if ( is_bool( $update ) ) |
1083
|
|
|
$is_new_item = !$update; // false is new item |
1084
|
|
|
elseif ( 'new' == self::$old_post_status ) { |
1085
|
|
|
$is_new_item = true; |
1086
|
|
|
} |
1087
|
|
|
|
1088
|
|
View Code Duplication |
if ( empty( $_POST ) ) { |
1089
|
|
|
return $post_id; |
1090
|
|
|
} |
1091
|
|
|
elseif ( !$is_new_item && !wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_post' ) ) { |
1092
|
|
|
return $post_id; |
1093
|
|
|
} |
1094
|
|
|
|
1095
|
|
|
// Reset to avoid manual new post issues |
1096
|
|
|
self::$old_post_status = ''; |
1097
|
|
|
|
1098
|
|
|
$blacklisted_types = array( |
1099
|
|
|
'revision', |
1100
|
|
|
'_pods_pod', |
1101
|
|
|
'_pods_field' |
1102
|
|
|
); |
1103
|
|
|
|
1104
|
|
|
$blacklisted_types = apply_filters( 'pods_meta_save_post_blacklist_types', $blacklisted_types, $post_id, $post ); |
1105
|
|
|
|
1106
|
|
|
// @todo Figure out how to hook into autosave for saving meta |
1107
|
|
|
|
1108
|
|
|
// Block Autosave and Revisions |
1109
|
|
|
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || in_array( $post->post_type, $blacklisted_types ) ) |
1110
|
|
|
return $post_id; |
1111
|
|
|
|
1112
|
|
|
// Block Quick Edits / Bulk Edits |
1113
|
|
|
if ( 'edit.php' == pods_var( 'pagenow', 'global' ) && ( 'inline-save' == pods_var( 'action', 'post' ) || null != pods_var( 'bulk_edit', 'get' ) || is_array( pods_var( 'post', 'get' ) ) ) ) |
1114
|
|
|
return $post_id; |
1115
|
|
|
|
1116
|
|
|
// Block Trash |
1117
|
|
|
if ( in_array( pods_var( 'action', 'get' ), array( 'untrash', 'trash' ) ) ) |
1118
|
|
|
return $post_id; |
1119
|
|
|
|
1120
|
|
|
// Block Auto-drafting and Trash (not via Admin action) |
1121
|
|
|
$blacklisted_status = array( |
1122
|
|
|
'auto-draft', |
1123
|
|
|
'trash' |
1124
|
|
|
); |
1125
|
|
|
|
1126
|
|
|
$blacklisted_status = apply_filters( 'pods_meta_save_post_blacklist_status', $blacklisted_status, $post_id, $post ); |
1127
|
|
|
|
1128
|
|
|
if ( in_array( $post->post_status, $blacklisted_status ) ) |
1129
|
|
|
return $post_id; |
1130
|
|
|
|
1131
|
|
|
$groups = $this->groups_get( 'post_type', $post->post_type ); |
1132
|
|
|
|
1133
|
|
|
if ( empty( $groups ) ) |
1134
|
|
|
return $post_id; |
1135
|
|
|
|
1136
|
|
|
$data = array(); |
1137
|
|
|
|
1138
|
|
|
$id = $post_id; |
1139
|
|
|
$pod = null; |
1140
|
|
|
|
1141
|
|
View Code Duplication |
foreach ( $groups as $group ) { |
1142
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
1143
|
|
|
continue; |
1144
|
|
|
|
1145
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
1146
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) |
1147
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
1148
|
|
|
elseif ( self::$current_pod->id() != $id ) |
1149
|
|
|
self::$current_pod->fetch( $id ); |
1150
|
|
|
|
1151
|
|
|
$pod = self::$current_pod; |
1152
|
|
|
} |
1153
|
|
|
|
1154
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
1155
|
|
|
|
1156
|
|
|
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
1157
|
|
|
if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) |
1158
|
|
|
continue; |
1159
|
|
|
} |
1160
|
|
|
|
1161
|
|
|
$data[ $field[ 'name' ] ] = ''; |
1162
|
|
|
|
1163
|
|
|
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) ) |
1164
|
|
|
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ]; |
1165
|
|
|
} |
1166
|
|
|
} |
1167
|
|
|
|
1168
|
|
View Code Duplication |
if ( $is_new_item ) { |
1169
|
|
|
do_action( 'pods_meta_create_pre_post', $data, $pod, $id, $groups, $post, $post->post_type ); |
1170
|
|
|
do_action( "pods_meta_create_pre_post_{$post->post_type}", $data, $pod, $id, $groups, $post ); |
1171
|
|
|
} |
1172
|
|
|
|
1173
|
|
|
do_action( 'pods_meta_save_pre_post', $data, $pod, $id, $groups, $post, $post->post_type, $is_new_item ); |
1174
|
|
|
do_action( "pods_meta_save_pre_post_{$post->post_type}", $data, $pod, $id, $groups, $post, $is_new_item ); |
1175
|
|
|
|
1176
|
|
|
pods_no_conflict_on( 'post' ); |
1177
|
|
|
|
1178
|
|
View Code Duplication |
if ( !empty( $pod ) ) { |
1179
|
|
|
// Fix for Pods doing it's own sanitization |
1180
|
|
|
$data = pods_unslash( (array) $data ); |
1181
|
|
|
|
1182
|
|
|
$pod->save( $data, null, null, array( 'is_new_item' => $is_new_item ) ); |
1183
|
|
|
} |
1184
|
|
|
elseif ( !empty( $id ) ) { |
1185
|
|
|
foreach ( $data as $field => $value ) { |
1186
|
|
|
update_post_meta( $id, $field, $value ); |
1187
|
|
|
} |
1188
|
|
|
} |
1189
|
|
|
|
1190
|
|
|
pods_no_conflict_off( 'post' ); |
1191
|
|
|
|
1192
|
|
View Code Duplication |
if ( $is_new_item ) { |
1193
|
|
|
do_action( 'pods_meta_create_post', $data, $pod, $id, $groups, $post, $post->post_type ); |
1194
|
|
|
do_action( "pods_meta_create_post_{$post->post_type}", $data, $pod, $id, $groups, $post ); |
1195
|
|
|
} |
1196
|
|
|
|
1197
|
|
|
do_action( 'pods_meta_save_post', $data, $pod, $id, $groups, $post, $post->post_type, $is_new_item ); |
1198
|
|
|
do_action( "pods_meta_save_post_{$post->post_type}", $data, $pod, $id, $groups, $post, $is_new_item ); |
1199
|
|
|
|
1200
|
|
|
return $post_id; |
1201
|
|
|
|
1202
|
|
|
} |
1203
|
|
|
|
1204
|
|
|
/** |
1205
|
|
|
* @param $form_fields |
1206
|
|
|
* @param $post |
1207
|
|
|
* |
1208
|
|
|
* @return array |
1209
|
|
|
*/ |
1210
|
|
|
public function meta_media ( $form_fields, $post ) { |
1211
|
|
|
$groups = $this->groups_get( 'media', 'media' ); |
1212
|
|
|
|
1213
|
|
|
if ( empty( $groups ) || 'attachment' == pods_var( 'typenow', 'global' ) ) |
1214
|
|
|
return $form_fields; |
1215
|
|
|
|
1216
|
|
|
wp_enqueue_style( 'pods-form' ); |
1217
|
|
|
|
1218
|
|
|
$id = null; |
1219
|
|
|
|
1220
|
|
|
if ( is_object( $post ) ) |
1221
|
|
|
$id = $post->ID; |
1222
|
|
|
|
1223
|
|
|
$pod = null; |
1224
|
|
|
|
1225
|
|
|
$meta_nonce = PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_media' ), 'hidden' ); |
1226
|
|
|
|
1227
|
|
|
foreach ( $groups as $group ) { |
1228
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
1229
|
|
|
continue; |
1230
|
|
|
|
1231
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
1232
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) |
1233
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
1234
|
|
|
elseif ( self::$current_pod->id() != $id ) |
1235
|
|
|
self::$current_pod->fetch( $id ); |
1236
|
|
|
|
1237
|
|
|
$pod = self::$current_pod; |
1238
|
|
|
} |
1239
|
|
|
|
1240
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
1241
|
|
|
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
1242
|
|
|
if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) |
1243
|
|
|
continue; |
1244
|
|
|
} |
1245
|
|
|
|
1246
|
|
|
$value = ''; |
1247
|
|
|
|
1248
|
|
View Code Duplication |
if ( !empty( $pod ) ) |
1249
|
|
|
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) ); |
1250
|
|
|
elseif ( !empty( $id ) ) { |
1251
|
|
|
pods_no_conflict_on( 'post' ); |
1252
|
|
|
|
1253
|
|
|
$value = get_post_meta( $id, $field[ 'name' ], true ); |
1254
|
|
|
|
1255
|
|
|
pods_no_conflict_off( 'post' ); |
1256
|
|
|
} |
1257
|
|
|
|
1258
|
|
|
$form_fields[ 'pods_meta_' . $field[ 'name' ] ] = array( |
1259
|
|
|
'label' => $field[ 'label' ], |
1260
|
|
|
'input' => 'html', |
1261
|
|
|
'html' => PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ) . $meta_nonce, |
1262
|
|
|
'helps' => PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ) |
1263
|
|
|
); |
1264
|
|
|
} |
1265
|
|
|
} |
1266
|
|
|
|
1267
|
|
|
$form_fields = apply_filters( 'pods_meta_' . __FUNCTION__, $form_fields ); |
1268
|
|
|
|
1269
|
|
|
return $form_fields; |
1270
|
|
|
} |
1271
|
|
|
|
1272
|
|
|
/** |
1273
|
|
|
* @param $post |
1274
|
|
|
* @param $attachment |
1275
|
|
|
* |
1276
|
|
|
* @return mixed |
1277
|
|
|
*/ |
1278
|
|
|
public function save_media ( $post, $attachment ) { |
1279
|
|
|
$groups = $this->groups_get( 'media', 'media' ); |
1280
|
|
|
|
1281
|
|
|
if ( empty( $groups ) ) |
1282
|
|
|
return $post; |
1283
|
|
|
|
1284
|
|
|
$post_id = $attachment; |
1285
|
|
|
|
1286
|
|
|
if ( empty( $_POST ) || !wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_media' ) ) { |
1287
|
|
|
return $post; |
1288
|
|
|
} |
1289
|
|
|
|
1290
|
|
View Code Duplication |
if ( is_array( $post ) && !empty( $post ) && isset( $post[ 'ID' ] ) && 'attachment' == $post[ 'post_type' ] ) |
1291
|
|
|
$post_id = $post[ 'ID' ]; |
1292
|
|
|
|
1293
|
|
|
if ( is_array( $post_id ) || empty( $post_id ) ) |
1294
|
|
|
return $post; |
1295
|
|
|
|
1296
|
|
|
$data = array(); |
1297
|
|
|
|
1298
|
|
|
$id = $post_id; |
1299
|
|
|
$pod = null; |
1300
|
|
|
|
1301
|
|
View Code Duplication |
foreach ( $groups as $group ) { |
1302
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
1303
|
|
|
continue; |
1304
|
|
|
|
1305
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
1306
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) |
1307
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
1308
|
|
|
elseif ( self::$current_pod->id() != $id ) |
1309
|
|
|
self::$current_pod->fetch( $id ); |
1310
|
|
|
|
1311
|
|
|
$pod = self::$current_pod; |
1312
|
|
|
} |
1313
|
|
|
|
1314
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
1315
|
|
|
|
1316
|
|
|
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
1317
|
|
|
if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) |
1318
|
|
|
continue; |
1319
|
|
|
} |
1320
|
|
|
|
1321
|
|
|
$data[ $field[ 'name' ] ] = ''; |
1322
|
|
|
|
1323
|
|
|
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) ) |
1324
|
|
|
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ]; |
1325
|
|
|
} |
1326
|
|
|
} |
1327
|
|
|
|
1328
|
|
|
do_action( 'pods_meta_save_pre_media', $data, $pod, $id, $groups, $post, $attachment ); |
1329
|
|
|
|
1330
|
|
View Code Duplication |
if ( !empty( $pod ) ) { |
1331
|
|
|
// Fix for Pods doing it's own sanitization |
1332
|
|
|
$data = pods_unslash( (array) $data ); |
1333
|
|
|
|
1334
|
|
|
$pod->save( $data ); |
1335
|
|
|
} |
1336
|
|
|
elseif ( !empty( $id ) ) { |
1337
|
|
|
pods_no_conflict_on( 'post' ); |
1338
|
|
|
|
1339
|
|
|
foreach ( $data as $field => $value ) { |
1340
|
|
|
update_post_meta( $id, $field, $value ); |
1341
|
|
|
} |
1342
|
|
|
|
1343
|
|
|
pods_no_conflict_off( 'post' ); |
1344
|
|
|
} |
1345
|
|
|
|
1346
|
|
|
do_action( 'pods_meta_save_media', $data, $pod, $id, $groups, $post, $attachment ); |
1347
|
|
|
|
1348
|
|
|
return $post; |
1349
|
|
|
} |
1350
|
|
|
|
1351
|
|
|
public function save_media_ajax () { |
1352
|
|
|
if ( !isset( $_POST[ 'id' ] ) || empty( $_POST[ 'id' ] ) || absint( $_POST[ 'id' ] ) < 1 ) |
1353
|
|
|
return; |
1354
|
|
|
|
1355
|
|
|
$id = absint( $_POST[ 'id' ] ); |
1356
|
|
|
|
1357
|
|
|
if ( !isset( $_POST[ 'nonce' ] ) || empty( $_POST[ 'nonce' ] ) ) |
1358
|
|
|
return; |
1359
|
|
|
|
1360
|
|
|
check_ajax_referer( 'update-post_' . $id, 'nonce' ); |
1361
|
|
|
|
1362
|
|
|
if ( !current_user_can( 'edit_post', $id ) ) |
1363
|
|
|
return; |
1364
|
|
|
|
1365
|
|
|
$post = get_post( $id, ARRAY_A ); |
1366
|
|
|
|
1367
|
|
|
if ( 'attachment' != $post[ 'post_type' ] ) |
1368
|
|
|
return; |
1369
|
|
|
|
1370
|
|
|
// fix ALL THE THINGS |
1371
|
|
|
|
1372
|
|
|
if ( !isset( $_REQUEST[ 'attachments' ] ) ) |
1373
|
|
|
$_REQUEST[ 'attachments' ] = array(); |
1374
|
|
|
|
1375
|
|
|
if ( !isset( $_REQUEST[ 'attachments' ][ $id ] ) ) |
1376
|
|
|
$_REQUEST[ 'attachments' ][ $id ] = array(); |
1377
|
|
|
|
1378
|
|
|
if ( empty( $_REQUEST[ 'attachments' ][ $id ] ) ) |
1379
|
|
|
$_REQUEST[ 'attachments' ][ $id ][ '_fix_wp' ] = 1; |
1380
|
|
|
} |
1381
|
|
|
|
1382
|
|
|
/** |
1383
|
|
|
* @param $tag |
1384
|
|
|
* @param null $taxonomy |
1385
|
|
|
*/ |
1386
|
|
|
public function meta_taxonomy ( $tag, $taxonomy = null ) { |
1387
|
|
|
wp_enqueue_style( 'pods-form' ); |
1388
|
|
|
|
1389
|
|
|
do_action( 'pods_meta_' . __FUNCTION__, $tag, $taxonomy ); |
1390
|
|
|
|
1391
|
|
|
$taxonomy_name = $taxonomy; |
1392
|
|
|
|
1393
|
|
|
if ( !is_object( $tag ) ) |
1394
|
|
|
$taxonomy_name = $tag; |
1395
|
|
|
|
1396
|
|
|
$groups = $this->groups_get( 'taxonomy', $taxonomy_name ); |
1397
|
|
|
|
1398
|
|
|
$id = null; |
1399
|
|
|
|
1400
|
|
|
if ( is_object( $tag ) ) |
1401
|
|
|
$id = $tag->term_id; |
1402
|
|
|
|
1403
|
|
|
$pod = null; |
1404
|
|
|
|
1405
|
|
|
echo PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_taxonomy' ), 'hidden' ); |
1406
|
|
|
|
1407
|
|
|
foreach ( $groups as $group ) { |
1408
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
1409
|
|
|
continue; |
1410
|
|
|
|
1411
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
1412
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) |
1413
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
1414
|
|
|
elseif ( self::$current_pod->id() != $id ) |
1415
|
|
|
self::$current_pod->fetch( $id ); |
1416
|
|
|
|
1417
|
|
|
$pod = self::$current_pod; |
1418
|
|
|
} |
1419
|
|
|
|
1420
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
1421
|
|
View Code Duplication |
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
1422
|
|
|
if ( pods_var( 'hidden', $field[ 'options' ], false ) ) |
1423
|
|
|
$field[ 'type' ] = 'hidden'; |
1424
|
|
|
else |
1425
|
|
|
continue; |
1426
|
|
|
} |
1427
|
|
|
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) ) |
1428
|
|
|
$field[ 'type' ] = 'hidden'; |
1429
|
|
|
|
1430
|
|
|
$value = ''; |
1431
|
|
|
|
1432
|
|
View Code Duplication |
if ( !empty( $pod ) ) |
1433
|
|
|
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) ); |
1434
|
|
|
|
1435
|
|
|
if ( !is_object( $tag ) ) { |
1436
|
|
|
?> |
1437
|
|
|
<div class="form-field pods-field" style="<?php echo esc_attr( 'hidden' == $field[ 'type' ] ? 'display:none;' : '' ); ?>"> |
1438
|
|
|
<?php |
1439
|
|
|
echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); |
1440
|
|
|
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); |
1441
|
|
|
echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); |
1442
|
|
|
?> |
1443
|
|
|
</div> |
1444
|
|
|
<?php |
1445
|
|
|
} |
1446
|
|
|
else { |
1447
|
|
|
?> |
1448
|
|
|
<tr class="form-field pods-field <?php echo esc_attr( 'pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ], true ) ); ?>" style="<?php echo esc_attr( 'hidden' == $field[ 'type' ] ? 'display:none;' : '' ); ?>"> |
1449
|
|
|
<th scope="row" valign="top"><?php echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?></th> |
1450
|
|
|
<td> |
1451
|
|
|
<?php |
1452
|
|
|
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); |
1453
|
|
|
echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); |
1454
|
|
|
?> |
1455
|
|
|
</td> |
1456
|
|
|
</tr> |
1457
|
|
|
<?php |
1458
|
|
|
} |
1459
|
|
|
} |
1460
|
|
|
} |
1461
|
|
|
|
1462
|
|
|
do_action( 'pods_meta_' . __FUNCTION__ . '_post', $tag, $taxonomy ); |
1463
|
|
|
} |
1464
|
|
|
|
1465
|
|
|
/** |
1466
|
|
|
* @param $term_id |
1467
|
|
|
* @param $term_taxonomy_id |
1468
|
|
|
* @param $taxonomy |
1469
|
|
|
*/ |
1470
|
|
|
public function save_taxonomy ( $term_id, $term_taxonomy_id, $taxonomy ) { |
1471
|
|
|
$is_new_item = false; |
1472
|
|
|
|
1473
|
|
|
if ( 'create_term' == current_filter() ) |
1474
|
|
|
$is_new_item = true; |
1475
|
|
|
|
1476
|
|
|
if ( empty( $_POST ) || !wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_taxonomy' ) ) { |
1477
|
|
|
return $term_id; |
1478
|
|
|
} |
1479
|
|
|
|
1480
|
|
|
// Block Quick Edits / Bulk Edits |
1481
|
|
|
if ( 'inline-save-tax' == pods_var( 'action', 'post' ) || null != pods_var( 'delete_tags', 'post' ) ) { |
1482
|
|
|
return $term_id; |
1483
|
|
|
} |
1484
|
|
|
|
1485
|
|
|
$groups = $this->groups_get( 'taxonomy', $taxonomy ); |
1486
|
|
|
|
1487
|
|
|
if ( empty( $groups ) ) |
1488
|
|
|
return $term_id; |
1489
|
|
|
|
1490
|
|
|
$term = null; |
1491
|
|
|
|
1492
|
|
|
$id = $term_id; |
1493
|
|
|
$pod = null; |
1494
|
|
|
|
1495
|
|
|
$has_fields = false; |
1496
|
|
|
|
1497
|
|
|
foreach ( $groups as $group ) { |
1498
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
1499
|
|
|
continue; |
1500
|
|
|
|
1501
|
|
|
if ( null === $term ) { |
1502
|
|
|
$term = get_term( $term_id, $taxonomy ); |
1503
|
|
|
|
1504
|
|
|
$data = array( |
1505
|
|
|
'name' => $term->name |
1506
|
|
|
); |
1507
|
|
|
} |
1508
|
|
|
|
1509
|
|
|
$has_fields = true; |
1510
|
|
|
|
1511
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
1512
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) |
1513
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
1514
|
|
|
elseif ( self::$current_pod->id() != $id ) |
1515
|
|
|
self::$current_pod->fetch( $id ); |
1516
|
|
|
|
1517
|
|
|
$pod = self::$current_pod; |
1518
|
|
|
} |
1519
|
|
|
|
1520
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
1521
|
|
|
|
1522
|
|
|
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
1523
|
|
|
if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) |
1524
|
|
|
continue; |
1525
|
|
|
} |
1526
|
|
|
|
1527
|
|
|
$data[ $field[ 'name' ] ] = ''; |
|
|
|
|
1528
|
|
|
|
1529
|
|
|
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) ) |
1530
|
|
|
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ]; |
1531
|
|
|
} |
1532
|
|
|
} |
1533
|
|
|
|
1534
|
|
|
if ( !$has_fields ) { |
1535
|
|
|
return $term_id; |
1536
|
|
|
} |
1537
|
|
|
|
1538
|
|
View Code Duplication |
if ( $is_new_item ) { |
1539
|
|
|
do_action( 'pods_meta_create_pre_taxonomy', $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy ); |
1540
|
|
|
do_action( "pods_meta_create_pre_taxonomy_{$taxonomy}", $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy ); |
1541
|
|
|
} |
1542
|
|
|
|
1543
|
|
|
do_action( 'pods_meta_save_pre_taxonomy', $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item ); |
1544
|
|
|
do_action( "pods_meta_save_pre_taxonomy_{$taxonomy}", $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item ); |
1545
|
|
|
|
1546
|
|
|
pods_no_conflict_on( 'taxonomy' ); |
1547
|
|
|
|
1548
|
|
|
if ( !empty( $pod ) ) { |
1549
|
|
|
// Fix for Pods doing it's own sanitization |
1550
|
|
|
$data = pods_unslash( (array) $data ); |
1551
|
|
|
|
1552
|
|
|
$pod->save( $data, null, null, array( 'is_new_item' => $is_new_item ) ); |
1553
|
|
|
} |
1554
|
|
|
|
1555
|
|
|
pods_no_conflict_off( 'taxonomy' ); |
1556
|
|
|
|
1557
|
|
View Code Duplication |
if ( $is_new_item ) { |
1558
|
|
|
do_action( 'pods_meta_create_taxonomy', $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy ); |
1559
|
|
|
do_action( "pods_meta_create_taxonomy_{$taxonomy}", $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy ); |
1560
|
|
|
} |
1561
|
|
|
|
1562
|
|
|
do_action( 'pods_meta_save_taxonomy', $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item ); |
1563
|
|
|
do_action( "pods_meta_save_taxonomy_{$taxonomy}", $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item ); |
1564
|
|
|
|
1565
|
|
|
return $term_id; |
1566
|
|
|
} |
1567
|
|
|
|
1568
|
|
|
/** |
1569
|
|
|
* @param $user_id |
1570
|
|
|
*/ |
1571
|
|
|
public function meta_user ( $user_id ) { |
1572
|
|
|
wp_enqueue_style( 'pods-form' ); |
1573
|
|
|
|
1574
|
|
|
do_action( 'pods_meta_' . __FUNCTION__, $user_id ); |
1575
|
|
|
|
1576
|
|
|
$groups = $this->groups_get( 'user', 'user' ); |
1577
|
|
|
|
1578
|
|
|
if ( is_object( $user_id ) ) |
1579
|
|
|
$user_id = $user_id->ID; |
1580
|
|
|
|
1581
|
|
|
$id = $user_id; |
1582
|
|
|
$pod = null; |
1583
|
|
|
|
1584
|
|
|
foreach ( $groups as $group ) { |
1585
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
1586
|
|
|
continue; |
1587
|
|
|
|
1588
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
1589
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) |
1590
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
1591
|
|
|
elseif ( self::$current_pod->id() != $id ) |
1592
|
|
|
self::$current_pod->fetch( $id ); |
1593
|
|
|
|
1594
|
|
|
$pod = self::$current_pod; |
1595
|
|
|
} |
1596
|
|
|
|
1597
|
|
|
$hidden_fields = array(); |
1598
|
|
|
?> |
1599
|
|
|
<h3><?php echo $group[ 'label' ]; ?></h3> |
1600
|
|
|
|
1601
|
|
|
<?php echo PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_user' ), 'hidden' ); ?> |
1602
|
|
|
|
1603
|
|
|
<table class="form-table pods-meta"> |
1604
|
|
|
<tbody> |
1605
|
|
|
<?php |
1606
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
1607
|
|
|
|
1608
|
|
View Code Duplication |
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
1609
|
|
|
if ( pods_var( 'hidden', $field[ 'options' ], false ) ) |
1610
|
|
|
$field[ 'type' ] = 'hidden'; |
1611
|
|
|
else |
1612
|
|
|
continue; |
1613
|
|
|
} |
1614
|
|
|
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) ) |
1615
|
|
|
$field[ 'type' ] = 'hidden'; |
1616
|
|
|
|
1617
|
|
|
$value = ''; |
1618
|
|
|
|
1619
|
|
View Code Duplication |
if ( !empty( $pod ) ) |
1620
|
|
|
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) ); |
1621
|
|
|
elseif ( !empty( $id ) ) { |
1622
|
|
|
pods_no_conflict_on( 'user' ); |
1623
|
|
|
|
1624
|
|
|
$value = get_user_meta( $id, $field[ 'name' ], true ); |
1625
|
|
|
|
1626
|
|
|
pods_no_conflict_off( 'user' ); |
1627
|
|
|
} |
1628
|
|
|
|
1629
|
|
View Code Duplication |
if ( 'hidden' == $field[ 'type' ] ) { |
1630
|
|
|
$hidden_fields[] = array( |
1631
|
|
|
'field' => $field, |
1632
|
|
|
'value' => $value |
1633
|
|
|
); |
1634
|
|
|
} |
1635
|
|
|
else { |
1636
|
|
|
?> |
1637
|
|
|
<tr class="form-field pods-field <?php echo esc_attr( 'pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ], true ) ); ?>"> |
1638
|
|
|
<th scope="row" valign="top"><?php echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?></th> |
1639
|
|
|
<td> |
1640
|
|
|
<?php echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); ?> |
1641
|
|
|
<?php echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); ?> |
1642
|
|
|
</td> |
1643
|
|
|
</tr> |
1644
|
|
|
<?php |
1645
|
|
|
} |
1646
|
|
|
} |
1647
|
|
|
?> |
1648
|
|
|
</tbody> |
1649
|
|
|
</table> |
1650
|
|
|
<?php |
1651
|
|
View Code Duplication |
foreach ( $hidden_fields as $hidden_field ) { |
1652
|
|
|
$field = $hidden_field[ 'field' ]; |
1653
|
|
|
|
1654
|
|
|
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $hidden_field[ 'value' ], 'hidden' ); |
1655
|
|
|
} |
1656
|
|
|
} |
1657
|
|
|
|
1658
|
|
|
do_action( 'pods_meta_' . __FUNCTION__ . '_post', $user_id ); |
1659
|
|
|
} |
1660
|
|
|
|
1661
|
|
|
/** |
1662
|
|
|
* @param $user_id |
1663
|
|
|
*/ |
1664
|
|
|
public function save_user ( $user_id ) { |
1665
|
|
|
|
1666
|
|
|
$is_new_item = false; |
1667
|
|
|
|
1668
|
|
|
if ( 'user_register' == current_filter() ) { |
1669
|
|
|
$is_new_item = true; |
1670
|
|
|
} |
1671
|
|
|
|
1672
|
|
View Code Duplication |
if ( empty( $_POST ) ) { |
1673
|
|
|
return $user_id; |
1674
|
|
|
} |
1675
|
|
|
elseif ( $is_new_item || !wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_user' ) ) { |
1676
|
|
|
return $user_id; |
1677
|
|
|
} |
1678
|
|
|
|
1679
|
|
|
$groups = $this->groups_get( 'user', 'user' ); |
1680
|
|
|
|
1681
|
|
|
if ( empty( $groups ) ) { |
1682
|
|
|
return $user_id; |
1683
|
|
|
} |
1684
|
|
|
|
1685
|
|
|
if ( is_object( $user_id ) ) { |
1686
|
|
|
$user_id = $user_id->ID; |
1687
|
|
|
} |
1688
|
|
|
|
1689
|
|
|
$data = array(); |
1690
|
|
|
|
1691
|
|
|
$id = $user_id; |
1692
|
|
|
$pod = null; |
1693
|
|
|
|
1694
|
|
View Code Duplication |
foreach ( $groups as $group ) { |
1695
|
|
|
if ( empty( $group[ 'fields' ] ) ) { |
1696
|
|
|
continue; |
1697
|
|
|
} |
1698
|
|
|
|
1699
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
1700
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) { |
1701
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
1702
|
|
|
} |
1703
|
|
|
elseif ( self::$current_pod->id() != $id ) { |
1704
|
|
|
self::$current_pod->fetch( $id ); |
1705
|
|
|
} |
1706
|
|
|
|
1707
|
|
|
$pod = self::$current_pod; |
1708
|
|
|
} |
1709
|
|
|
|
1710
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
1711
|
|
|
|
1712
|
|
|
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
1713
|
|
|
if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) { |
1714
|
|
|
continue; |
1715
|
|
|
} |
1716
|
|
|
} |
1717
|
|
|
|
1718
|
|
|
$data[ $field[ 'name' ] ] = ''; |
1719
|
|
|
|
1720
|
|
|
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) ) { |
1721
|
|
|
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ]; |
1722
|
|
|
} |
1723
|
|
|
} |
1724
|
|
|
} |
1725
|
|
|
|
1726
|
|
|
if ( $is_new_item ) { |
1727
|
|
|
do_action( 'pods_meta_create_pre_user', $data, $pod, $id, $groups ); |
1728
|
|
|
} |
1729
|
|
|
|
1730
|
|
|
do_action( 'pods_meta_save_pre_user', $data, $pod, $id, $groups, $is_new_item ); |
1731
|
|
|
|
1732
|
|
|
pods_no_conflict_on( 'user' ); |
1733
|
|
|
|
1734
|
|
View Code Duplication |
if ( !empty( $pod ) ) { |
1735
|
|
|
// Fix for Pods doing it's own sanitization |
1736
|
|
|
$data = pods_unslash( (array) $data ); |
1737
|
|
|
|
1738
|
|
|
$pod->save( $data, null, null, array( 'is_new_item' => $is_new_item ) ); |
1739
|
|
|
} |
1740
|
|
|
elseif ( !empty( $id ) ) { |
1741
|
|
|
foreach ( $data as $field => $value ) { |
1742
|
|
|
update_user_meta( $id, $field, $value ); |
1743
|
|
|
} |
1744
|
|
|
} |
1745
|
|
|
|
1746
|
|
|
pods_no_conflict_off( 'user' ); |
1747
|
|
|
|
1748
|
|
|
if ( $is_new_item ) { |
1749
|
|
|
do_action( 'pods_meta_create_user', $data, $pod, $id, $groups ); |
1750
|
|
|
} |
1751
|
|
|
|
1752
|
|
|
do_action( 'pods_meta_save_user', $data, $pod, $id, $groups, $is_new_item ); |
1753
|
|
|
|
1754
|
|
|
return $user_id; |
1755
|
|
|
|
1756
|
|
|
} |
1757
|
|
|
|
1758
|
|
|
/** |
1759
|
|
|
* @param $commenter |
1760
|
|
|
* @param $user_identity |
1761
|
|
|
*/ |
1762
|
|
|
public function meta_comment_new_logged_in ( $commenter, $user_identity ) { |
1763
|
|
|
wp_enqueue_style( 'pods-form' ); |
1764
|
|
|
|
1765
|
|
|
do_action( 'pods_meta_' . __FUNCTION__, $commenter, $user_identity ); |
1766
|
|
|
|
1767
|
|
|
$groups = $this->groups_get( 'comment', 'comment' ); |
1768
|
|
|
|
1769
|
|
|
$id = null; |
1770
|
|
|
$pod = null; |
1771
|
|
|
|
1772
|
|
|
echo PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_comment' ), 'hidden' ); |
1773
|
|
|
|
1774
|
|
|
foreach ( $groups as $group ) { |
1775
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
1776
|
|
|
continue; |
1777
|
|
|
|
1778
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
1779
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) |
1780
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
1781
|
|
|
elseif ( self::$current_pod->id() != $id ) |
1782
|
|
|
self::$current_pod->fetch( $id ); |
1783
|
|
|
|
1784
|
|
|
$pod = self::$current_pod; |
1785
|
|
|
} |
1786
|
|
|
|
1787
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
1788
|
|
View Code Duplication |
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
1789
|
|
|
if ( pods_var( 'hidden', $field[ 'options' ], false ) ) |
1790
|
|
|
$field[ 'type' ] = 'hidden'; |
1791
|
|
|
else |
1792
|
|
|
continue; |
1793
|
|
|
} |
1794
|
|
|
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) ) |
1795
|
|
|
$field[ 'type' ] = 'hidden'; |
1796
|
|
|
|
1797
|
|
|
$value = ''; |
1798
|
|
|
|
1799
|
|
View Code Duplication |
if ( !empty( $pod ) ) |
1800
|
|
|
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) ); |
1801
|
|
|
elseif ( !empty( $id ) ) { |
1802
|
|
|
pods_no_conflict_on( 'comment' ); |
1803
|
|
|
|
1804
|
|
|
$value = get_comment_meta( $id, $field[ 'name' ], true ); |
1805
|
|
|
|
1806
|
|
|
pods_no_conflict_off( 'comment' ); |
1807
|
|
|
} |
1808
|
|
|
?> |
1809
|
|
|
<p class="comment-form-author comment-form-pods-meta-<?php echo esc_attr( $field[ 'name' ] ); ?> pods-field" style="<?php echo esc_attr( 'hidden' == $field[ 'type' ] ? 'display:none;' : '' ); ?>"> |
1810
|
|
|
<?php |
1811
|
|
|
echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); |
1812
|
|
|
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); |
1813
|
|
|
echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); |
1814
|
|
|
?> |
1815
|
|
|
</p> |
1816
|
|
|
<?php |
1817
|
|
|
} |
1818
|
|
|
} |
1819
|
|
|
|
1820
|
|
|
do_action( 'pods_meta_' . __FUNCTION__ . '_post', $commenter, $user_identity ); |
1821
|
|
|
} |
1822
|
|
|
|
1823
|
|
|
/** |
1824
|
|
|
* @param $form_fields |
1825
|
|
|
* |
1826
|
|
|
* @return array |
1827
|
|
|
*/ |
1828
|
|
|
public function meta_comment_new ( $form_fields ) { |
1829
|
|
|
wp_enqueue_style( 'pods-form' ); |
1830
|
|
|
|
1831
|
|
|
$groups = $this->groups_get( 'comment', 'comment' ); |
1832
|
|
|
|
1833
|
|
|
$id = null; |
1834
|
|
|
$pod = null; |
1835
|
|
|
|
1836
|
|
|
$form_fields[ 'pods_meta' ] = PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_comment' ), 'hidden' ); |
1837
|
|
|
|
1838
|
|
|
foreach ( $groups as $group ) { |
1839
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
1840
|
|
|
continue; |
1841
|
|
|
|
1842
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
1843
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) |
1844
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
1845
|
|
|
elseif ( self::$current_pod->id() != $id ) |
1846
|
|
|
self::$current_pod->fetch( $id ); |
1847
|
|
|
|
1848
|
|
|
$pod = self::$current_pod; |
1849
|
|
|
} |
1850
|
|
|
|
1851
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
1852
|
|
|
|
1853
|
|
View Code Duplication |
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
1854
|
|
|
if ( pods_var( 'hidden', $field[ 'options' ], false ) ) |
1855
|
|
|
$field[ 'type' ] = 'hidden'; |
1856
|
|
|
else |
1857
|
|
|
continue; |
1858
|
|
|
} |
1859
|
|
|
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) ) |
1860
|
|
|
$field[ 'type' ] = 'hidden'; |
1861
|
|
|
|
1862
|
|
|
$value = ''; |
1863
|
|
|
|
1864
|
|
View Code Duplication |
if ( !empty( $pod ) ) |
1865
|
|
|
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) ); |
1866
|
|
|
elseif ( !empty( $id ) ) { |
1867
|
|
|
pods_no_conflict_on( 'comment' ); |
1868
|
|
|
|
1869
|
|
|
$value = get_comment_meta( $id, $field[ 'name' ], true ); |
1870
|
|
|
|
1871
|
|
|
pods_no_conflict_off( 'comment' ); |
1872
|
|
|
} |
1873
|
|
|
|
1874
|
|
|
ob_start(); |
1875
|
|
|
?> |
1876
|
|
|
<p class="comment-form-author comment-form-pods-meta-<?php echo esc_attr( $field[ 'name' ] ); ?> pods-field" style="<?php echo esc_attr( 'hidden' == $field[ 'type' ] ? 'display:none;' : '' ); ?>"> |
1877
|
|
|
<?php |
1878
|
|
|
echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); |
1879
|
|
|
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); |
1880
|
|
|
echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); |
1881
|
|
|
?> |
1882
|
|
|
</p> |
1883
|
|
|
<?php |
1884
|
|
|
$form_fields[ 'pods_meta_' . $field[ 'name' ] ] = ob_get_clean(); |
1885
|
|
|
} |
1886
|
|
|
} |
1887
|
|
|
|
1888
|
|
|
$form_fields = apply_filters( 'pods_meta_' . __FUNCTION__, $form_fields ); |
1889
|
|
|
|
1890
|
|
|
return $form_fields; |
1891
|
|
|
} |
1892
|
|
|
|
1893
|
|
|
/** |
1894
|
|
|
* @param $comment_type |
1895
|
|
|
* @param null $comment |
1896
|
|
|
*/ |
1897
|
|
|
public function meta_comment_add ( $comment_type, $comment = null ) { |
1898
|
|
|
if ( is_object( $comment ) && isset( $comment_type->comment_type ) ) |
1899
|
|
|
$comment_type = $comment->comment_type; |
1900
|
|
|
|
1901
|
|
|
if ( is_object( $comment_type ) && isset( $comment_type->comment_type ) ) { |
1902
|
|
|
$comment = $comment_type; |
1903
|
|
|
$comment_type = $comment_type->comment_type; |
1904
|
|
|
} |
1905
|
|
|
|
1906
|
|
|
if ( is_object( $comment_type ) ) |
1907
|
|
|
return; |
1908
|
|
|
elseif ( empty( $comment_type ) ) |
1909
|
|
|
$comment_type = 'comment'; |
1910
|
|
|
|
1911
|
|
|
$groups = $this->groups_get( 'comment', $comment_type ); |
1912
|
|
|
|
1913
|
|
|
foreach ( $groups as $group ) { |
1914
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
1915
|
|
|
continue; |
1916
|
|
|
|
1917
|
|
|
$field_found = false; |
1918
|
|
|
|
1919
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
1920
|
|
|
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], null, null ) ) { |
1921
|
|
|
if ( pods_var( 'hidden', $field[ 'options' ], false ) ) { |
1922
|
|
|
$field_found = true; |
1923
|
|
|
break; |
1924
|
|
|
} |
1925
|
|
|
else { |
1926
|
|
|
continue; |
1927
|
|
|
} |
1928
|
|
|
} |
1929
|
|
|
else { |
1930
|
|
|
$field_found = true; |
1931
|
|
|
break; |
1932
|
|
|
} |
1933
|
|
|
} |
1934
|
|
|
|
1935
|
|
View Code Duplication |
if ( $field_found ) { |
1936
|
|
|
add_meta_box( |
1937
|
|
|
'pods-meta-' . sanitize_title( $group[ 'label' ] ), |
1938
|
|
|
$group[ 'label' ], |
1939
|
|
|
array( $this, 'meta_comment' ), |
1940
|
|
|
$comment_type, |
1941
|
|
|
$group[ 'context' ], |
1942
|
|
|
$group[ 'priority' ], |
1943
|
|
|
array( 'group' => $group ) |
1944
|
|
|
); |
1945
|
|
|
} |
1946
|
|
|
} |
1947
|
|
|
} |
1948
|
|
|
|
1949
|
|
|
/** |
1950
|
|
|
* @param $comment |
1951
|
|
|
* @param $metabox |
1952
|
|
|
*/ |
1953
|
|
|
public function meta_comment ( $comment, $metabox ) { |
1954
|
|
|
wp_enqueue_style( 'pods-form' ); |
1955
|
|
|
|
1956
|
|
|
do_action( 'pods_meta_' . __FUNCTION__, $comment, $metabox ); |
1957
|
|
|
|
1958
|
|
|
$hidden_fields = array(); |
1959
|
|
|
|
1960
|
|
|
echo PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_comment' ), 'hidden' ); |
1961
|
|
|
?> |
1962
|
|
|
<table class="form-table editcomment pods-metabox"> |
1963
|
|
|
<?php |
1964
|
|
|
$id = null; |
1965
|
|
|
|
1966
|
|
|
if ( is_object( $comment ) ) |
1967
|
|
|
$id = $comment->comment_ID; |
1968
|
|
|
|
1969
|
|
View Code Duplication |
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $metabox[ 'args' ][ 'group' ][ 'pod' ][ 'name' ] ) |
1970
|
|
|
self::$current_pod = pods( $metabox[ 'args' ][ 'group' ][ 'pod' ][ 'name' ], $id, true ); |
1971
|
|
|
elseif ( self::$current_pod->id() != $id ) |
1972
|
|
|
self::$current_pod->fetch( $id ); |
1973
|
|
|
|
1974
|
|
|
$pod = self::$current_pod; |
1975
|
|
|
|
1976
|
|
|
foreach ( $metabox[ 'args' ][ 'group' ][ 'fields' ] as $field ) { |
1977
|
|
View Code Duplication |
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $metabox[ 'args' ][ 'group' ][ 'fields' ], $pod, $id ) ) { |
1978
|
|
|
if ( pods_var( 'hidden', $field[ 'options' ], false ) ) |
1979
|
|
|
$field[ 'type' ] = 'hidden'; |
1980
|
|
|
else |
1981
|
|
|
continue; |
1982
|
|
|
} |
1983
|
|
|
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) ) |
1984
|
|
|
$field[ 'type' ] = 'hidden'; |
1985
|
|
|
|
1986
|
|
|
$value = ''; |
1987
|
|
|
|
1988
|
|
View Code Duplication |
if ( !empty( $pod ) ) |
1989
|
|
|
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) ); |
1990
|
|
|
|
1991
|
|
View Code Duplication |
if ( 'hidden' == $field[ 'type' ] ) { |
1992
|
|
|
$hidden_fields[] = array( |
1993
|
|
|
'field' => $field, |
1994
|
|
|
'value' => $value |
1995
|
|
|
); |
1996
|
|
|
} |
1997
|
|
|
else { |
1998
|
|
|
?> |
1999
|
|
|
<tr class="form-field pods-field <?php echo esc_attr( 'pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ], true ) ); ?>"> |
2000
|
|
|
<th scope="row" valign="top"><?php echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?></th> |
2001
|
|
|
<td> |
2002
|
|
|
<?php echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); ?> |
2003
|
|
|
<?php echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); ?> |
2004
|
|
|
</td> |
2005
|
|
|
</tr> |
2006
|
|
|
<?php |
2007
|
|
|
} |
2008
|
|
|
} |
2009
|
|
|
?> |
2010
|
|
|
</table> |
2011
|
|
|
<?php |
2012
|
|
View Code Duplication |
foreach ( $hidden_fields as $hidden_field ) { |
2013
|
|
|
$field = $hidden_field[ 'field' ]; |
2014
|
|
|
|
2015
|
|
|
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $hidden_field[ 'value' ], 'hidden' ); |
2016
|
|
|
} |
2017
|
|
|
|
2018
|
|
|
do_action( 'pods_meta_' . __FUNCTION__ . '_post', $comment, $metabox ); |
2019
|
|
|
} |
2020
|
|
|
|
2021
|
|
|
/** |
2022
|
|
|
* @param $approved |
2023
|
|
|
* @param $commentdata |
2024
|
|
|
*/ |
2025
|
|
|
public function validate_comment ( $approved, $commentdata ) { |
|
|
|
|
2026
|
|
|
$groups = $this->groups_get( 'comment', 'comment' ); |
2027
|
|
|
|
2028
|
|
|
if ( empty( $groups ) ) |
2029
|
|
|
return $approved; |
2030
|
|
|
|
2031
|
|
|
$data = array(); |
2032
|
|
|
|
2033
|
|
|
$pod = null; |
2034
|
|
|
$id = null; |
2035
|
|
|
|
2036
|
|
|
foreach ( $groups as $group ) { |
2037
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
2038
|
|
|
continue; |
2039
|
|
|
|
2040
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
2041
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) |
2042
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
2043
|
|
|
elseif ( self::$current_pod->id() != $id ) |
2044
|
|
|
self::$current_pod->fetch( $id ); |
2045
|
|
|
|
2046
|
|
|
$pod = self::$current_pod; |
2047
|
|
|
} |
2048
|
|
|
|
2049
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
2050
|
|
|
|
2051
|
|
|
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
2052
|
|
|
if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) |
2053
|
|
|
continue; |
2054
|
|
|
} |
2055
|
|
|
|
2056
|
|
|
$data[ $field[ 'name' ] ] = ''; |
2057
|
|
|
|
2058
|
|
|
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) ) |
2059
|
|
|
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ]; |
2060
|
|
|
|
2061
|
|
|
$validate = pods_api()->handle_field_validation( $data[ $field[ 'name' ] ], $field[ 'name' ], pods_api()->get_wp_object_fields( 'comment' ), $pod->fields(), $pod, array() ); |
2062
|
|
|
|
2063
|
|
|
if ( false === $validate ) |
2064
|
|
|
$validate = sprintf( __( 'There was an issue validating the field %s', 'pods' ), $field[ 'label' ] ); |
2065
|
|
|
|
2066
|
|
|
if ( !is_bool( $validate ) && !empty( $validate ) ) |
2067
|
|
|
return pods_error( $validate, $this ); |
2068
|
|
|
} |
2069
|
|
|
} |
2070
|
|
|
|
2071
|
|
|
return $approved; |
2072
|
|
|
} |
2073
|
|
|
|
2074
|
|
|
/** |
2075
|
|
|
* @param $comment_id |
2076
|
|
|
*/ |
2077
|
|
|
public function save_comment ( $comment_id ) { |
2078
|
|
|
$groups = $this->groups_get( 'comment', 'comment' ); |
2079
|
|
|
|
2080
|
|
View Code Duplication |
if ( empty( $groups ) ) { |
2081
|
|
|
return $comment_id; |
2082
|
|
|
} |
2083
|
|
|
elseif ( empty( $_POST ) ) { |
2084
|
|
|
return $comment_id; |
2085
|
|
|
} |
2086
|
|
|
elseif ( !wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_comment' ) ) { |
2087
|
|
|
return $comment_id; |
2088
|
|
|
} |
2089
|
|
|
|
2090
|
|
|
$data = array(); |
2091
|
|
|
|
2092
|
|
|
$id = $comment_id; |
2093
|
|
|
$pod = null; |
2094
|
|
|
|
2095
|
|
View Code Duplication |
foreach ( $groups as $group ) { |
2096
|
|
|
if ( empty( $group[ 'fields' ] ) ) |
2097
|
|
|
continue; |
2098
|
|
|
|
2099
|
|
|
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) { |
2100
|
|
|
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) |
2101
|
|
|
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true ); |
2102
|
|
|
elseif ( self::$current_pod->id() != $id ) |
2103
|
|
|
self::$current_pod->fetch( $id ); |
2104
|
|
|
|
2105
|
|
|
$pod = self::$current_pod; |
2106
|
|
|
} |
2107
|
|
|
|
2108
|
|
|
foreach ( $group[ 'fields' ] as $field ) { |
2109
|
|
|
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) { |
2110
|
|
|
if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) |
2111
|
|
|
continue; |
2112
|
|
|
} |
2113
|
|
|
|
2114
|
|
|
$data[ $field[ 'name' ] ] = ''; |
2115
|
|
|
|
2116
|
|
|
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) ) |
2117
|
|
|
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ]; |
2118
|
|
|
} |
2119
|
|
|
} |
2120
|
|
|
|
2121
|
|
|
do_action( 'pods_meta_save_pre_comment', $data, $pod, $id, $groups ); |
2122
|
|
|
|
2123
|
|
View Code Duplication |
if ( !empty( $pod ) ) { |
2124
|
|
|
// Fix for Pods doing it's own sanitization |
2125
|
|
|
$data = pods_unslash( (array) $data ); |
2126
|
|
|
|
2127
|
|
|
$pod->save( $data ); |
2128
|
|
|
} |
2129
|
|
|
elseif ( !empty( $id ) ) { |
2130
|
|
|
pods_no_conflict_on( 'comment' ); |
2131
|
|
|
|
2132
|
|
|
foreach ( $data as $field => $value ) { |
2133
|
|
|
update_comment_meta( $id, $field, $value ); |
2134
|
|
|
} |
2135
|
|
|
|
2136
|
|
|
pods_no_conflict_off( 'comment' ); |
2137
|
|
|
} |
2138
|
|
|
|
2139
|
|
|
do_action( 'pods_meta_save_comment', $data, $pod, $id, $groups ); |
2140
|
|
|
|
2141
|
|
|
return $comment_id; |
2142
|
|
|
} |
2143
|
|
|
|
2144
|
|
|
/** |
2145
|
|
|
* All *_*_meta filter handler aliases |
2146
|
|
|
* |
2147
|
|
|
* @return mixed |
2148
|
|
|
*/ |
2149
|
|
View Code Duplication |
public function get_post_meta () { |
|
|
|
|
2150
|
|
|
$args = func_get_args(); |
2151
|
|
|
|
2152
|
|
|
array_unshift( $args, 'post_type' ); |
2153
|
|
|
|
2154
|
|
|
$_null = apply_filters( 'pods_meta_get_post_meta', null, $args ); |
2155
|
|
|
|
2156
|
|
|
if ( null !== $_null ) |
2157
|
|
|
return $_null; |
2158
|
|
|
|
2159
|
|
|
return call_user_func_array( array( $this, 'get_meta' ), $args ); |
2160
|
|
|
} |
2161
|
|
|
|
2162
|
|
|
/** |
2163
|
|
|
* @return mixed |
2164
|
|
|
*/ |
2165
|
|
View Code Duplication |
public function get_user_meta () { |
|
|
|
|
2166
|
|
|
$args = func_get_args(); |
2167
|
|
|
|
2168
|
|
|
array_unshift( $args, 'user' ); |
2169
|
|
|
|
2170
|
|
|
$_null = apply_filters( 'pods_meta_get_user_meta', null, $args ); |
2171
|
|
|
|
2172
|
|
|
if ( null !== $_null ) |
2173
|
|
|
return $_null; |
2174
|
|
|
|
2175
|
|
|
return call_user_func_array( array( $this, 'get_meta' ), $args ); |
2176
|
|
|
} |
2177
|
|
|
|
2178
|
|
|
/** |
2179
|
|
|
* @return mixed |
2180
|
|
|
*/ |
2181
|
|
View Code Duplication |
public function get_comment_meta () { |
|
|
|
|
2182
|
|
|
$args = func_get_args(); |
2183
|
|
|
|
2184
|
|
|
array_unshift( $args, 'comment' ); |
2185
|
|
|
|
2186
|
|
|
$_null = apply_filters( 'pods_meta_get_comment_meta', null, $args ); |
2187
|
|
|
|
2188
|
|
|
if ( null !== $_null ) |
2189
|
|
|
return $_null; |
2190
|
|
|
|
2191
|
|
|
return call_user_func_array( array( $this, 'get_meta' ), $args ); |
2192
|
|
|
} |
2193
|
|
|
|
2194
|
|
|
/** |
2195
|
|
|
* @return mixed |
2196
|
|
|
*/ |
2197
|
|
View Code Duplication |
public function get_term_meta () { |
|
|
|
|
2198
|
|
|
$args = func_get_args(); |
2199
|
|
|
|
2200
|
|
|
array_unshift( $args, 'term' ); |
2201
|
|
|
|
2202
|
|
|
$_null = apply_filters( 'pods_meta_get_term_meta', null, $args ); |
2203
|
|
|
|
2204
|
|
|
if ( null !== $_null ) |
2205
|
|
|
return $_null; |
2206
|
|
|
|
2207
|
|
|
return call_user_func_array( array( $this, 'get_meta' ), $args ); |
2208
|
|
|
} |
2209
|
|
|
|
2210
|
|
|
/** |
2211
|
|
|
* All *_*_meta filter handler aliases |
2212
|
|
|
* |
2213
|
|
|
* @return mixed |
2214
|
|
|
*/ |
2215
|
|
View Code Duplication |
public function get_option () { |
|
|
|
|
2216
|
|
|
$args = func_get_args(); |
2217
|
|
|
|
2218
|
|
|
array_unshift( $args, 'settings' ); |
2219
|
|
|
|
2220
|
|
|
$_null = apply_filters( 'pods_meta_get_option', null, $args ); |
2221
|
|
|
|
2222
|
|
|
if ( null !== $_null ) |
2223
|
|
|
return $_null; |
2224
|
|
|
|
2225
|
|
|
return call_user_func_array( array( $this, 'get_meta' ), $args ); |
2226
|
|
|
} |
2227
|
|
|
|
2228
|
|
|
/** |
2229
|
|
|
* @return mixed |
2230
|
|
|
*/ |
2231
|
|
View Code Duplication |
public function add_post_meta () { |
|
|
|
|
2232
|
|
|
$args = func_get_args(); |
2233
|
|
|
|
2234
|
|
|
array_unshift( $args, 'post_type' ); |
2235
|
|
|
|
2236
|
|
|
$_null = apply_filters( 'pods_meta_add_post_meta', null, $args ); |
2237
|
|
|
|
2238
|
|
|
if ( null !== $_null ) |
2239
|
|
|
return $_null; |
2240
|
|
|
|
2241
|
|
|
return call_user_func_array( array( $this, 'add_meta' ), $args ); |
2242
|
|
|
} |
2243
|
|
|
|
2244
|
|
|
/** |
2245
|
|
|
* @return mixed |
2246
|
|
|
*/ |
2247
|
|
View Code Duplication |
public function add_user_meta () { |
|
|
|
|
2248
|
|
|
$args = func_get_args(); |
2249
|
|
|
|
2250
|
|
|
array_unshift( $args, 'user' ); |
2251
|
|
|
|
2252
|
|
|
$_null = apply_filters( 'pods_meta_add_user_meta', null, $args ); |
2253
|
|
|
|
2254
|
|
|
if ( null !== $_null ) |
2255
|
|
|
return $_null; |
2256
|
|
|
|
2257
|
|
|
return call_user_func_array( array( $this, 'add_meta' ), $args ); |
2258
|
|
|
} |
2259
|
|
|
|
2260
|
|
|
/** |
2261
|
|
|
* @return mixed |
2262
|
|
|
*/ |
2263
|
|
View Code Duplication |
public function add_comment_meta () { |
|
|
|
|
2264
|
|
|
$args = func_get_args(); |
2265
|
|
|
|
2266
|
|
|
array_unshift( $args, 'comment' ); |
2267
|
|
|
|
2268
|
|
|
$_null = apply_filters( 'pods_meta_add_comment_meta', null, $args ); |
2269
|
|
|
|
2270
|
|
|
if ( null !== $_null ) |
2271
|
|
|
return $_null; |
2272
|
|
|
|
2273
|
|
|
return call_user_func_array( array( $this, 'add_meta' ), $args ); |
2274
|
|
|
} |
2275
|
|
|
|
2276
|
|
|
/** |
2277
|
|
|
* @return mixed |
2278
|
|
|
*/ |
2279
|
|
View Code Duplication |
public function add_term_meta () { |
|
|
|
|
2280
|
|
|
$args = func_get_args(); |
2281
|
|
|
|
2282
|
|
|
array_unshift( $args, 'term' ); |
2283
|
|
|
|
2284
|
|
|
$_null = apply_filters( 'pods_meta_add_term_meta', null, $args ); |
2285
|
|
|
|
2286
|
|
|
if ( null !== $_null ) |
2287
|
|
|
return $_null; |
2288
|
|
|
|
2289
|
|
|
return call_user_func_array( array( $this, 'add_meta' ), $args ); |
2290
|
|
|
} |
2291
|
|
|
|
2292
|
|
|
/** |
2293
|
|
|
* @return mixed |
2294
|
|
|
*/ |
2295
|
|
View Code Duplication |
public function add_option () { |
|
|
|
|
2296
|
|
|
$args = func_get_args(); |
2297
|
|
|
|
2298
|
|
|
array_unshift( $args, 'settings' ); |
2299
|
|
|
|
2300
|
|
|
$_null = apply_filters( 'pods_meta_add_option', null, $args ); |
2301
|
|
|
|
2302
|
|
|
if ( null !== $_null ) |
2303
|
|
|
return $_null; |
2304
|
|
|
|
2305
|
|
|
return call_user_func_array( array( $this, 'add_meta' ), $args ); |
2306
|
|
|
} |
2307
|
|
|
|
2308
|
|
|
/** |
2309
|
|
|
* @return mixed |
2310
|
|
|
*/ |
2311
|
|
View Code Duplication |
public function update_post_meta () { |
|
|
|
|
2312
|
|
|
$args = func_get_args(); |
2313
|
|
|
|
2314
|
|
|
array_unshift( $args, 'post_type' ); |
2315
|
|
|
|
2316
|
|
|
$_null = apply_filters( 'pods_meta_update_post_meta', null, $args ); |
2317
|
|
|
|
2318
|
|
|
if ( null !== $_null ) |
2319
|
|
|
return $_null; |
2320
|
|
|
|
2321
|
|
|
return call_user_func_array( array( $this, 'update_meta' ), $args ); |
2322
|
|
|
} |
2323
|
|
|
|
2324
|
|
|
/** |
2325
|
|
|
* @return mixed |
2326
|
|
|
*/ |
2327
|
|
View Code Duplication |
public function update_user_meta () { |
|
|
|
|
2328
|
|
|
$args = func_get_args(); |
2329
|
|
|
|
2330
|
|
|
array_unshift( $args, 'user' ); |
2331
|
|
|
|
2332
|
|
|
$_null = apply_filters( 'pods_meta_update_user_meta', null, $args ); |
2333
|
|
|
|
2334
|
|
|
if ( null !== $_null ) |
2335
|
|
|
return $_null; |
2336
|
|
|
|
2337
|
|
|
return call_user_func_array( array( $this, 'update_meta' ), $args ); |
2338
|
|
|
} |
2339
|
|
|
|
2340
|
|
|
/** |
2341
|
|
|
* @return mixed |
2342
|
|
|
*/ |
2343
|
|
View Code Duplication |
public function update_comment_meta () { |
|
|
|
|
2344
|
|
|
$args = func_get_args(); |
2345
|
|
|
|
2346
|
|
|
array_unshift( $args, 'comment' ); |
2347
|
|
|
|
2348
|
|
|
$_null = apply_filters( 'pods_meta_update_comment_meta', null, $args ); |
2349
|
|
|
|
2350
|
|
|
if ( null !== $_null ) |
2351
|
|
|
return $_null; |
2352
|
|
|
|
2353
|
|
|
return call_user_func_array( array( $this, 'update_meta' ), $args ); |
2354
|
|
|
} |
2355
|
|
|
|
2356
|
|
|
/** |
2357
|
|
|
* @return mixed |
2358
|
|
|
*/ |
2359
|
|
View Code Duplication |
public function update_term_meta () { |
|
|
|
|
2360
|
|
|
$args = func_get_args(); |
2361
|
|
|
|
2362
|
|
|
array_unshift( $args, 'term' ); |
2363
|
|
|
|
2364
|
|
|
$_null = apply_filters( 'pods_meta_update_term_meta', null, $args ); |
2365
|
|
|
|
2366
|
|
|
if ( null !== $_null ) |
2367
|
|
|
return $_null; |
2368
|
|
|
|
2369
|
|
|
return call_user_func_array( array( $this, 'update_meta' ), $args ); |
2370
|
|
|
} |
2371
|
|
|
|
2372
|
|
|
/** |
2373
|
|
|
* @return mixed |
2374
|
|
|
*/ |
2375
|
|
View Code Duplication |
public function update_option () { |
|
|
|
|
2376
|
|
|
$args = func_get_args(); |
2377
|
|
|
|
2378
|
|
|
array_unshift( $args, 'settings' ); |
2379
|
|
|
|
2380
|
|
|
$_null = apply_filters( 'pods_meta_update_option', null, $args ); |
2381
|
|
|
|
2382
|
|
|
if ( null !== $_null ) |
2383
|
|
|
return $_null; |
2384
|
|
|
|
2385
|
|
|
return call_user_func_array( array( $this, 'update_meta' ), $args ); |
2386
|
|
|
} |
2387
|
|
|
|
2388
|
|
|
/** |
2389
|
|
|
* @return mixed |
2390
|
|
|
*/ |
2391
|
|
View Code Duplication |
public function delete_post_meta () { |
|
|
|
|
2392
|
|
|
$args = func_get_args(); |
2393
|
|
|
|
2394
|
|
|
array_unshift( $args, 'post_type' ); |
2395
|
|
|
|
2396
|
|
|
$_null = apply_filters( 'pods_meta_delete_post_meta', null, $args ); |
2397
|
|
|
|
2398
|
|
|
if ( null !== $_null ) |
2399
|
|
|
return $_null; |
2400
|
|
|
|
2401
|
|
|
return call_user_func_array( array( $this, 'delete_meta' ), $args ); |
2402
|
|
|
} |
2403
|
|
|
|
2404
|
|
|
/** |
2405
|
|
|
* @return mixed |
2406
|
|
|
*/ |
2407
|
|
View Code Duplication |
public function delete_user_meta () { |
|
|
|
|
2408
|
|
|
$args = func_get_args(); |
2409
|
|
|
|
2410
|
|
|
array_unshift( $args, 'user' ); |
2411
|
|
|
|
2412
|
|
|
$_null = apply_filters( 'pods_meta_delete_user_meta', null, $args ); |
2413
|
|
|
|
2414
|
|
|
if ( null !== $_null ) |
2415
|
|
|
return $_null; |
2416
|
|
|
|
2417
|
|
|
return call_user_func_array( array( $this, 'delete_meta' ), $args ); |
2418
|
|
|
} |
2419
|
|
|
|
2420
|
|
|
/** |
2421
|
|
|
* @return mixed |
2422
|
|
|
*/ |
2423
|
|
View Code Duplication |
public function delete_comment_meta () { |
|
|
|
|
2424
|
|
|
$args = func_get_args(); |
2425
|
|
|
|
2426
|
|
|
array_unshift( $args, 'comment' ); |
2427
|
|
|
|
2428
|
|
|
$_null = apply_filters( 'pods_meta_delete_comment_meta', null, $args ); |
2429
|
|
|
|
2430
|
|
|
if ( null !== $_null ) |
2431
|
|
|
return $_null; |
2432
|
|
|
|
2433
|
|
|
return call_user_func_array( array( $this, 'delete_meta' ), $args ); |
2434
|
|
|
} |
2435
|
|
|
|
2436
|
|
|
/** |
2437
|
|
|
* @return mixed |
2438
|
|
|
*/ |
2439
|
|
View Code Duplication |
public function delete_term_meta () { |
|
|
|
|
2440
|
|
|
$args = func_get_args(); |
2441
|
|
|
|
2442
|
|
|
array_unshift( $args, 'term' ); |
2443
|
|
|
|
2444
|
|
|
$_null = apply_filters( 'pods_meta_delete_term_meta', null, $args ); |
2445
|
|
|
|
2446
|
|
|
if ( null !== $_null ) |
2447
|
|
|
return $_null; |
2448
|
|
|
|
2449
|
|
|
return call_user_func_array( array( $this, 'delete_meta' ), $args ); |
2450
|
|
|
} |
2451
|
|
|
|
2452
|
|
|
/** |
2453
|
|
|
* @return mixed |
2454
|
|
|
*/ |
2455
|
|
View Code Duplication |
public function delete_option () { |
|
|
|
|
2456
|
|
|
$args = func_get_args(); |
2457
|
|
|
|
2458
|
|
|
array_unshift( $args, 'settings' ); |
2459
|
|
|
|
2460
|
|
|
$_null = apply_filters( 'pods_meta_delete_option', null, $args ); |
2461
|
|
|
|
2462
|
|
|
if ( null !== $_null ) |
2463
|
|
|
return $_null; |
2464
|
|
|
|
2465
|
|
|
return call_user_func_array( array( $this, 'delete_meta' ), $args ); |
2466
|
|
|
} |
2467
|
|
|
|
2468
|
|
|
/* |
2469
|
|
|
* The real meta functions |
2470
|
|
|
*/ |
2471
|
|
|
/** |
2472
|
|
|
* @param $object_type |
2473
|
|
|
* @param $object_id |
2474
|
|
|
* @param string $aux |
2475
|
|
|
* |
2476
|
|
|
* @return bool|mixed |
2477
|
|
|
*/ |
2478
|
|
|
public function get_object ( $object_type, $object_id, $aux = '' ) { |
2479
|
|
|
|
2480
|
|
|
global $wpdb; |
|
|
|
|
2481
|
|
|
|
2482
|
|
|
if ( 'term' == $object_type ) { |
2483
|
|
|
$object_type = 'taxonomy'; |
2484
|
|
|
} |
2485
|
|
|
|
2486
|
|
|
if ( 'post_type' == $object_type ) |
2487
|
|
|
$objects = self::$post_types; |
2488
|
|
|
elseif ( 'taxonomy' == $object_type ) |
2489
|
|
|
$objects = self::$taxonomies; |
2490
|
|
|
elseif ( 'media' == $object_type ) |
2491
|
|
|
$objects = self::$media; |
2492
|
|
|
elseif ( 'user' == $object_type ) |
2493
|
|
|
$objects = self::$user; |
2494
|
|
|
elseif ( 'comment' == $object_type ) |
2495
|
|
|
$objects = self::$comment; |
2496
|
|
|
elseif ( 'settings' == $object_type ) |
2497
|
|
|
$objects = self::$settings; |
2498
|
|
|
else |
2499
|
|
|
return false; |
2500
|
|
|
|
2501
|
|
|
if ( empty( $objects ) || !is_array( $objects ) ) |
2502
|
|
|
return false; |
2503
|
|
|
|
2504
|
|
|
$object_name = null; |
2505
|
|
|
|
2506
|
|
|
if ( 'media' == $object_type ) |
2507
|
|
|
return @current( $objects ); |
2508
|
|
|
elseif ( 'user' == $object_type ) |
2509
|
|
|
return @current( $objects ); |
2510
|
|
|
elseif ( 'comment' == $object_type ) |
2511
|
|
|
return @current( $objects ); |
2512
|
|
|
elseif ( 'post_type' == $object_type ) { |
2513
|
|
|
$object = get_post( $object_id ); |
2514
|
|
|
|
2515
|
|
|
if ( !is_object( $object ) || !isset( $object->post_type ) ) |
2516
|
|
|
return false; |
2517
|
|
|
|
2518
|
|
|
$object_name = $object->post_type; |
2519
|
|
|
} |
2520
|
|
|
elseif ( 'taxonomy' == $object_type ) { |
2521
|
|
|
if ( pods_version_check( 'wp', '4.4' ) ) { |
2522
|
|
|
$object = get_term( $object_id ); |
2523
|
|
|
|
2524
|
|
|
if ( !is_object( $object ) || !isset( $object->taxonomy ) ) |
2525
|
|
|
return false; |
2526
|
|
|
|
2527
|
|
|
$object_name = $object->taxonomy; |
2528
|
|
|
} elseif ( empty( $aux ) ) { |
2529
|
|
|
$object_name = $wpdb->get_var( $wpdb->prepare( "SELECT `taxonomy` FROM `{$wpdb->term_taxonomy}` WHERE `term_id` = %d", $object_id ) ); |
2530
|
|
|
} else { |
2531
|
|
|
$object_name = $aux; |
2532
|
|
|
} |
2533
|
|
|
} |
2534
|
|
|
elseif ( 'settings' == $object_type ) |
2535
|
|
|
$object = $object_id; |
2536
|
|
|
else |
2537
|
|
|
return false; |
2538
|
|
|
|
2539
|
|
|
$reserved_post_types = array( |
2540
|
|
|
'revision' |
2541
|
|
|
); |
2542
|
|
|
|
2543
|
|
|
$reserved_post_types = apply_filters( 'pods_meta_reserved_post_types', $reserved_post_types, $object_type, $object_id, $object_name, $objects ); |
2544
|
|
|
|
2545
|
|
|
if ( empty( $object_name ) || ( 'post_type' == $object_type && ( 0 === strpos( $object_name, '_pods_' ) ) || in_array( $object_name, $reserved_post_types ) ) ) { |
2546
|
|
|
return false; |
2547
|
|
|
} |
2548
|
|
|
elseif ( 'attachment' == $object_name ) { |
2549
|
|
|
return @current( self::$media ); |
2550
|
|
|
} |
2551
|
|
|
|
2552
|
|
|
$recheck = array(); |
2553
|
|
|
|
2554
|
|
|
// Return first created by Pods, save extended for later |
2555
|
|
|
foreach ( $objects as $pod ) { |
2556
|
|
|
if ( $object_name == $pod[ 'object' ] ) |
2557
|
|
|
$recheck[] = $pod; |
2558
|
|
|
|
2559
|
|
|
if ( '' == $pod[ 'object' ] && $object_name == $pod[ 'name' ] ) |
2560
|
|
|
return $pod; |
2561
|
|
|
} |
2562
|
|
|
|
2563
|
|
|
// If no objects created by Pods, return first extended |
2564
|
|
|
foreach ( $recheck as $pod ) { |
2565
|
|
|
return $pod; |
2566
|
|
|
} |
2567
|
|
|
|
2568
|
|
|
return false; |
2569
|
|
|
} |
2570
|
|
|
|
2571
|
|
|
/** |
2572
|
|
|
* @param $object_type |
2573
|
|
|
* @param null $_null |
2574
|
|
|
* @param int $object_id |
2575
|
|
|
* @param string $meta_key |
2576
|
|
|
* @param bool $single |
2577
|
|
|
* |
2578
|
|
|
* @return array|bool|int|mixed|null|string|void |
2579
|
|
|
*/ |
2580
|
|
|
public function get_meta ( $object_type, $_null = null, $object_id = 0, $meta_key = '', $single = false ) { |
2581
|
|
|
$meta_type = $object_type; |
2582
|
|
|
|
2583
|
|
|
if ( in_array( $meta_type, array( 'post_type', 'media' ) ) ) |
2584
|
|
|
$meta_type = 'post'; |
2585
|
|
|
elseif ( 'taxonomy' == $meta_type ) |
2586
|
|
|
$meta_type = 'term'; |
2587
|
|
|
|
2588
|
|
|
if ( empty( $meta_key ) ) { |
2589
|
|
|
if ( !defined( 'PODS_ALLOW_FULL_META' ) || !PODS_ALLOW_FULL_META ) { |
2590
|
|
|
return $_null; // don't cover get_post_meta( $id ) |
2591
|
|
|
} |
2592
|
|
|
|
2593
|
|
|
$single = false; |
2594
|
|
|
} |
2595
|
|
|
|
2596
|
|
|
$object = $this->get_object( $object_type, $object_id ); |
2597
|
|
|
|
2598
|
|
|
if ( empty( $object_id ) || empty( $object ) ) |
2599
|
|
|
return $_null; |
2600
|
|
|
|
2601
|
|
|
$no_conflict = pods_no_conflict_check( $meta_type ); |
2602
|
|
|
|
2603
|
|
|
if ( !$no_conflict ) |
2604
|
|
|
pods_no_conflict_on( $meta_type ); |
2605
|
|
|
|
2606
|
|
|
$meta_cache = array(); |
2607
|
|
|
|
2608
|
|
|
if ( !$single && isset( $GLOBALS[ 'wp_object_cache' ] ) && is_object( $GLOBALS[ 'wp_object_cache' ] ) ) { |
2609
|
|
|
$meta_cache = wp_cache_get( $object_id, 'pods_' . $meta_type . '_meta' ); |
2610
|
|
|
|
2611
|
|
|
if ( empty( $meta_cache ) ) { |
2612
|
|
|
$meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' ); |
2613
|
|
|
|
2614
|
|
|
if ( empty( $meta_cache ) ) { |
2615
|
|
|
$meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); |
2616
|
|
|
$meta_cache = $meta_cache[ $object_id ]; |
2617
|
|
|
} |
2618
|
|
|
} |
2619
|
|
|
} |
2620
|
|
|
|
2621
|
|
|
if ( empty( $meta_cache ) || !is_array( $meta_cache ) ) |
2622
|
|
|
$meta_cache = array(); |
2623
|
|
|
|
2624
|
|
View Code Duplication |
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] ) |
2625
|
|
|
self::$current_field_pod = pods( $object[ 'name' ], $object_id ); |
2626
|
|
|
elseif ( self::$current_field_pod->id() != $object_id ) |
2627
|
|
|
self::$current_field_pod->fetch( $object_id ); |
2628
|
|
|
|
2629
|
|
|
$pod = self::$current_field_pod; |
2630
|
|
|
|
2631
|
|
|
$meta_keys = array( $meta_key ); |
2632
|
|
|
|
2633
|
|
|
if ( empty( $meta_key ) ) |
2634
|
|
|
$meta_keys = array_keys( $meta_cache ); |
2635
|
|
|
|
2636
|
|
|
$key_found = false; |
2637
|
|
|
|
2638
|
|
|
foreach ( $meta_keys as $meta_k ) { |
2639
|
|
|
if ( !empty( $pod ) ) { |
2640
|
|
|
if ( isset( $pod->fields[ $meta_k ] ) ) { |
2641
|
|
|
$key_found = true; |
2642
|
|
|
|
2643
|
|
|
$meta_cache[ $meta_k ] = $pod->field( array( 'name' => $meta_k, 'single' => $single, 'get_meta' => true ) ); |
2644
|
|
|
|
2645
|
|
View Code Duplication |
if ( ( !is_array( $meta_cache[ $meta_k ] ) || !isset( $meta_cache[ $meta_k ][ 0 ] ) ) ) { |
2646
|
|
|
if ( empty( $meta_cache[ $meta_k ] ) && !is_array( $meta_cache[ $meta_k ] ) && $single ) |
2647
|
|
|
$meta_cache[ $meta_k ] = array(); |
2648
|
|
|
else |
2649
|
|
|
$meta_cache[ $meta_k ] = array( $meta_cache[ $meta_k ] ); |
2650
|
|
|
} |
2651
|
|
|
|
2652
|
|
View Code Duplication |
if ( in_array( $pod->fields[ $meta_k ][ 'type' ], PodsForm::tableless_field_types() ) && isset( $meta_cache[ '_pods_' . $meta_k ] ) ) |
2653
|
|
|
unset( $meta_cache[ '_pods_' . $meta_k ] ); |
2654
|
|
|
} |
2655
|
|
|
elseif ( false !== strpos( $meta_k, '.' ) ) { |
2656
|
|
|
$key_found = true; |
2657
|
|
|
|
2658
|
|
|
$first = current( explode( '.', $meta_k ) ); |
2659
|
|
|
|
2660
|
|
|
if ( isset( $pod->fields[ $first ] ) ) { |
2661
|
|
|
$meta_cache[ $meta_k ] = $pod->field( array( 'name' => $meta_k, 'single' => $single, 'get_meta' => true ) ); |
2662
|
|
|
|
2663
|
|
View Code Duplication |
if ( ( !is_array( $meta_cache[ $meta_k ] ) || !isset( $meta_cache[ $meta_k ][ 0 ] ) ) && $single ) { |
2664
|
|
|
if ( empty( $meta_cache[ $meta_k ] ) && !is_array( $meta_cache[ $meta_k ] ) && $single ) |
2665
|
|
|
$meta_cache[ $meta_k ] = array(); |
2666
|
|
|
else |
2667
|
|
|
$meta_cache[ $meta_k ] = array( $meta_cache[ $meta_k ] ); |
2668
|
|
|
} |
2669
|
|
|
|
2670
|
|
View Code Duplication |
if ( in_array( $pod->fields[ $first ][ 'type' ], PodsForm::tableless_field_types() ) && isset( $meta_cache[ '_pods_' . $first ] ) ) |
2671
|
|
|
unset( $meta_cache[ '_pods_' . $first ] ); |
2672
|
|
|
} |
2673
|
|
|
} |
2674
|
|
|
} |
2675
|
|
|
} |
2676
|
|
|
|
2677
|
|
|
if ( !$no_conflict ) |
2678
|
|
|
pods_no_conflict_off( $meta_type ); |
2679
|
|
|
|
2680
|
|
|
unset( $pod ); // memory clear |
2681
|
|
|
|
2682
|
|
|
if ( !$key_found ) |
2683
|
|
|
return $_null; |
2684
|
|
|
|
2685
|
|
|
if ( !$single && isset( $GLOBALS[ 'wp_object_cache' ] ) && is_object( $GLOBALS[ 'wp_object_cache' ] ) ) |
2686
|
|
|
wp_cache_set( $object_id, $meta_cache, 'pods_' . $meta_type . '_meta' ); |
2687
|
|
|
|
2688
|
|
|
if ( empty( $meta_key ) ) |
2689
|
|
|
return $meta_cache; |
2690
|
|
|
elseif ( isset( $meta_cache[ $meta_key ] ) ) |
2691
|
|
|
$value = $meta_cache[ $meta_key ]; |
2692
|
|
|
else |
2693
|
|
|
$value = ''; |
2694
|
|
|
|
2695
|
|
|
if ( !is_numeric( $value ) && empty( $value ) ) { |
2696
|
|
|
if ( $single ) |
2697
|
|
|
$value = ''; |
2698
|
|
|
else |
2699
|
|
|
$value = array(); |
2700
|
|
|
} |
2701
|
|
|
// get_metadata requires $meta[ 0 ] to be set for first value to be retrieved |
2702
|
|
|
elseif ( !is_array( $value ) ) |
2703
|
|
|
$value = array( $value ); |
2704
|
|
|
|
2705
|
|
|
return $value; |
2706
|
|
|
} |
2707
|
|
|
|
2708
|
|
|
/** |
2709
|
|
|
* @param $object_type |
2710
|
|
|
* @param null $_null |
2711
|
|
|
* @param int $object_id |
2712
|
|
|
* @param string $meta_key |
2713
|
|
|
* @param string $meta_value |
2714
|
|
|
* @param bool $unique |
2715
|
|
|
* |
2716
|
|
|
* @return bool|int|null |
2717
|
|
|
*/ |
2718
|
|
|
public function add_meta ( $object_type, $_null = null, $object_id = 0, $meta_key = '', $meta_value = '', $unique = false ) { |
|
|
|
|
2719
|
|
|
if ( pods_tableless() ) |
2720
|
|
|
return $_null; |
2721
|
|
|
|
2722
|
|
|
$object = $this->get_object( $object_type, $object_id ); |
2723
|
|
|
|
2724
|
|
View Code Duplication |
if ( empty( $object_id ) || empty( $object ) || !isset( $object[ 'fields' ][ $meta_key ] ) ) |
2725
|
|
|
return $_null; |
2726
|
|
|
|
2727
|
|
|
if ( in_array( $object[ 'fields' ][ $meta_key ][ 'type' ], PodsForm::tableless_field_types() ) ) { |
2728
|
|
View Code Duplication |
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] ) |
2729
|
|
|
self::$current_field_pod = pods( $object[ 'name' ], $object_id ); |
2730
|
|
|
elseif ( self::$current_field_pod->id() != $object_id ) |
2731
|
|
|
self::$current_field_pod->fetch( $object_id ); |
2732
|
|
|
|
2733
|
|
|
$pod = self::$current_field_pod; |
2734
|
|
|
|
2735
|
|
|
$pod->add_to( $meta_key, $meta_value ); |
2736
|
|
|
} |
2737
|
|
|
else { |
2738
|
|
View Code Duplication |
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] ) |
2739
|
|
|
self::$current_field_pod = pods( $object[ 'name' ] ); |
2740
|
|
|
|
2741
|
|
|
$pod = self::$current_field_pod; |
2742
|
|
|
|
2743
|
|
|
$pod->save( $meta_key, $meta_value, $object_id ); |
2744
|
|
|
} |
2745
|
|
|
|
2746
|
|
|
return $object_id; |
2747
|
|
|
} |
2748
|
|
|
|
2749
|
|
|
/** |
2750
|
|
|
* @param $object_type |
2751
|
|
|
* @param null $_null |
2752
|
|
|
* @param int $object_id |
2753
|
|
|
* @param string $meta_key |
2754
|
|
|
* @param string $meta_value |
2755
|
|
|
* @param string $prev_value |
2756
|
|
|
* |
2757
|
|
|
* @return bool|int|null |
2758
|
|
|
*/ |
2759
|
|
|
public function update_meta ( $object_type, $_null = null, $object_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
|
|
|
2760
|
|
|
if ( pods_tableless() ) |
2761
|
|
|
return $_null; |
2762
|
|
|
|
2763
|
|
|
$object = $this->get_object( $object_type, $object_id ); |
2764
|
|
|
|
2765
|
|
View Code Duplication |
if ( empty( $object_id ) || empty( $object ) || !isset( $object[ 'fields' ][ $meta_key ] ) ) |
2766
|
|
|
return $_null; |
2767
|
|
|
|
2768
|
|
View Code Duplication |
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] ) |
2769
|
|
|
self::$current_field_pod = pods( $object[ 'name' ] ); |
2770
|
|
|
|
2771
|
|
|
$pod = self::$current_field_pod; |
2772
|
|
|
|
2773
|
|
|
if ( ( isset( $pod->fields[ $meta_key ] ) || false !== strpos( $meta_key, '.' ) ) && $pod->row !== null) { |
2774
|
|
|
|
2775
|
|
|
$key = $meta_key; |
2776
|
|
|
if(false !== strpos( $meta_key, '.' )){ |
2777
|
|
|
$key = current( explode( '.', $meta_key ) ); |
2778
|
|
|
} |
2779
|
|
|
|
2780
|
|
|
$pod->row[ $meta_key ] = $meta_value; |
2781
|
|
|
|
2782
|
|
View Code Duplication |
if ( isset( $pod->fields[ $key ] ) ) { |
2783
|
|
|
if ( in_array( $pod->fields[ $key ][ 'type' ], PodsForm::tableless_field_types() ) && isset( $meta_cache[ '_pods_' . $key ] ) ) |
|
|
|
|
2784
|
|
|
unset( $meta_cache[ '_pods_' . $key ] ); |
2785
|
|
|
} |
2786
|
|
|
|
2787
|
|
|
} |
2788
|
|
|
|
2789
|
|
|
$pod->save( $meta_key, $meta_value, $object_id ); |
2790
|
|
|
|
2791
|
|
|
return $object_id; |
2792
|
|
|
} |
2793
|
|
|
|
2794
|
|
|
/** |
2795
|
|
|
* @param $object_type |
2796
|
|
|
* @param null $_null |
2797
|
|
|
* @param int $object_id |
2798
|
|
|
* @param string $meta_key |
2799
|
|
|
* @param string $meta_value |
2800
|
|
|
* @param bool $delete_all |
2801
|
|
|
* |
2802
|
|
|
* @return null |
2803
|
|
|
*/ |
2804
|
|
|
public function delete_meta ( $object_type, $_null = null, $object_id = 0, $meta_key = '', $meta_value = '', $delete_all = false ) { |
|
|
|
|
2805
|
|
|
if ( pods_tableless() ) |
2806
|
|
|
return $_null; |
2807
|
|
|
|
2808
|
|
|
$object = $this->get_object( $object_type, $object_id ); |
2809
|
|
|
|
2810
|
|
View Code Duplication |
if ( empty( $object_id ) || empty( $object ) || !isset( $object[ 'fields' ][ $meta_key ] ) ) |
2811
|
|
|
return $_null; |
2812
|
|
|
|
2813
|
|
|
// @todo handle $delete_all (delete the field values from all pod items) |
2814
|
|
|
if ( !empty( $meta_value ) && in_array( $object[ 'fields' ][ $meta_key ][ 'type' ], PodsForm::tableless_field_types() ) ) { |
2815
|
|
View Code Duplication |
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] ) |
2816
|
|
|
self::$current_field_pod = pods( $object[ 'name' ], $object_id ); |
2817
|
|
|
elseif ( self::$current_field_pod->id() != $object_id ) |
2818
|
|
|
self::$current_field_pod->fetch( $object_id ); |
2819
|
|
|
|
2820
|
|
|
$pod = self::$current_field_pod; |
2821
|
|
|
|
2822
|
|
|
$pod->remove_from( $meta_key, $meta_value ); |
2823
|
|
|
} |
2824
|
|
|
else { |
2825
|
|
View Code Duplication |
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] ) |
2826
|
|
|
self::$current_field_pod = pods( $object[ 'name' ] ); |
2827
|
|
|
|
2828
|
|
|
$pod = self::$current_field_pod; |
2829
|
|
|
|
2830
|
|
|
$pod->save( array( $meta_key => null ), null, $object_id ); |
2831
|
|
|
} |
2832
|
|
|
|
2833
|
|
|
return $_null; |
2834
|
|
|
} |
2835
|
|
|
|
2836
|
|
|
public function delete_post ( $id ) { |
2837
|
|
|
$post = get_post( $id ); |
2838
|
|
|
|
2839
|
|
|
if ( empty( $post ) ) |
2840
|
|
|
return; |
2841
|
|
|
|
2842
|
|
|
$id = $post->ID; |
2843
|
|
|
$post_type = $post->post_type; |
2844
|
|
|
|
2845
|
|
|
return $this->delete_object( 'post_type', $id, $post_type ); |
2846
|
|
|
} |
2847
|
|
|
|
2848
|
|
|
public function delete_taxonomy ( $id ) { |
2849
|
|
|
/** |
2850
|
|
|
* @var $wpdb WPDB |
2851
|
|
|
*/ |
2852
|
|
|
global $wpdb; |
|
|
|
|
2853
|
|
|
|
2854
|
|
|
$terms = $wpdb->get_results( "SELECT `term_id`, `taxonomy` FROM `{$wpdb->term_taxonomy}` WHERE `term_taxonomy_id` = {$id}" ); |
2855
|
|
|
|
2856
|
|
|
if ( empty( $terms ) ) |
2857
|
|
|
return; |
2858
|
|
|
|
2859
|
|
|
foreach ( $terms as $term ) { |
2860
|
|
|
$id = $term->term_id; |
2861
|
|
|
$taxonomy = $term->taxonomy; |
2862
|
|
|
|
2863
|
|
|
$this->delete_object( 'taxonomy', $id, $taxonomy ); |
2864
|
|
|
} |
2865
|
|
|
} |
2866
|
|
|
|
2867
|
|
|
/** |
2868
|
|
|
* Hook the split_shared_term action and point it to this method |
2869
|
|
|
* |
2870
|
|
|
* Fires after a previously shared taxonomy term is split into two separate terms. |
2871
|
|
|
* |
2872
|
|
|
* @param int $term_id ID of the formerly shared term. |
2873
|
|
|
* @param int $new_term_id ID of the new term created for the $term_taxonomy_id. |
2874
|
|
|
* @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. |
2875
|
|
|
* @param string $taxonomy Taxonomy for the split term. |
2876
|
|
|
*/ |
2877
|
|
|
public static function split_shared_term( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { |
2878
|
|
|
|
2879
|
|
|
require_once( PODS_DIR . 'classes/PodsTermSplitting.php' ); |
2880
|
|
|
|
2881
|
|
|
$term_splitting = new Pods_Term_Splitting( $term_id, $new_term_id, $taxonomy ); |
2882
|
|
|
$term_splitting->split_shared_term(); |
2883
|
|
|
|
2884
|
|
|
} |
2885
|
|
|
|
2886
|
|
|
public function delete_user ( $id ) { |
2887
|
|
|
return $this->delete_object( 'user', $id ); |
2888
|
|
|
} |
2889
|
|
|
|
2890
|
|
|
public function delete_comment ( $id ) { |
2891
|
|
|
return $this->delete_object( 'comment', $id ); |
2892
|
|
|
} |
2893
|
|
|
|
2894
|
|
|
public function delete_media ( $id ) { |
2895
|
|
|
return $this->delete_object( 'media', $id ); |
2896
|
|
|
} |
2897
|
|
|
|
2898
|
|
|
public function delete_object ( $type, $id, $name = null ) { |
2899
|
|
|
if ( empty( $name ) ) |
2900
|
|
|
$name = $type; |
2901
|
|
|
|
2902
|
|
|
$object = $this->object_get( $type, $name ); |
2903
|
|
|
|
2904
|
|
|
if ( !empty( $object ) ) { |
2905
|
|
|
$params = array( |
2906
|
|
|
'pod' => pods_var( 'name', $object ), |
2907
|
|
|
'pod_id' => pods_var( 'id', $object ), |
2908
|
|
|
'id' => $id |
2909
|
|
|
); |
2910
|
|
|
|
2911
|
|
|
return pods_api()->delete_pod_item( $params, false ); |
2912
|
|
|
} |
2913
|
|
|
else |
2914
|
|
|
return pods_api()->delete_object_from_relationships( $id, $type, $name ); |
2915
|
|
|
} |
2916
|
|
|
} |
2917
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.