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