diff --git wp-includes/meta.php wp-includes/meta.php
index 4066781..c55290d 100644
|
|
function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = |
47 | 47 | $meta_value = wp_unslash($meta_value); |
48 | 48 | $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type ); |
49 | 49 | |
| 50 | /** |
| 51 | * Filter to apply before adding the metadata to the database to allow overriding what is |
| 52 | * returned by add_metadata(). |
| 53 | * |
| 54 | * @since 3.1.0 |
| 55 | * |
| 56 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 57 | * @param int|null null The value add_metadata() should return. The meta ID on successful update, false on failure. |
| 58 | * @param int $object_id ID of the object metadata is for. |
| 59 | * @param string $meta_key Metadata key. |
| 60 | * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
| 61 | * @param bool $unique Optional, default is false. Whether the specified metadata key should be |
| 62 | * unique for the object. If true, and the object already has a value for the specified |
| 63 | * metadata key, no change will be made. |
| 64 | */ |
50 | 65 | $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique ); |
51 | 66 | if ( null !== $check ) |
52 | 67 | return $check; |
… |
… |
function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = |
59 | 74 | $_meta_value = $meta_value; |
60 | 75 | $meta_value = maybe_serialize( $meta_value ); |
61 | 76 | |
| 77 | /** |
| 78 | * Fires before adding metadata to the database. |
| 79 | * |
| 80 | * @since 3.1.0 |
| 81 | * |
| 82 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 83 | * @param int $object_id ID of the object metadata is for. |
| 84 | * @param string $meta_key Metadata key. |
| 85 | * @param mixed $_meta_value Metadata value. |
| 86 | */ |
62 | 87 | do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value ); |
63 | 88 | |
64 | 89 | $result = $wpdb->insert( $table, array( |
… |
… |
function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = |
74 | 99 | |
75 | 100 | wp_cache_delete($object_id, $meta_type . '_meta'); |
76 | 101 | |
| 102 | /** |
| 103 | * Fires after adding metadata to the database. |
| 104 | * |
| 105 | * @since 2.9.0 |
| 106 | * |
| 107 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 108 | * @param int $object_id ID of the object metadata is for. |
| 109 | * @param string $meta_key Metadata key. |
| 110 | * @param mixed $_meta_value Metadata value. |
| 111 | * @param int $mid The meta ID after successful update. |
| 112 | */ |
77 | 113 | do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value ); |
78 | 114 | |
79 | 115 | return $mid; |
… |
… |
function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v |
119 | 155 | $meta_value = wp_unslash($meta_value); |
120 | 156 | $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type ); |
121 | 157 | |
| 158 | /** |
| 159 | * Filter before updating the metadata in the database to allow overriding what is returned by update_metadata(). |
| 160 | * |
| 161 | * @since 3.1.0 |
| 162 | * |
| 163 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 164 | * @param bool|null null The value update_metadata() should return. True on successful update, false on failure. |
| 165 | * @param int $object_id ID of the object metadata is for. |
| 166 | * @param string $meta_key Metadata key. |
| 167 | * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
| 168 | * @param mixed $prev_value Optional. If specified, only update existing metadata entries with |
| 169 | * the specified value. Otherwise, update all entries. |
| 170 | */ |
122 | 171 | $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value ); |
123 | 172 | if ( null !== $check ) |
124 | 173 | return (bool) $check; |
… |
… |
function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v |
146 | 195 | $where['meta_value'] = $prev_value; |
147 | 196 | } |
148 | 197 | |
| 198 | /** |
| 199 | * Fires before updating metadata in the database. |
| 200 | * |
| 201 | * @since 2.9.0 |
| 202 | * |
| 203 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 204 | * @param int $meta_id of metadata entry to update |
| 205 | * @param int $object_id ID of the object metadata is for |
| 206 | * @param string $meta_key Metadata key |
| 207 | * @param mixed $_meta_value Metadata value. |
| 208 | */ |
149 | 209 | do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
150 | 210 | |
151 | 211 | if ( 'post' == $meta_type ) |
| 212 | /** |
| 213 | * Fires before updating metadata in the database when Meta Type is 'post'. |
| 214 | * |
| 215 | * @since 3.3.0 |
| 216 | * |
| 217 | * @param int $meta_id of metadata entry to update |
| 218 | * @param int $object_id ID of the object metadata is for |
| 219 | * @param string $meta_key Metadata key |
| 220 | * @param mixed $meta_value Metadata value. |
| 221 | */ |
152 | 222 | do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
153 | 223 | |
154 | 224 | $result = $wpdb->update( $table, $data, $where ); |
… |
… |
function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v |
157 | 227 | |
158 | 228 | wp_cache_delete($object_id, $meta_type . '_meta'); |
159 | 229 | |
| 230 | /** |
| 231 | * Fires after updating metadata in the database. |
| 232 | * |
| 233 | * @since 2.9.0 |
| 234 | * |
| 235 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 236 | * @param int $meta_id of updated metadata entry. |
| 237 | * @param int $object_id ID of the object metadata is for. |
| 238 | * @param string $meta_key Metadata key. |
| 239 | * @param mixed $_meta_value Metadata value. |
| 240 | */ |
160 | 241 | do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
161 | 242 | |
162 | 243 | if ( 'post' == $meta_type ) |
| 244 | /** |
| 245 | * Fires after updating metadata in the database when meta type is 'post'. |
| 246 | * |
| 247 | * @since 3.3.0 |
| 248 | * |
| 249 | * @param int $meta_id of updated metadata entry. |
| 250 | * @param int $object_id ID of the object metadata is for. |
| 251 | * @param string $meta_key Metadata key. |
| 252 | * @param mixed $meta_value Metadata value. |
| 253 | */ |
163 | 254 | do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
164 | 255 | |
165 | 256 | return true; |
… |
… |
function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $d |
201 | 292 | $meta_key = wp_unslash($meta_key); |
202 | 293 | $meta_value = wp_unslash($meta_value); |
203 | 294 | |
| 295 | /** |
| 296 | * Filter before deleting the metadata from the database. If filter is applied, delete_metadata() |
| 297 | * immediately returns the value returned by the filter and does not delete metadata from database. |
| 298 | * |
| 299 | * @since 3.1.0 |
| 300 | * |
| 301 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 302 | * @param bool|null null The value delete_metadata() should return. |
| 303 | * @param int $object_id ID of the object metadata is for. |
| 304 | * @param string $meta_key Metadata key. |
| 305 | * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
| 306 | * @param bool $delete_all Optional, default is false. If true, delete matching metadata entries |
| 307 | * for all objects, ignoring the specified object_id. Otherwise, only delete matching |
| 308 | * metadata entries for the specified object_id. |
| 309 | */ |
204 | 310 | $check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all ); |
205 | 311 | if ( null !== $check ) |
206 | 312 | return (bool) $check; |
… |
… |
function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $d |
223 | 329 | if ( $delete_all ) |
224 | 330 | $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) ); |
225 | 331 | |
| 332 | /** |
| 333 | * Fires before deleting metadata from the database. |
| 334 | * |
| 335 | * @since 3.1.0 |
| 336 | * |
| 337 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 338 | * @param array $meta_ids Array of metadata entry IDs to delete. |
| 339 | * @param int $object_id ID of the object metadata is for. |
| 340 | * @param string $meta_key Metadata key. |
| 341 | * @param mixed $_meta_value Metadata value. |
| 342 | */ |
226 | 343 | do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); |
227 | 344 | |
228 | 345 | // Old-style action. |
229 | 346 | if ( 'post' == $meta_type ) |
| 347 | /** |
| 348 | * Fires before deleting metadata from the database when meta type is 'post'. |
| 349 | * |
| 350 | * @since 3.3.0 |
| 351 | * |
| 352 | * @param array $meta_ids Array of metadata entry IDs to delete. |
| 353 | */ |
230 | 354 | do_action( 'delete_postmeta', $meta_ids ); |
231 | 355 | |
232 | 356 | $query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )"; |
… |
… |
function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $d |
244 | 368 | wp_cache_delete($object_id, $meta_type . '_meta'); |
245 | 369 | } |
246 | 370 | |
| 371 | /** |
| 372 | * Fires after deleting metadata from the database. |
| 373 | * |
| 374 | * @since 2.9.0 |
| 375 | * |
| 376 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 377 | * @param array $meta_ids Array of deleted metadata entries. |
| 378 | * @param int $object_id ID of the object metadata is for. |
| 379 | * @param string $meta_key Metadata key. |
| 380 | * @param mixed $_meta_value Metadata value. |
| 381 | */ |
247 | 382 | do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); |
248 | 383 | |
249 | 384 | // Old-style action. |
250 | 385 | if ( 'post' == $meta_type ) |
| 386 | /** |
| 387 | * Fires after deleting metadata from the database when meta type is 'post'. |
| 388 | * |
| 389 | * @since 3.3.0 |
| 390 | * |
| 391 | * @param array $meta_ids Array of deleted metadata entry IDs. |
| 392 | */ |
251 | 393 | do_action( 'deleted_postmeta', $meta_ids ); |
252 | 394 | |
253 | 395 | return true; |
… |
… |
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) { |
273 | 415 | if ( !$object_id = absint($object_id) ) |
274 | 416 | return false; |
275 | 417 | |
| 418 | /** |
| 419 | * Filter metadata retrieval. |
| 420 | * |
| 421 | * @since 3.1.0 |
| 422 | * |
| 423 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 424 | * @param string|array|null null The value get_metadata() should return. Single metadata value, or array of values. |
| 425 | * @param int $object_id ID of the object metadata is for. |
| 426 | * @param string $meta_key Metadata key. |
| 427 | * @param string|array Single metadata value, or array of values |
| 428 | */ |
276 | 429 | $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single ); |
277 | 430 | if ( null !== $check ) { |
278 | 431 | if ( $single && is_array( $check ) ) |
… |
… |
function metadata_exists( $meta_type, $object_id, $meta_key ) { |
321 | 474 | if ( ! $object_id = absint( $object_id ) ) |
322 | 475 | return false; |
323 | 476 | |
| 477 | /** |
| 478 | * Filter the check if metadata exists. If non-null is returned, metadata_exists() returns true. |
| 479 | * |
| 480 | * @since 3.1.0 |
| 481 | * |
| 482 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 483 | * @param bool|null null The value returned by metadata_exists(); if non-null, true is returned. |
| 484 | * @param int $object_id ID of the object metadata is for. |
| 485 | * @param string $meta_key Metadata key. |
| 486 | * @param boolean true if the key is set, false if not. |
| 487 | */ |
324 | 488 | $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true ); |
325 | 489 | if ( null !== $check ) |
326 | 490 | return true; |
… |
… |
function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = |
431 | 595 | $where = array(); |
432 | 596 | $where[$id_column] = $meta_id; |
433 | 597 | |
| 598 | /** |
| 599 | * Fires before updating metadata in the database. |
| 600 | * |
| 601 | * @since 2.9.0 |
| 602 | * |
| 603 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 604 | * @param int $meta_id of metadata entry to update |
| 605 | * @param int $object_id ID of the object metadata is for |
| 606 | * @param string $meta_key Metadata key |
| 607 | * @param mixed $_meta_value Metadata value. |
| 608 | */ |
434 | 609 | do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
435 | 610 | |
436 | 611 | if ( 'post' == $meta_type ) |
| 612 | /** |
| 613 | * Fires before updating metadata in the database when Meta Type is 'post'. |
| 614 | * |
| 615 | * @since 3.3.0 |
| 616 | * |
| 617 | * @param int $meta_id of metadata entry to update |
| 618 | * @param int $object_id ID of the object metadata is for |
| 619 | * @param string $meta_key Metadata key |
| 620 | * @param mixed $meta_value Metadata value. |
| 621 | */ |
437 | 622 | do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
438 | 623 | |
439 | 624 | // Run the update query, all fields in $data are %s, $where is a %d. |
… |
… |
function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = |
444 | 629 | // Clear the caches. |
445 | 630 | wp_cache_delete($object_id, $meta_type . '_meta'); |
446 | 631 | |
| 632 | /** |
| 633 | * Fires after updating metadata in the database. |
| 634 | * |
| 635 | * @since 2.9.0 |
| 636 | * |
| 637 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 638 | * @param int $meta_id of updated metadata entry. |
| 639 | * @param int $object_id ID of the object metadata is for. |
| 640 | * @param string $meta_key Metadata key. |
| 641 | * @param mixed $_meta_value Metadata value. |
| 642 | */ |
447 | 643 | do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
448 | 644 | |
449 | 645 | if ( 'post' == $meta_type ) |
| 646 | /** |
| 647 | * Fires after updating metadata in the database when meta type is 'post'. |
| 648 | * |
| 649 | * @since 3.3.0 |
| 650 | * |
| 651 | * @param int $meta_id of updated metadata entry. |
| 652 | * @param int $object_id ID of the object metadata is for. |
| 653 | * @param string $meta_key Metadata key. |
| 654 | * @param mixed $meta_value Metadata value. |
| 655 | */ |
450 | 656 | do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
451 | 657 | |
452 | 658 | return true; |
… |
… |
function delete_metadata_by_mid( $meta_type, $meta_id ) { |
489 | 695 | if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { |
490 | 696 | $object_id = $meta->{$column}; |
491 | 697 | |
| 698 | /** |
| 699 | * Fires before deleting metadata from the database. |
| 700 | * |
| 701 | * @since 3.1.0 |
| 702 | * |
| 703 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 704 | * @param array $meta_id Array with single metadata entry ID to delete. |
| 705 | * @param int $object_id ID of the object metadata is for. |
| 706 | * @param string $meta->meta_key Metadata key. |
| 707 | * @param mixed $meta->meta_value Metadata value. |
| 708 | */ |
492 | 709 | do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); |
493 | 710 | |
494 | 711 | // Old-style action. |
495 | 712 | if ( 'post' == $meta_type || 'comment' == $meta_type ) |
| 713 | /** |
| 714 | * Fires before deleting metadata from the database when meta type is 'post'. |
| 715 | * |
| 716 | * @since 3.3.0 |
| 717 | * |
| 718 | * @param int $meta_id ID of metadata entry to delete. |
| 719 | */ |
496 | 720 | do_action( "delete_{$meta_type}meta", $meta_id ); |
497 | 721 | |
498 | 722 | // Run the query, will return true if deleted, false otherwise |
… |
… |
function delete_metadata_by_mid( $meta_type, $meta_id ) { |
501 | 725 | // Clear the caches. |
502 | 726 | wp_cache_delete($object_id, $meta_type . '_meta'); |
503 | 727 | |
| 728 | /** |
| 729 | * Fires after deleting metadata from the database. |
| 730 | * |
| 731 | * @since 2.9.0 |
| 732 | * |
| 733 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user). |
| 734 | * @param array $meta_id Array with single deleted metadata entry ID. |
| 735 | * @param int $object_id ID of the object metadata is for. |
| 736 | * @param string $meta->meta_key Metadata key. |
| 737 | * @param mixed $meta->meta_value Metadata value. |
| 738 | */ |
504 | 739 | do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); |
505 | 740 | |
506 | 741 | // Old-style action. |
507 | 742 | if ( 'post' == $meta_type || 'comment' == $meta_type ) |
| 743 | /** |
| 744 | * Fires after deleting metadata from the database when meta type is 'post'. |
| 745 | * |
| 746 | * @since 3.3.0 |
| 747 | * |
| 748 | * @param array $meta_ids ID of deleted metadata entry. |
| 749 | */ |
508 | 750 | do_action( "deleted_{$meta_type}meta", $meta_id ); |
509 | 751 | |
510 | 752 | return $result; |
… |
… |
class WP_Meta_Query { |
859 | 1101 | if ( ! empty( $join ) ) |
860 | 1102 | $join = ' ' . $join; |
861 | 1103 | |
| 1104 | /** |
| 1105 | * Filter the generated SQL clauses to be appended to a main query. |
| 1106 | * |
| 1107 | * @since 3.1.0 |
| 1108 | * |
| 1109 | * @param array $args { |
| 1110 | * Short description about this hash. |
| 1111 | * |
| 1112 | * @type type $var Description. |
| 1113 | * @type type $var Description. |
| 1114 | * @param string $type Type of meta |
| 1115 | * @param string $primary_table |
| 1116 | * @param string $primary_id_column |
| 1117 | * @param object $context (optional) The main query object |
| 1118 | * @return array( 'join' => $join_sql, 'where' => $where_sql |
| 1119 | * } |
| 1120 | */ |
862 | 1121 | return apply_filters_ref_array( 'get_meta_sql', array( compact( 'join', 'where' ), $this->queries, $type, $primary_table, $primary_id_column, $context ) ); |
863 | 1122 | } |
864 | 1123 | } |
… |
… |
function _get_meta_table($type) { |
894 | 1153 | function is_protected_meta( $meta_key, $meta_type = null ) { |
895 | 1154 | $protected = ( '_' == $meta_key[0] ); |
896 | 1155 | |
| 1156 | /** |
| 1157 | * Filter whether a meta key is protected. |
| 1158 | * |
| 1159 | * @since 3.2.0 |
| 1160 | * |
| 1161 | * @param bool $protected True if the key is protected, false otherwise. |
| 1162 | * @param string $meta_key Meta key. |
| 1163 | * @param string $meta_type Type of meta. |
| 1164 | */ |
897 | 1165 | return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type ); |
898 | 1166 | } |
899 | 1167 | |
… |
… |
function is_protected_meta( $meta_key, $meta_type = null ) { |
908 | 1176 | * @return mixed Sanitized $meta_value |
909 | 1177 | */ |
910 | 1178 | function sanitize_meta( $meta_key, $meta_value, $meta_type ) { |
| 1179 | /** |
| 1180 | * Filter meta sanitation. |
| 1181 | * |
| 1182 | * @since 3.3.0 |
| 1183 | * |
| 1184 | * @param string $meta_type Type of meta. |
| 1185 | * @param string $meta_key Meta key. |
| 1186 | * @param mixed $meta_value Meta value to sanitize. |
| 1187 | */ |
911 | 1188 | return apply_filters( "sanitize_{$meta_type}_meta_{$meta_key}", $meta_value, $meta_key, $meta_type ); |
912 | 1189 | } |
913 | 1190 | |