author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Core Metadata API |
0 | 4 |
* |
5 |
* Functions for retrieving and manipulating metadata of various WordPress object types. Metadata |
|
6 |
* for an object is a represented by a simple key-value pair. Objects may contain multiple |
|
7 |
* metadata entries that share the same key and differ only in their value. |
|
8 |
* |
|
9 |
* @package WordPress |
|
10 |
* @subpackage Meta |
|
11 |
*/ |
|
12 |
||
13 |
/** |
|
14 |
* Add metadata for the specified object. |
|
15 |
* |
|
16 |
* @since 2.9.0 |
|
5 | 17 |
* |
18 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 19 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* @param int $object_id ID of the object metadata is for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* @param string $meta_key Metadata key |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* @param bool $unique Optional, default is false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* Whether the specified metadata key should be unique for the object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
* If true, and the object already has a value for the specified metadata key, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
* no change will be made. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
* @return int|false The meta ID on success, false on failure. |
0 | 29 |
*/ |
30 |
function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = false) { |
|
5 | 31 |
global $wpdb; |
0 | 32 |
|
5 | 33 |
if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) { |
0 | 34 |
return false; |
5 | 35 |
} |
0 | 36 |
|
5 | 37 |
$object_id = absint( $object_id ); |
38 |
if ( ! $object_id ) { |
|
0 | 39 |
return false; |
5 | 40 |
} |
0 | 41 |
|
5 | 42 |
$table = _get_meta_table( $meta_type ); |
43 |
if ( ! $table ) { |
|
44 |
return false; |
|
45 |
} |
|
0 | 46 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
$meta_subtype = get_object_subtype( $meta_type, $object_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
|
0 | 49 |
$column = sanitize_key($meta_type . '_id'); |
50 |
||
51 |
// expected_slashed ($meta_key) |
|
52 |
$meta_key = wp_unslash($meta_key); |
|
53 |
$meta_value = wp_unslash($meta_value); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
$meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type, $meta_subtype ); |
0 | 55 |
|
5 | 56 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* Filters whether to add metadata of a specific type. |
5 | 58 |
* |
59 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
60 |
* object type (comment, post, or user). Returning a non-null value |
|
61 |
* will effectively short-circuit the function. |
|
62 |
* |
|
63 |
* @since 3.1.0 |
|
64 |
* |
|
65 |
* @param null|bool $check Whether to allow adding metadata for the given type. |
|
66 |
* @param int $object_id Object ID. |
|
67 |
* @param string $meta_key Meta key. |
|
68 |
* @param mixed $meta_value Meta value. Must be serializable if non-scalar. |
|
69 |
* @param bool $unique Whether the specified meta key should be unique |
|
70 |
* for the object. Optional. Default false. |
|
71 |
*/ |
|
0 | 72 |
$check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique ); |
73 |
if ( null !== $check ) |
|
74 |
return $check; |
|
75 |
||
76 |
if ( $unique && $wpdb->get_var( $wpdb->prepare( |
|
77 |
"SELECT COUNT(*) FROM $table WHERE meta_key = %s AND $column = %d", |
|
78 |
$meta_key, $object_id ) ) ) |
|
79 |
return false; |
|
80 |
||
81 |
$_meta_value = $meta_value; |
|
82 |
$meta_value = maybe_serialize( $meta_value ); |
|
83 |
||
5 | 84 |
/** |
85 |
* Fires immediately before meta of a specific type is added. |
|
86 |
* |
|
87 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
88 |
* object type (comment, post, or user). |
|
89 |
* |
|
90 |
* @since 3.1.0 |
|
91 |
* |
|
92 |
* @param int $object_id Object ID. |
|
93 |
* @param string $meta_key Meta key. |
|
94 |
* @param mixed $meta_value Meta value. |
|
95 |
*/ |
|
0 | 96 |
do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value ); |
97 |
||
98 |
$result = $wpdb->insert( $table, array( |
|
99 |
$column => $object_id, |
|
100 |
'meta_key' => $meta_key, |
|
101 |
'meta_value' => $meta_value |
|
102 |
) ); |
|
103 |
||
104 |
if ( ! $result ) |
|
105 |
return false; |
|
106 |
||
107 |
$mid = (int) $wpdb->insert_id; |
|
108 |
||
109 |
wp_cache_delete($object_id, $meta_type . '_meta'); |
|
110 |
||
5 | 111 |
/** |
112 |
* Fires immediately after meta of a specific type is added. |
|
113 |
* |
|
114 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
115 |
* object type (comment, post, or user). |
|
116 |
* |
|
117 |
* @since 2.9.0 |
|
118 |
* |
|
119 |
* @param int $mid The meta ID after successful update. |
|
120 |
* @param int $object_id Object ID. |
|
121 |
* @param string $meta_key Meta key. |
|
122 |
* @param mixed $meta_value Meta value. |
|
123 |
*/ |
|
0 | 124 |
do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value ); |
125 |
||
126 |
return $mid; |
|
127 |
} |
|
128 |
||
129 |
/** |
|
130 |
* Update metadata for the specified object. If no value already exists for the specified object |
|
131 |
* ID and metadata key, the metadata will be added. |
|
132 |
* |
|
133 |
* @since 2.9.0 |
|
5 | 134 |
* |
135 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 136 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
* @param int $object_id ID of the object metadata is for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
* @param string $meta_key Metadata key |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
* @param mixed $prev_value Optional. If specified, only update existing metadata entries with |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
* the specified value. Otherwise, update all entries. |
5 | 143 |
* @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
0 | 144 |
*/ |
145 |
function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '') { |
|
5 | 146 |
global $wpdb; |
0 | 147 |
|
5 | 148 |
if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) { |
0 | 149 |
return false; |
5 | 150 |
} |
0 | 151 |
|
5 | 152 |
$object_id = absint( $object_id ); |
153 |
if ( ! $object_id ) { |
|
0 | 154 |
return false; |
5 | 155 |
} |
0 | 156 |
|
5 | 157 |
$table = _get_meta_table( $meta_type ); |
158 |
if ( ! $table ) { |
|
159 |
return false; |
|
160 |
} |
|
0 | 161 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
$meta_subtype = get_object_subtype( $meta_type, $object_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
|
0 | 164 |
$column = sanitize_key($meta_type . '_id'); |
165 |
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
|
166 |
||
167 |
// expected_slashed ($meta_key) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
$raw_meta_key = $meta_key; |
0 | 169 |
$meta_key = wp_unslash($meta_key); |
170 |
$passed_value = $meta_value; |
|
171 |
$meta_value = wp_unslash($meta_value); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
$meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type, $meta_subtype ); |
0 | 173 |
|
5 | 174 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
* Filters whether to update metadata of a specific type. |
5 | 176 |
* |
177 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
178 |
* object type (comment, post, or user). Returning a non-null value |
|
179 |
* will effectively short-circuit the function. |
|
180 |
* |
|
181 |
* @since 3.1.0 |
|
182 |
* |
|
183 |
* @param null|bool $check Whether to allow updating metadata for the given type. |
|
184 |
* @param int $object_id Object ID. |
|
185 |
* @param string $meta_key Meta key. |
|
186 |
* @param mixed $meta_value Meta value. Must be serializable if non-scalar. |
|
187 |
* @param mixed $prev_value Optional. If specified, only update existing |
|
188 |
* metadata entries with the specified value. |
|
189 |
* Otherwise, update all entries. |
|
190 |
*/ |
|
0 | 191 |
$check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value ); |
192 |
if ( null !== $check ) |
|
193 |
return (bool) $check; |
|
194 |
||
195 |
// Compare existing value to new value if no prev value given and the key exists only once. |
|
196 |
if ( empty($prev_value) ) { |
|
197 |
$old_value = get_metadata($meta_type, $object_id, $meta_key); |
|
198 |
if ( count($old_value) == 1 ) { |
|
199 |
if ( $old_value[0] === $meta_value ) |
|
200 |
return false; |
|
201 |
} |
|
202 |
} |
|
203 |
||
5 | 204 |
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ); |
205 |
if ( empty( $meta_ids ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
return add_metadata( $meta_type, $object_id, $raw_meta_key, $passed_value ); |
5 | 207 |
} |
0 | 208 |
|
209 |
$_meta_value = $meta_value; |
|
210 |
$meta_value = maybe_serialize( $meta_value ); |
|
211 |
||
212 |
$data = compact( 'meta_value' ); |
|
213 |
$where = array( $column => $object_id, 'meta_key' => $meta_key ); |
|
214 |
||
215 |
if ( !empty( $prev_value ) ) { |
|
216 |
$prev_value = maybe_serialize($prev_value); |
|
217 |
$where['meta_value'] = $prev_value; |
|
218 |
} |
|
219 |
||
5 | 220 |
foreach ( $meta_ids as $meta_id ) { |
221 |
/** |
|
222 |
* Fires immediately before updating metadata of a specific type. |
|
223 |
* |
|
224 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
225 |
* object type (comment, post, or user). |
|
226 |
* |
|
227 |
* @since 2.9.0 |
|
228 |
* |
|
229 |
* @param int $meta_id ID of the metadata entry to update. |
|
230 |
* @param int $object_id Object ID. |
|
231 |
* @param string $meta_key Meta key. |
|
232 |
* @param mixed $meta_value Meta value. |
|
233 |
*/ |
|
234 |
do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
|
0 | 235 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
if ( 'post' == $meta_type ) { |
5 | 237 |
/** |
238 |
* Fires immediately before updating a post's metadata. |
|
239 |
* |
|
240 |
* @since 2.9.0 |
|
241 |
* |
|
242 |
* @param int $meta_id ID of metadata entry to update. |
|
243 |
* @param int $object_id Object ID. |
|
244 |
* @param string $meta_key Meta key. |
|
245 |
* @param mixed $meta_value Meta value. |
|
246 |
*/ |
|
247 |
do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
|
248 |
} |
|
249 |
} |
|
0 | 250 |
|
251 |
$result = $wpdb->update( $table, $data, $where ); |
|
252 |
if ( ! $result ) |
|
253 |
return false; |
|
254 |
||
255 |
wp_cache_delete($object_id, $meta_type . '_meta'); |
|
256 |
||
5 | 257 |
foreach ( $meta_ids as $meta_id ) { |
258 |
/** |
|
259 |
* Fires immediately after updating metadata of a specific type. |
|
260 |
* |
|
261 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
262 |
* object type (comment, post, or user). |
|
263 |
* |
|
264 |
* @since 2.9.0 |
|
265 |
* |
|
266 |
* @param int $meta_id ID of updated metadata entry. |
|
267 |
* @param int $object_id Object ID. |
|
268 |
* @param string $meta_key Meta key. |
|
269 |
* @param mixed $meta_value Meta value. |
|
270 |
*/ |
|
271 |
do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
|
0 | 272 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
if ( 'post' == $meta_type ) { |
5 | 274 |
/** |
275 |
* Fires immediately after updating a post's metadata. |
|
276 |
* |
|
277 |
* @since 2.9.0 |
|
278 |
* |
|
279 |
* @param int $meta_id ID of updated metadata entry. |
|
280 |
* @param int $object_id Object ID. |
|
281 |
* @param string $meta_key Meta key. |
|
282 |
* @param mixed $meta_value Meta value. |
|
283 |
*/ |
|
284 |
do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
|
285 |
} |
|
286 |
} |
|
0 | 287 |
|
288 |
return true; |
|
289 |
} |
|
290 |
||
291 |
/** |
|
292 |
* Delete metadata for the specified object. |
|
293 |
* |
|
294 |
* @since 2.9.0 |
|
5 | 295 |
* |
296 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 297 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
* @param int $object_id ID of the object metadata is for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
* @param string $meta_key Metadata key |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
* @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
* metadata entries with this value. Otherwise, delete all entries with the specified meta_key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
* Pass `null, `false`, or an empty string to skip this check. (For backward compatibility, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
* it is not possible to pass an empty string to delete those entries with an empty string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
* for a value.) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
* @param bool $delete_all Optional, default is false. If true, delete matching metadata entries for all objects, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
* ignoring the specified object_id. Otherwise, only delete matching metadata entries for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
* the specified object_id. |
0 | 309 |
* @return bool True on successful delete, false on failure. |
310 |
*/ |
|
311 |
function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false) { |
|
5 | 312 |
global $wpdb; |
0 | 313 |
|
5 | 314 |
if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) && ! $delete_all ) { |
0 | 315 |
return false; |
5 | 316 |
} |
0 | 317 |
|
5 | 318 |
$object_id = absint( $object_id ); |
319 |
if ( ! $object_id && ! $delete_all ) { |
|
0 | 320 |
return false; |
5 | 321 |
} |
0 | 322 |
|
5 | 323 |
$table = _get_meta_table( $meta_type ); |
324 |
if ( ! $table ) { |
|
325 |
return false; |
|
326 |
} |
|
0 | 327 |
|
328 |
$type_column = sanitize_key($meta_type . '_id'); |
|
329 |
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
|
330 |
// expected_slashed ($meta_key) |
|
331 |
$meta_key = wp_unslash($meta_key); |
|
332 |
$meta_value = wp_unslash($meta_value); |
|
333 |
||
5 | 334 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
* Filters whether to delete metadata of a specific type. |
5 | 336 |
* |
337 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
338 |
* object type (comment, post, or user). Returning a non-null value |
|
339 |
* will effectively short-circuit the function. |
|
340 |
* |
|
341 |
* @since 3.1.0 |
|
342 |
* |
|
343 |
* @param null|bool $delete Whether to allow metadata deletion of the given type. |
|
344 |
* @param int $object_id Object ID. |
|
345 |
* @param string $meta_key Meta key. |
|
346 |
* @param mixed $meta_value Meta value. Must be serializable if non-scalar. |
|
347 |
* @param bool $delete_all Whether to delete the matching metadata entries |
|
348 |
* for all objects, ignoring the specified $object_id. |
|
349 |
* Default false. |
|
350 |
*/ |
|
0 | 351 |
$check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all ); |
352 |
if ( null !== $check ) |
|
353 |
return (bool) $check; |
|
354 |
||
355 |
$_meta_value = $meta_value; |
|
356 |
$meta_value = maybe_serialize( $meta_value ); |
|
357 |
||
358 |
$query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key ); |
|
359 |
||
360 |
if ( !$delete_all ) |
|
361 |
$query .= $wpdb->prepare(" AND $type_column = %d", $object_id ); |
|
362 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) |
0 | 364 |
$query .= $wpdb->prepare(" AND meta_value = %s", $meta_value ); |
365 |
||
366 |
$meta_ids = $wpdb->get_col( $query ); |
|
367 |
if ( !count( $meta_ids ) ) |
|
368 |
return false; |
|
369 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
if ( $delete_all ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
$object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s AND meta_value = %s", $meta_key, $meta_value ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
$object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
} |
0 | 377 |
|
5 | 378 |
/** |
379 |
* Fires immediately before deleting metadata of a specific type. |
|
380 |
* |
|
381 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
382 |
* object type (comment, post, or user). |
|
383 |
* |
|
384 |
* @since 3.1.0 |
|
385 |
* |
|
386 |
* @param array $meta_ids An array of metadata entry IDs to delete. |
|
387 |
* @param int $object_id Object ID. |
|
388 |
* @param string $meta_key Meta key. |
|
389 |
* @param mixed $meta_value Meta value. |
|
390 |
*/ |
|
0 | 391 |
do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); |
392 |
||
393 |
// Old-style action. |
|
5 | 394 |
if ( 'post' == $meta_type ) { |
395 |
/** |
|
396 |
* Fires immediately before deleting metadata for a post. |
|
397 |
* |
|
398 |
* @since 2.9.0 |
|
399 |
* |
|
400 |
* @param array $meta_ids An array of post metadata entry IDs to delete. |
|
401 |
*/ |
|
0 | 402 |
do_action( 'delete_postmeta', $meta_ids ); |
5 | 403 |
} |
0 | 404 |
|
405 |
$query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )"; |
|
406 |
||
407 |
$count = $wpdb->query($query); |
|
408 |
||
409 |
if ( !$count ) |
|
410 |
return false; |
|
411 |
||
412 |
if ( $delete_all ) { |
|
413 |
foreach ( (array) $object_ids as $o_id ) { |
|
414 |
wp_cache_delete($o_id, $meta_type . '_meta'); |
|
415 |
} |
|
416 |
} else { |
|
417 |
wp_cache_delete($object_id, $meta_type . '_meta'); |
|
418 |
} |
|
419 |
||
5 | 420 |
/** |
421 |
* Fires immediately after deleting metadata of a specific type. |
|
422 |
* |
|
423 |
* The dynamic portion of the hook name, `$meta_type`, refers to the meta |
|
424 |
* object type (comment, post, or user). |
|
425 |
* |
|
426 |
* @since 2.9.0 |
|
427 |
* |
|
428 |
* @param array $meta_ids An array of deleted metadata entry IDs. |
|
429 |
* @param int $object_id Object ID. |
|
430 |
* @param string $meta_key Meta key. |
|
431 |
* @param mixed $meta_value Meta value. |
|
432 |
*/ |
|
0 | 433 |
do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); |
434 |
||
435 |
// Old-style action. |
|
5 | 436 |
if ( 'post' == $meta_type ) { |
437 |
/** |
|
438 |
* Fires immediately after deleting metadata for a post. |
|
439 |
* |
|
440 |
* @since 2.9.0 |
|
441 |
* |
|
442 |
* @param array $meta_ids An array of deleted post metadata entry IDs. |
|
443 |
*/ |
|
0 | 444 |
do_action( 'deleted_postmeta', $meta_ids ); |
5 | 445 |
} |
0 | 446 |
|
447 |
return true; |
|
448 |
} |
|
449 |
||
450 |
/** |
|
451 |
* Retrieve metadata for the specified object. |
|
452 |
* |
|
453 |
* @since 2.9.0 |
|
454 |
* |
|
455 |
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
* @param int $object_id ID of the object metadata is for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
* @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
* the specified object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
* @param bool $single Optional, default is false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
* If true, return only the first value of the specified meta_key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
* This parameter has no effect if meta_key is not specified. |
5 | 462 |
* @return mixed Single metadata value, or array of values |
0 | 463 |
*/ |
464 |
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) { |
|
5 | 465 |
if ( ! $meta_type || ! is_numeric( $object_id ) ) { |
0 | 466 |
return false; |
5 | 467 |
} |
468 |
||
469 |
$object_id = absint( $object_id ); |
|
470 |
if ( ! $object_id ) { |
|
471 |
return false; |
|
472 |
} |
|
0 | 473 |
|
5 | 474 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
* Filters whether to retrieve metadata of a specific type. |
5 | 476 |
* |
477 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
478 |
* object type (comment, post, or user). Returning a non-null value |
|
479 |
* will effectively short-circuit the function. |
|
480 |
* |
|
481 |
* @since 3.1.0 |
|
482 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
* @param null|array|string $value The value get_metadata() should return - a single metadata value, |
5 | 484 |
* or an array of values. |
485 |
* @param int $object_id Object ID. |
|
486 |
* @param string $meta_key Meta key. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
* @param bool $single Whether to return only the first value of the specified $meta_key. |
5 | 488 |
*/ |
0 | 489 |
$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single ); |
490 |
if ( null !== $check ) { |
|
491 |
if ( $single && is_array( $check ) ) |
|
492 |
return $check[0]; |
|
493 |
else |
|
494 |
return $check; |
|
495 |
} |
|
496 |
||
497 |
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta'); |
|
498 |
||
499 |
if ( !$meta_cache ) { |
|
500 |
$meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); |
|
501 |
$meta_cache = $meta_cache[$object_id]; |
|
502 |
} |
|
503 |
||
5 | 504 |
if ( ! $meta_key ) { |
0 | 505 |
return $meta_cache; |
5 | 506 |
} |
0 | 507 |
|
508 |
if ( isset($meta_cache[$meta_key]) ) { |
|
509 |
if ( $single ) |
|
510 |
return maybe_unserialize( $meta_cache[$meta_key][0] ); |
|
511 |
else |
|
512 |
return array_map('maybe_unserialize', $meta_cache[$meta_key]); |
|
513 |
} |
|
514 |
||
515 |
if ($single) |
|
516 |
return ''; |
|
517 |
else |
|
518 |
return array(); |
|
519 |
} |
|
520 |
||
521 |
/** |
|
522 |
* Determine if a meta key is set for a given object |
|
523 |
* |
|
524 |
* @since 3.3.0 |
|
525 |
* |
|
526 |
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
* @param int $object_id ID of the object metadata is for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
* @param string $meta_key Metadata key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
* @return bool True of the key is set, false if not. |
0 | 530 |
*/ |
531 |
function metadata_exists( $meta_type, $object_id, $meta_key ) { |
|
5 | 532 |
if ( ! $meta_type || ! is_numeric( $object_id ) ) { |
0 | 533 |
return false; |
5 | 534 |
} |
0 | 535 |
|
5 | 536 |
$object_id = absint( $object_id ); |
537 |
if ( ! $object_id ) { |
|
0 | 538 |
return false; |
5 | 539 |
} |
0 | 540 |
|
5 | 541 |
/** This filter is documented in wp-includes/meta.php */ |
0 | 542 |
$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true ); |
543 |
if ( null !== $check ) |
|
5 | 544 |
return (bool) $check; |
0 | 545 |
|
546 |
$meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' ); |
|
547 |
||
548 |
if ( !$meta_cache ) { |
|
549 |
$meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); |
|
550 |
$meta_cache = $meta_cache[$object_id]; |
|
551 |
} |
|
552 |
||
553 |
if ( isset( $meta_cache[ $meta_key ] ) ) |
|
554 |
return true; |
|
555 |
||
556 |
return false; |
|
557 |
} |
|
558 |
||
559 |
/** |
|
560 |
* Get meta data by meta ID |
|
561 |
* |
|
562 |
* @since 3.3.0 |
|
563 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
* @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
* @param int $meta_id ID for a specific meta row |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
* @return object|false Meta object or false. |
0 | 569 |
*/ |
570 |
function get_metadata_by_mid( $meta_type, $meta_id ) { |
|
571 |
global $wpdb; |
|
572 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) { |
0 | 574 |
return false; |
5 | 575 |
} |
0 | 576 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
$meta_id = intval( $meta_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
if ( $meta_id <= 0 ) { |
0 | 579 |
return false; |
5 | 580 |
} |
0 | 581 |
|
5 | 582 |
$table = _get_meta_table( $meta_type ); |
583 |
if ( ! $table ) { |
|
0 | 584 |
return false; |
5 | 585 |
} |
0 | 586 |
|
587 |
$id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id'; |
|
588 |
||
589 |
$meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) ); |
|
590 |
||
591 |
if ( empty( $meta ) ) |
|
592 |
return false; |
|
593 |
||
594 |
if ( isset( $meta->meta_value ) ) |
|
595 |
$meta->meta_value = maybe_unserialize( $meta->meta_value ); |
|
596 |
||
597 |
return $meta; |
|
598 |
} |
|
599 |
||
600 |
/** |
|
601 |
* Update meta data by meta ID |
|
602 |
* |
|
603 |
* @since 3.3.0 |
|
604 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
* @param int $meta_id ID for a specific meta row |
0 | 609 |
* @param string $meta_value Metadata value |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
* @param string $meta_key Optional, you can provide a meta key to update it |
0 | 611 |
* @return bool True on successful update, false on failure. |
612 |
*/ |
|
613 |
function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = false ) { |
|
614 |
global $wpdb; |
|
615 |
||
616 |
// Make sure everything is valid. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) { |
0 | 618 |
return false; |
5 | 619 |
} |
0 | 620 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
$meta_id = intval( $meta_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
if ( $meta_id <= 0 ) { |
0 | 623 |
return false; |
5 | 624 |
} |
0 | 625 |
|
5 | 626 |
$table = _get_meta_table( $meta_type ); |
627 |
if ( ! $table ) { |
|
0 | 628 |
return false; |
5 | 629 |
} |
0 | 630 |
|
631 |
$column = sanitize_key($meta_type . '_id'); |
|
632 |
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
|
633 |
||
634 |
// Fetch the meta and go on if it's found. |
|
635 |
if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { |
|
636 |
$original_key = $meta->meta_key; |
|
637 |
$object_id = $meta->{$column}; |
|
638 |
||
639 |
// If a new meta_key (last parameter) was specified, change the meta key, |
|
640 |
// otherwise use the original key in the update statement. |
|
641 |
if ( false === $meta_key ) { |
|
642 |
$meta_key = $original_key; |
|
643 |
} elseif ( ! is_string( $meta_key ) ) { |
|
644 |
return false; |
|
645 |
} |
|
646 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
$meta_subtype = get_object_subtype( $meta_type, $object_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
|
0 | 649 |
// Sanitize the meta |
650 |
$_meta_value = $meta_value; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
$meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type, $meta_subtype ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
$meta_value = maybe_serialize( $meta_value ); |
0 | 653 |
|
654 |
// Format the data query arguments. |
|
655 |
$data = array( |
|
656 |
'meta_key' => $meta_key, |
|
657 |
'meta_value' => $meta_value |
|
658 |
); |
|
659 |
||
660 |
// Format the where query arguments. |
|
661 |
$where = array(); |
|
662 |
$where[$id_column] = $meta_id; |
|
663 |
||
5 | 664 |
/** This action is documented in wp-includes/meta.php */ |
0 | 665 |
do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
666 |
||
5 | 667 |
if ( 'post' == $meta_type ) { |
668 |
/** This action is documented in wp-includes/meta.php */ |
|
0 | 669 |
do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
5 | 670 |
} |
0 | 671 |
|
672 |
// Run the update query, all fields in $data are %s, $where is a %d. |
|
673 |
$result = $wpdb->update( $table, $data, $where, '%s', '%d' ); |
|
674 |
if ( ! $result ) |
|
675 |
return false; |
|
676 |
||
677 |
// Clear the caches. |
|
678 |
wp_cache_delete($object_id, $meta_type . '_meta'); |
|
679 |
||
5 | 680 |
/** This action is documented in wp-includes/meta.php */ |
0 | 681 |
do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
682 |
||
5 | 683 |
if ( 'post' == $meta_type ) { |
684 |
/** This action is documented in wp-includes/meta.php */ |
|
0 | 685 |
do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
5 | 686 |
} |
0 | 687 |
|
688 |
return true; |
|
689 |
} |
|
690 |
||
691 |
// And if the meta was not found. |
|
692 |
return false; |
|
693 |
} |
|
694 |
||
695 |
/** |
|
696 |
* Delete meta data by meta ID |
|
697 |
* |
|
698 |
* @since 3.3.0 |
|
699 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
* @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
* @param int $meta_id ID for a specific meta row |
0 | 704 |
* @return bool True on successful delete, false on failure. |
705 |
*/ |
|
706 |
function delete_metadata_by_mid( $meta_type, $meta_id ) { |
|
707 |
global $wpdb; |
|
708 |
||
709 |
// Make sure everything is valid. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) { |
0 | 711 |
return false; |
5 | 712 |
} |
0 | 713 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
$meta_id = intval( $meta_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
if ( $meta_id <= 0 ) { |
0 | 716 |
return false; |
5 | 717 |
} |
0 | 718 |
|
5 | 719 |
$table = _get_meta_table( $meta_type ); |
720 |
if ( ! $table ) { |
|
0 | 721 |
return false; |
5 | 722 |
} |
0 | 723 |
|
724 |
// object and id columns |
|
725 |
$column = sanitize_key($meta_type . '_id'); |
|
726 |
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
|
727 |
||
728 |
// Fetch the meta and go on if it's found. |
|
729 |
if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { |
|
730 |
$object_id = $meta->{$column}; |
|
731 |
||
5 | 732 |
/** This action is documented in wp-includes/meta.php */ |
0 | 733 |
do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); |
734 |
||
735 |
// Old-style action. |
|
5 | 736 |
if ( 'post' == $meta_type || 'comment' == $meta_type ) { |
737 |
/** |
|
738 |
* Fires immediately before deleting post or comment metadata of a specific type. |
|
739 |
* |
|
740 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
741 |
* object type (post or comment). |
|
742 |
* |
|
743 |
* @since 3.4.0 |
|
744 |
* |
|
745 |
* @param int $meta_id ID of the metadata entry to delete. |
|
746 |
*/ |
|
0 | 747 |
do_action( "delete_{$meta_type}meta", $meta_id ); |
5 | 748 |
} |
0 | 749 |
|
750 |
// Run the query, will return true if deleted, false otherwise |
|
751 |
$result = (bool) $wpdb->delete( $table, array( $id_column => $meta_id ) ); |
|
752 |
||
753 |
// Clear the caches. |
|
754 |
wp_cache_delete($object_id, $meta_type . '_meta'); |
|
755 |
||
5 | 756 |
/** This action is documented in wp-includes/meta.php */ |
0 | 757 |
do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); |
758 |
||
759 |
// Old-style action. |
|
5 | 760 |
if ( 'post' == $meta_type || 'comment' == $meta_type ) { |
761 |
/** |
|
762 |
* Fires immediately after deleting post or comment metadata of a specific type. |
|
763 |
* |
|
764 |
* The dynamic portion of the hook, `$meta_type`, refers to the meta |
|
765 |
* object type (post or comment). |
|
766 |
* |
|
767 |
* @since 3.4.0 |
|
768 |
* |
|
769 |
* @param int $meta_ids Deleted metadata entry ID. |
|
770 |
*/ |
|
0 | 771 |
do_action( "deleted_{$meta_type}meta", $meta_id ); |
5 | 772 |
} |
0 | 773 |
|
774 |
return $result; |
|
775 |
||
776 |
} |
|
777 |
||
778 |
// Meta id was not found. |
|
779 |
return false; |
|
780 |
} |
|
781 |
||
782 |
/** |
|
783 |
* Update the metadata cache for the specified objects. |
|
784 |
* |
|
785 |
* @since 2.9.0 |
|
5 | 786 |
* |
787 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 788 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
* @param int|array $object_ids Array or comma delimited list of object IDs to update cache for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
* @return array|false Metadata cache for the specified objects, or false on failure. |
0 | 792 |
*/ |
793 |
function update_meta_cache($meta_type, $object_ids) { |
|
5 | 794 |
global $wpdb; |
0 | 795 |
|
5 | 796 |
if ( ! $meta_type || ! $object_ids ) { |
0 | 797 |
return false; |
5 | 798 |
} |
799 |
||
800 |
$table = _get_meta_table( $meta_type ); |
|
801 |
if ( ! $table ) { |
|
802 |
return false; |
|
803 |
} |
|
0 | 804 |
|
805 |
$column = sanitize_key($meta_type . '_id'); |
|
806 |
||
807 |
if ( !is_array($object_ids) ) { |
|
808 |
$object_ids = preg_replace('|[^0-9,]|', '', $object_ids); |
|
809 |
$object_ids = explode(',', $object_ids); |
|
810 |
} |
|
811 |
||
812 |
$object_ids = array_map('intval', $object_ids); |
|
813 |
||
814 |
$cache_key = $meta_type . '_meta'; |
|
815 |
$ids = array(); |
|
816 |
$cache = array(); |
|
817 |
foreach ( $object_ids as $id ) { |
|
818 |
$cached_object = wp_cache_get( $id, $cache_key ); |
|
819 |
if ( false === $cached_object ) |
|
820 |
$ids[] = $id; |
|
821 |
else |
|
822 |
$cache[$id] = $cached_object; |
|
823 |
} |
|
824 |
||
825 |
if ( empty( $ids ) ) |
|
826 |
return $cache; |
|
827 |
||
828 |
// Get meta info |
|
5 | 829 |
$id_list = join( ',', $ids ); |
830 |
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
|
831 |
$meta_list = $wpdb->get_results( "SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) ORDER BY $id_column ASC", ARRAY_A ); |
|
0 | 832 |
|
833 |
if ( !empty($meta_list) ) { |
|
834 |
foreach ( $meta_list as $metarow) { |
|
835 |
$mpid = intval($metarow[$column]); |
|
836 |
$mkey = $metarow['meta_key']; |
|
837 |
$mval = $metarow['meta_value']; |
|
838 |
||
839 |
// Force subkeys to be array type: |
|
840 |
if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) ) |
|
841 |
$cache[$mpid] = array(); |
|
842 |
if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) ) |
|
843 |
$cache[$mpid][$mkey] = array(); |
|
844 |
||
845 |
// Add a value to the current pid/key: |
|
846 |
$cache[$mpid][$mkey][] = $mval; |
|
847 |
} |
|
848 |
} |
|
849 |
||
850 |
foreach ( $ids as $id ) { |
|
851 |
if ( ! isset($cache[$id]) ) |
|
852 |
$cache[$id] = array(); |
|
853 |
wp_cache_add( $id, $cache[$id], $cache_key ); |
|
854 |
} |
|
855 |
||
856 |
return $cache; |
|
857 |
} |
|
858 |
||
859 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
* Retrieves the queue for lazy-loading metadata. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
* @return WP_Metadata_Lazyloader $lazyloader Metadata lazyloader queue. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
function wp_metadata_lazyloader() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
static $wp_metadata_lazyloader; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
if ( null === $wp_metadata_lazyloader ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
$wp_metadata_lazyloader = new WP_Metadata_Lazyloader(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
return $wp_metadata_lazyloader; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
/** |
5 | 877 |
* Given a meta query, generates SQL clauses to be appended to a main query. |
0 | 878 |
* |
879 |
* @since 3.2.0 |
|
880 |
* |
|
881 |
* @see WP_Meta_Query |
|
882 |
* |
|
5 | 883 |
* @param array $meta_query A meta query. |
884 |
* @param string $type Type of meta. |
|
885 |
* @param string $primary_table Primary database table name. |
|
886 |
* @param string $primary_id_column Primary ID column name. |
|
887 |
* @param object $context Optional. The main query object |
|
888 |
* @return array Associative array of `JOIN` and `WHERE` SQL. |
|
0 | 889 |
*/ |
890 |
function get_meta_sql( $meta_query, $type, $primary_table, $primary_id_column, $context = null ) { |
|
891 |
$meta_query_obj = new WP_Meta_Query( $meta_query ); |
|
892 |
return $meta_query_obj->get_sql( $type, $primary_table, $primary_id_column, $context ); |
|
893 |
} |
|
894 |
||
895 |
/** |
|
896 |
* Retrieve the name of the metadata table for the specified object type. |
|
897 |
* |
|
898 |
* @since 2.9.0 |
|
5 | 899 |
* |
900 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 901 |
* |
902 |
* @param string $type Type of object to get metadata table for (e.g., comment, post, or user) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
* @return string|false Metadata table name, or false if no metadata table exists |
0 | 904 |
*/ |
905 |
function _get_meta_table($type) { |
|
906 |
global $wpdb; |
|
907 |
||
908 |
$table_name = $type . 'meta'; |
|
909 |
||
910 |
if ( empty($wpdb->$table_name) ) |
|
911 |
return false; |
|
912 |
||
913 |
return $wpdb->$table_name; |
|
914 |
} |
|
915 |
||
916 |
/** |
|
5 | 917 |
* Determine whether a meta key is protected. |
0 | 918 |
* |
919 |
* @since 3.1.3 |
|
920 |
* |
|
5 | 921 |
* @param string $meta_key Meta key |
922 |
* @param string|null $meta_type |
|
0 | 923 |
* @return bool True if the key is protected, false otherwise. |
924 |
*/ |
|
925 |
function is_protected_meta( $meta_key, $meta_type = null ) { |
|
926 |
$protected = ( '_' == $meta_key[0] ); |
|
927 |
||
5 | 928 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
* Filters whether a meta key is protected. |
5 | 930 |
* |
931 |
* @since 3.2.0 |
|
932 |
* |
|
933 |
* @param bool $protected Whether the key is protected. Default false. |
|
934 |
* @param string $meta_key Meta key. |
|
935 |
* @param string $meta_type Meta type. |
|
936 |
*/ |
|
0 | 937 |
return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type ); |
938 |
} |
|
939 |
||
940 |
/** |
|
5 | 941 |
* Sanitize meta value. |
0 | 942 |
* |
943 |
* @since 3.1.3 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
* @since 4.9.8 The `$object_subtype` parameter was added. |
0 | 945 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
* @param string $meta_key Meta key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
947 |
* @param mixed $meta_value Meta value to sanitize. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
* @param string $object_type Type of object the meta is registered to. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
* @return mixed Sanitized $meta_value. |
0 | 951 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
if ( ! empty( $object_subtype ) && has_filter( "sanitize_{$object_type}_meta_{$meta_key}_for_{$object_subtype}" ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
* Filters the sanitization of a specific meta key of a specific meta type and subtype. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
* The dynamic portions of the hook name, `$object_type`, `$meta_key`, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
959 |
* and `$object_subtype`, refer to the metadata object type (comment, post, term or user), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
* the meta key value, and the object subtype respectively. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
962 |
* @since 4.9.8 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
963 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
* @param mixed $meta_value Meta value to sanitize. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
* @param string $meta_key Meta key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
* @param string $object_type Object type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
* @param string $object_subtype Object subtype. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
969 |
return apply_filters( "sanitize_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $meta_value, $meta_key, $object_type, $object_subtype ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
} |
5 | 971 |
|
972 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
973 |
* Filters the sanitization of a specific meta key of a specific meta type. |
5 | 974 |
* |
975 |
* The dynamic portions of the hook name, `$meta_type`, and `$meta_key`, |
|
976 |
* refer to the metadata object type (comment, post, or user) and the meta |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
* key value, respectively. |
5 | 978 |
* |
979 |
* @since 3.3.0 |
|
980 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
* @param mixed $meta_value Meta value to sanitize. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
* @param string $meta_key Meta key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
* @param string $object_type Object type. |
5 | 984 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
return apply_filters( "sanitize_{$object_type}_meta_{$meta_key}", $meta_value, $meta_key, $object_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
* Registers a meta key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
* It is recommended to register meta keys for a specific combination of object type and object subtype. If passing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
* an object subtype is omitted, the meta key will be registered for the entire object type, however it can be partly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
* overridden in case a more specific meta key of the same name exists for the same object type and a subtype. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
* If an object type does not support any subtypes, such as users or comments, you should commonly call this function |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
* without passing a subtype. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
* @since 3.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
* @since 4.6.0 {@link https://core.trac.wordpress.org/ticket/35658 Modified |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
* to support an array of data to attach to registered meta keys}. Previous arguments for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
* `$sanitize_callback` and `$auth_callback` have been folded into this array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
* @since 4.9.8 The `$object_subtype` argument was added to the arguments array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
* @param string $object_type Type of object this meta is registered to. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
* @param string $meta_key Meta key to register. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
* Data used to describe the meta key when registered. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
* @type string $object_subtype A subtype; e.g. if the object type is "post", the post type. If left empty, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1010 |
* the meta key will be registered on the entire object type. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
* @type string $type The type of data associated with this meta key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
* Valid values are 'string', 'boolean', 'integer', and 'number'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1013 |
* @type string $description A description of the data attached to this meta key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1014 |
* @type bool $single Whether the meta key has one value per object, or an array of values per object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1015 |
* @type string $sanitize_callback A function or method to call when sanitizing `$meta_key` data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
* @type string $auth_callback Optional. A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1017 |
* @type bool $show_in_rest Whether data associated with this meta key can be considered public. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1018 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
* @param string|array $deprecated Deprecated. Use `$args` instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
* @return bool True if the meta key was successfully registered in the global array, false if not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
* Registering a meta key with distinct sanitize and auth callbacks will fire those |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1023 |
* callbacks, but will not add to the global registry. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
global $wp_meta_keys; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
if ( ! is_array( $wp_meta_keys ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
$wp_meta_keys = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
'object_subtype' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
'type' => 'string', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
'description' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
'single' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
'sanitize_callback' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
'auth_callback' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
'show_in_rest' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
// There used to be individual args for sanitize and auth callbacks |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
$has_old_sanitize_cb = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
$has_old_auth_cb = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
if ( is_callable( $args ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
$args = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
'sanitize_callback' => $args, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
$has_old_sanitize_cb = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
$args = (array) $args; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
if ( is_callable( $deprecated ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
$args['auth_callback'] = $deprecated; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
$has_old_auth_cb = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
* Filters the registration arguments when registering meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
* @param array $args Array of meta registration arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
* @param array $defaults Array of default arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
* @param string $object_type Object type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
* @param string $meta_key Meta key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
$args = apply_filters( 'register_meta_args', $args, $defaults, $object_type, $meta_key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1072 |
$args = wp_parse_args( $args, $defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
$object_subtype = ! empty( $args['object_subtype'] ) ? $args['object_subtype'] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
// If `auth_callback` is not provided, fall back to `is_protected_meta()`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
if ( empty( $args['auth_callback'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
if ( is_protected_meta( $meta_key, $object_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1079 |
$args['auth_callback'] = '__return_false'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
$args['auth_callback'] = '__return_true'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1083 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
// Back-compat: old sanitize and auth callbacks are applied to all of an object type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
if ( is_callable( $args['sanitize_callback'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
if ( ! empty( $object_subtype ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
add_filter( "sanitize_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['sanitize_callback'], 10, 4 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
add_filter( "sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'], 10, 3 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
if ( is_callable( $args['auth_callback'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
if ( ! empty( $object_subtype ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
add_filter( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['auth_callback'], 10, 6 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
add_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'], 10, 6 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
// Global registry only contains meta keys registered with the array of arguments added in 4.6.0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
if ( ! $has_old_auth_cb && ! $has_old_sanitize_cb ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
unset( $args['object_subtype'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
$wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ] = $args; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
* Checks if a meta key is registered. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
* @since 4.9.8 The `$object_subtype` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1119 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
* @param string $object_type The type of object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
* @param string $meta_key The meta key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
* @param string $object_subtype Optional. The subtype of the object type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
* @return bool True if the meta key is registered to the object type and, if provided, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
* the object subtype. False if not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
function registered_meta_key_exists( $object_type, $meta_key, $object_subtype = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
$meta_keys = get_registered_meta_keys( $object_type, $object_subtype ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
return isset( $meta_keys[ $meta_key ] ); |
0 | 1131 |
} |
1132 |
||
1133 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1134 |
* Unregisters a meta key from the list of registered keys. |
0 | 1135 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1136 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
* @since 4.9.8 The `$object_subtype` parameter was added. |
0 | 1138 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
* @param string $object_type The type of object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
* @param string $meta_key The meta key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
* @param string $object_subtype Optional. The subtype of the object type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
* @return bool True if successful. False if the meta key was not registered. |
0 | 1143 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
function unregister_meta_key( $object_type, $meta_key, $object_subtype = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1145 |
global $wp_meta_keys; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
if ( ! registered_meta_key_exists( $object_type, $meta_key, $object_subtype ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1149 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
$args = $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1152 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
if ( isset( $args['sanitize_callback'] ) && is_callable( $args['sanitize_callback'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1154 |
if ( ! empty( $object_subtype ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
remove_filter( "sanitize_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['sanitize_callback'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1157 |
remove_filter( "sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1158 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1159 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
if ( isset( $args['auth_callback'] ) && is_callable( $args['auth_callback'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
if ( ! empty( $object_subtype ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
remove_filter( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['auth_callback'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
remove_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
unset( $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ] ); |
0 | 1170 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
// Do some clean up |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
if ( empty( $wp_meta_keys[ $object_type ][ $object_subtype ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
unset( $wp_meta_keys[ $object_type ][ $object_subtype ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
if ( empty( $wp_meta_keys[ $object_type ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
unset( $wp_meta_keys[ $object_type ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
* Retrieves a list of registered meta keys for an object type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1185 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1186 |
* @since 4.9.8 The `$object_subtype` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
* @param string $object_type The type of object. Post, comment, user, term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
* @param string $object_subtype Optional. The subtype of the object type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
* @return array List of registered meta keys. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1192 |
function get_registered_meta_keys( $object_type, $object_subtype = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
global $wp_meta_keys; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
if ( ! is_array( $wp_meta_keys ) || ! isset( $wp_meta_keys[ $object_type ] ) || ! isset( $wp_meta_keys[ $object_type ][ $object_subtype ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1196 |
return array(); |
0 | 1197 |
} |
1198 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1199 |
return $wp_meta_keys[ $object_type ][ $object_subtype ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1200 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1201 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1202 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1203 |
* Retrieves registered metadata for a specified object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1204 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
* The results include both meta that is registered specifically for the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1206 |
* object's subtype and meta that is registered for the entire object type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1208 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1209 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
* @param string $object_type Type of object to request metadata for. (e.g. comment, post, term, user) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
* @param int $object_id ID of the object the metadata is for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
* @param string $meta_key Optional. Registered metadata key. If not specified, retrieve all registered |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
* metadata for the specified object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
* @return mixed A single value or array of values for a key if specified. An array of all registered keys |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
* and values for an object ID if not. False if a given $meta_key is not registered. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
function get_registered_metadata( $object_type, $object_id, $meta_key = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
$object_subtype = get_object_subtype( $object_type, $object_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
if ( ! empty( $meta_key ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1221 |
if ( ! empty( $object_subtype ) && ! registered_meta_key_exists( $object_type, $meta_key, $object_subtype ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
$object_subtype = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1223 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
if ( ! registered_meta_key_exists( $object_type, $meta_key, $object_subtype ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
$meta_keys = get_registered_meta_keys( $object_type, $object_subtype ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
$meta_key_data = $meta_keys[ $meta_key ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
$data = get_metadata( $object_type, $object_id, $meta_key, $meta_key_data['single'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
return $data; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
$data = get_metadata( $object_type, $object_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1238 |
if ( ! $data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
return array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
$meta_keys = get_registered_meta_keys( $object_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
if ( ! empty( $object_subtype ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
$meta_keys = array_merge( $meta_keys, get_registered_meta_keys( $object_type, $object_subtype ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
return array_intersect_key( $data, $meta_keys ); |
0 | 1248 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
* Filter out `register_meta()` args based on a whitelist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
* `register_meta()` args may change over time, so requiring the whitelist |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
* to be explicitly turned off is a warranty seal of sorts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
* @param array $args Arguments from `register_meta()`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
* @param array $default_args Default arguments for `register_meta()`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
* @return array Filtered arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1262 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1263 |
function _wp_register_meta_args_whitelist( $args, $default_args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
return array_intersect_key( $args, $default_args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1265 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1267 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
* Returns the object subtype for a given object ID of a specific type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1270 |
* @since 4.9.8 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1272 |
* @param string $object_type Type of object to request metadata for. (e.g. comment, post, term, user) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1273 |
* @param int $object_id ID of the object to retrieve its subtype. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1274 |
* @return string The object subtype or an empty string if unspecified subtype. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1275 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1276 |
function get_object_subtype( $object_type, $object_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
$object_id = (int) $object_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
$object_subtype = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
switch ( $object_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
case 'post': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
$post_type = get_post_type( $object_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
if ( ! empty( $post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
$object_subtype = $post_type; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1288 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1289 |
case 'term': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1290 |
$term = get_term( $object_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
if ( ! $term instanceof WP_Term ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1292 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1293 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1294 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1295 |
$object_subtype = $term->taxonomy; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1296 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1297 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
case 'comment': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1299 |
$comment = get_comment( $object_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1300 |
if ( ! $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1302 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
$object_subtype = 'comment'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
case 'user': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
$user = get_user_by( 'id', $object_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
if ( ! $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
$object_subtype = 'user'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
* Filters the object subtype identifier for a non standard object type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
* The dynamic portion of the hook, `$object_type`, refers to the object |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
* type (post, comment, term, or user). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
* @since 4.9.8 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
* @param string $object_subtype Empty string to override. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1326 |
* @param int $object_id ID of the object to get the subtype for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
return apply_filters( "get_object_subtype_{$object_type}", $object_subtype, $object_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1329 |
} |