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