Changeset 43729 for branches/5.0
- Timestamp:
- 10/15/2018 11:45:16 AM (6 years ago)
- Location:
- branches/5.0
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/comment.php
r43468 r43729 423 423 * @return int|bool Meta ID on success, false on failure. 424 424 */ 425 function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) { 426 $added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); 427 if ( $added ) { 428 wp_cache_set( 'last_changed', microtime(), 'comment' ); 429 } 430 return $added; 425 function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) { 426 return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); 431 427 } 432 428 … … 446 442 * @return bool True on success, false on failure. 447 443 */ 448 function delete_comment_meta($comment_id, $meta_key, $meta_value = '') { 449 $deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value ); 450 if ( $deleted ) { 451 wp_cache_set( 'last_changed', microtime(), 'comment' ); 452 } 453 return $deleted; 444 function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) { 445 return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value ); 454 446 } 455 447 … … 466 458 * is true. 467 459 */ 468 function get_comment_meta( $comment_id, $key = '', $single = false) {469 return get_metadata( 'comment', $comment_id, $key, $single);460 function get_comment_meta( $comment_id, $key = '', $single = false ) { 461 return get_metadata( 'comment', $comment_id, $key, $single ); 470 462 } 471 463 … … 487 479 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. 488 480 */ 489 function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '') { 490 $updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value ); 491 if ( $updated ) { 492 wp_cache_set( 'last_changed', microtime(), 'comment' ); 493 } 494 return $updated; 481 function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) { 482 return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value ); 495 483 } 496 484 … … 3062 3050 */ 3063 3051 do_action( 'comment_on_draft', $comment_post_ID ); 3064 3052 3065 3053 if ( current_user_can( 'read_post', $comment_post_ID ) ) { 3066 3054 return new WP_Error( 'comment_on_draft', __( 'Sorry, comments are not allowed for this item.' ), 403 ); … … 3388 3376 ); 3389 3377 } 3378 3379 /** 3380 * Sets the last changed time for the 'comment' cache group. 3381 * 3382 * @since 5.0.0 3383 */ 3384 function wp_cache_set_comments_last_changed() { 3385 wp_cache_set( 'last_changed', microtime(), 'comment' ); 3386 } -
branches/5.0/src/wp-includes/default-filters.php
r43502 r43729 89 89 // Meta 90 90 add_filter( 'register_meta_args', '_wp_register_meta_args_whitelist', 10, 2 ); 91 92 // Post meta 93 add_action( 'added_post_meta', 'wp_cache_set_posts_last_changed' ); 94 add_action( 'updated_post_meta', 'wp_cache_set_posts_last_changed' ); 95 add_action( 'deleted_post_meta', 'wp_cache_set_posts_last_changed' ); 96 97 // Term meta 98 add_action( 'added_term_meta', 'wp_cache_set_terms_last_changed' ); 99 add_action( 'updated_term_meta', 'wp_cache_set_terms_last_changed' ); 100 add_action( 'deleted_term_meta', 'wp_cache_set_terms_last_changed' ); 101 add_filter( 'get_term_metadata', 'wp_check_term_meta_support_prefilter' ); 102 add_filter( 'add_term_metadata', 'wp_check_term_meta_support_prefilter' ); 103 add_filter( 'update_term_metadata', 'wp_check_term_meta_support_prefilter' ); 104 add_filter( 'delete_term_metadata', 'wp_check_term_meta_support_prefilter' ); 105 add_filter( 'get_term_metadata_by_mid', 'wp_check_term_meta_support_prefilter' ); 106 add_filter( 'update_term_metadata_by_mid', 'wp_check_term_meta_support_prefilter' ); 107 add_filter( 'delete_term_metadata_by_mid', 'wp_check_term_meta_support_prefilter' ); 108 add_filter( 'update_term_metadata_cache', 'wp_check_term_meta_support_prefilter' ); 109 110 // Comment meta 111 add_action( 'added_comment_meta', 'wp_cache_set_comments_last_changed' ); 112 add_action( 'updated_comment_meta', 'wp_cache_set_comments_last_changed' ); 113 add_action( 'deleted_comment_meta', 'wp_cache_set_comments_last_changed' ); 91 114 92 115 // Places to balance tags on input -
branches/5.0/src/wp-includes/meta.php
r43706 r43729 587 587 $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id'; 588 588 589 /** 590 * Filters whether to retrieve metadata of a specific type by meta ID. 591 * 592 * The dynamic portion of the hook, `$meta_type`, refers to the meta 593 * object type (comment, post, term, or user). Returning a non-null value 594 * will effectively short-circuit the function. 595 * 596 * @since 5.0.0 597 * 598 * @param mixed $value The value get_metadata_by_mid() should return. 599 * @param int $meta_id Meta ID. 600 */ 601 $check = apply_filters( "get_{$meta_type}_metadata_by_mid", null, $meta_id ); 602 if ( null !== $check ) { 603 return $check; 604 } 605 589 606 $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) ); 590 607 … … 631 648 $column = sanitize_key($meta_type . '_id'); 632 649 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 650 651 /** 652 * Filters whether to update metadata of a specific type by meta ID. 653 * 654 * The dynamic portion of the hook, `$meta_type`, refers to the meta 655 * object type (comment, post, term, or user). Returning a non-null value 656 * will effectively short-circuit the function. 657 * 658 * @since 5.0.0 659 * 660 * @param null|bool $check Whether to allow updating metadata for the given type. 661 * @param int $meta_id Meta ID. 662 * @param mixed $meta_value Meta value. Must be serializable if non-scalar. 663 * @param string|bool $meta_key Meta key, if provided. 664 */ 665 $check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key ); 666 if ( null !== $check ) { 667 return (bool) $check; 668 } 633 669 634 670 // Fetch the meta and go on if it's found. … … 725 761 $column = sanitize_key($meta_type . '_id'); 726 762 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 763 764 /** 765 * Filters whether to delete metadata of a specific type by meta ID. 766 * 767 * The dynamic portion of the hook, `$meta_type`, refers to the meta 768 * object type (comment, post, term, or user). Returning a non-null value 769 * will effectively short-circuit the function. 770 * 771 * @since 5.0.0 772 * 773 * @param null|bool $delete Whether to allow metadata deletion of the given type. 774 * @param int $meta_id Meta ID. 775 */ 776 $check = apply_filters( "delete_{$meta_type}_metadata_by_mid", null, $meta_id ); 777 if ( null !== $check ) { 778 return (bool) $check; 779 } 727 780 728 781 // Fetch the meta and go on if it's found. … … 811 864 812 865 $object_ids = array_map('intval', $object_ids); 866 867 /** 868 * Filters whether to update the metadata cache of a specific type. 869 * 870 * The dynamic portion of the hook, `$meta_type`, refers to the meta 871 * object type (comment, post, term, or user). Returning a non-null value 872 * will effectively short-circuit the function. 873 * 874 * @since 5.0.0 875 * 876 * @param mixed $check Whether to allow updating the meta cache of the given type. 877 * @param array $object_ids Array of object IDs to update the meta cache for. 878 */ 879 $check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids ); 880 if ( null !== $check ) { 881 return (bool) $check; 882 } 813 883 814 884 $cache_key = $meta_type . '_meta'; -
branches/5.0/src/wp-includes/post.php
r43710 r43729 1785 1785 function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { 1786 1786 // Make sure meta is added to the post, not a revision. 1787 if ( $the_post = wp_is_post_revision($post_id) ) 1787 $the_post = wp_is_post_revision( $post_id ); 1788 if ( $the_post ) { 1788 1789 $post_id = $the_post; 1789 1790 $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); 1791 if ( $added ) { 1792 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1793 } 1794 return $added; 1790 } 1791 1792 return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); 1795 1793 } 1796 1794 … … 1812 1810 function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { 1813 1811 // Make sure meta is added to the post, not a revision. 1814 if ( $the_post = wp_is_post_revision($post_id) ) 1812 $the_post = wp_is_post_revision( $post_id ); 1813 if ( $the_post ) { 1815 1814 $post_id = $the_post; 1816 1817 $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value ); 1818 if ( $deleted ) { 1819 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1820 } 1821 return $deleted; 1815 } 1816 1817 return delete_metadata( 'post', $post_id, $meta_key, $meta_value ); 1822 1818 } 1823 1819 … … 1858 1854 function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) { 1859 1855 // Make sure meta is added to the post, not a revision. 1860 if ( $the_post = wp_is_post_revision($post_id) ) 1856 $the_post = wp_is_post_revision( $post_id ); 1857 if ( $the_post ) { 1861 1858 $post_id = $the_post; 1862 1863 $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); 1864 if ( $updated ) { 1865 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1866 } 1867 return $updated; 1859 } 1860 1861 return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); 1868 1862 } 1869 1863 … … 1877 1871 */ 1878 1872 function delete_post_meta_by_key( $post_meta_key ) { 1879 $deleted = delete_metadata( 'post', null, $post_meta_key, '', true ); 1880 if ( $deleted ) { 1881 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1882 } 1883 return $deleted; 1873 return delete_metadata( 'post', null, $post_meta_key, '', true ); 1884 1874 } 1885 1875 … … 6476 6466 return $clauses; 6477 6467 } 6468 6469 /** 6470 * Sets the last changed time for the 'posts' cache group. 6471 * 6472 * @since 5.0.0 6473 */ 6474 function wp_cache_set_posts_last_changed() { 6475 wp_cache_set( 'last_changed', microtime(), 'posts' ); 6476 } -
branches/5.0/src/wp-includes/taxonomy.php
r43510 r43729 1136 1136 */ 1137 1137 function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) { 1138 // Bail if term meta table is not installed.1139 if ( get_option( 'db_version' ) < 34370 ) {1140 return false;1141 }1142 1143 1138 if ( wp_term_is_shared( $term_id ) ) { 1144 1139 return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id ); 1145 1140 } 1146 1141 1147 $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); 1148 1149 // Bust term query cache. 1150 if ( $added ) { 1151 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1152 } 1153 1154 return $added; 1142 return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); 1155 1143 } 1156 1144 … … 1166 1154 */ 1167 1155 function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) { 1168 // Bail if term meta table is not installed. 1169 if ( get_option( 'db_version' ) < 34370 ) { 1170 return false; 1171 } 1172 1173 $deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value ); 1174 1175 // Bust term query cache. 1176 if ( $deleted ) { 1177 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1178 } 1179 1180 return $deleted; 1156 return delete_metadata( 'term', $term_id, $meta_key, $meta_value ); 1181 1157 } 1182 1158 … … 1193 1169 */ 1194 1170 function get_term_meta( $term_id, $key = '', $single = false ) { 1195 // Bail if term meta table is not installed.1196 if ( get_option( 'db_version' ) < 34370 ) {1197 return false;1198 }1199 1200 1171 return get_metadata( 'term', $term_id, $key, $single ); 1201 1172 } … … 1218 1189 */ 1219 1190 function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) { 1220 // Bail if term meta table is not installed.1221 if ( get_option( 'db_version' ) < 34370 ) {1222 return false;1223 }1224 1225 1191 if ( wp_term_is_shared( $term_id ) ) { 1226 1192 return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id ); 1227 1193 } 1228 1194 1229 $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); 1230 1231 // Bust term query cache. 1232 if ( $updated ) { 1233 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1234 } 1235 1236 return $updated; 1195 return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); 1237 1196 } 1238 1197 … … 1249 1208 */ 1250 1209 function update_termmeta_cache( $term_ids ) { 1251 // Bail if term meta table is not installed.1252 if ( get_option( 'db_version' ) < 34370 ) {1253 return;1254 }1255 1256 1210 return update_meta_cache( 'term', $term_ids ); 1257 1211 } … … 1268 1222 */ 1269 1223 function has_term_meta( $term_id ) { 1270 // Bail if term meta table is not installed.1271 if ( get_option( 'db_version' ) < 34370) {1272 return false;1224 $check = wp_check_term_meta_support_prefilter( null ); 1225 if ( null !== $check ) { 1226 return $check; 1273 1227 } 1274 1228 … … 4342 4296 return $parent; 4343 4297 } 4298 4299 /** 4300 * Sets the last changed time for the 'terms' cache group. 4301 * 4302 * @since 5.0.0 4303 */ 4304 function wp_cache_set_terms_last_changed() { 4305 wp_cache_set( 'last_changed', microtime(), 'terms' ); 4306 } 4307 4308 /** 4309 * Aborts calls to term meta if it is not supported. 4310 * 4311 * @since 5.0.0 4312 * 4313 * @param mixed $check Skip-value for whether to proceed term meta function execution. 4314 * @return mixed Original value of $check, or false if term meta is not supported. 4315 */ 4316 function wp_check_term_meta_support_prefilter( $check ) { 4317 if ( get_option( 'db_version' ) < 34370 ) { 4318 return false; 4319 } 4320 4321 return $check; 4322 } -
branches/5.0/tests/phpunit/tests/comment/metaCache.php
r37954 r43729 211 211 $this->assertSame( $num_queries, $wpdb->num_queries ); 212 212 } 213 214 /** 215 * @ticket 44467 216 */ 217 public function test_add_metadata_sets_comments_last_changed() { 218 $comment_id = self::factory()->comment->create(); 219 220 wp_cache_delete( 'last_changed', 'comment' ); 221 222 $this->assertInternalType( 'integer', add_metadata( 'comment', $comment_id, 'foo', 'bar' ) ); 223 $this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) ); 224 } 225 226 /** 227 * @ticket 44467 228 */ 229 public function test_update_metadata_sets_comments_last_changed() { 230 $comment_id = self::factory()->comment->create(); 231 232 wp_cache_delete( 'last_changed', 'comment' ); 233 234 $this->assertInternalType( 'integer', update_metadata( 'comment', $comment_id, 'foo', 'bar' ) ); 235 $this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) ); 236 } 237 238 /** 239 * @ticket 44467 240 */ 241 public function test_delete_metadata_sets_comments_last_changed() { 242 $comment_id = self::factory()->comment->create(); 243 244 update_metadata( 'comment', $comment_id, 'foo', 'bar' ); 245 wp_cache_delete( 'last_changed', 'comment' ); 246 247 $this->assertTrue( delete_metadata( 'comment', $comment_id, 'foo' ) ); 248 $this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) ); 249 } 213 250 } -
branches/5.0/tests/phpunit/tests/post/meta.php
r43510 r43729 306 306 ); 307 307 } 308 309 /** 310 * @ticket 44467 311 */ 312 public function test_add_metadata_sets_posts_last_changed() { 313 $post_id = self::factory()->post->create(); 314 315 wp_cache_delete( 'last_changed', 'posts' ); 316 317 $this->assertInternalType( 'integer', add_metadata( 'post', $post_id, 'foo', 'bar' ) ); 318 $this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) ); 319 } 320 321 /** 322 * @ticket 44467 323 */ 324 public function test_update_metadata_sets_posts_last_changed() { 325 $post_id = self::factory()->post->create(); 326 327 wp_cache_delete( 'last_changed', 'posts' ); 328 329 $this->assertInternalType( 'integer', update_metadata( 'post', $post_id, 'foo', 'bar' ) ); 330 $this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) ); 331 } 332 333 /** 334 * @ticket 44467 335 */ 336 public function test_delete_metadata_sets_posts_last_changed() { 337 $post_id = self::factory()->post->create(); 338 339 update_metadata( 'post', $post_id, 'foo', 'bar' ); 340 wp_cache_delete( 'last_changed', 'posts' ); 341 342 $this->assertTrue( delete_metadata( 'post', $post_id, 'foo' ) ); 343 $this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) ); 344 } 308 345 } -
branches/5.0/tests/phpunit/tests/term/meta.php
r43510 r43729 510 510 ); 511 511 } 512 513 /** 514 * @ticket 44467 515 */ 516 public function test_add_metadata_sets_terms_last_changed() { 517 $term_id = self::factory()->term->create(); 518 519 wp_cache_delete( 'last_changed', 'terms' ); 520 521 $this->assertInternalType( 'integer', add_metadata( 'term', $term_id, 'foo', 'bar' ) ); 522 $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) ); 523 } 524 525 /** 526 * @ticket 44467 527 */ 528 public function test_update_metadata_sets_terms_last_changed() { 529 $term_id = self::factory()->term->create(); 530 531 wp_cache_delete( 'last_changed', 'terms' ); 532 533 $this->assertInternalType( 'integer', update_metadata( 'term', $term_id, 'foo', 'bar' ) ); 534 $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) ); 535 } 536 537 /** 538 * @ticket 44467 539 */ 540 public function test_delete_metadata_sets_terms_last_changed() { 541 $term_id = self::factory()->term->create(); 542 543 update_metadata( 'term', $term_id, 'foo', 'bar' ); 544 wp_cache_delete( 'last_changed', 'terms' ); 545 546 $this->assertTrue( delete_metadata( 'term', $term_id, 'foo' ) ); 547 $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) ); 548 } 549 550 /** 551 * @ticket 44467 552 */ 553 public function test_metadata_functions_respect_term_meta_support() { 554 $term_id = self::factory()->term->create(); 555 556 $meta_id = add_metadata( 'term', $term_id, 'foo', 'bar' ); 557 558 // Set database version to last version before term meta support. 559 update_option( 'db_version', 34369 ); 560 561 $this->assertFalse( get_metadata( 'term', $term_id, 'foo', true ) ); 562 $this->assertFalse( add_metadata( 'term', $term_id, 'foo', 'bar' ) ); 563 $this->assertFalse( update_metadata( 'term', $term_id, 'foo', 'bar' ) ); 564 $this->assertFalse( delete_metadata( 'term', $term_id, 'foo' ) ); 565 $this->assertFalse( get_metadata_by_mid( 'term', $meta_id ) ); 566 $this->assertFalse( update_metadata_by_mid( 'term', $meta_id, 'baz' ) ); 567 $this->assertFalse( delete_metadata_by_mid( 'term', $meta_id ) ); 568 $this->assertFalse( update_meta_cache( 'term', array( $term_id ) ) ); 569 } 512 570 }
Note: See TracChangeset
for help on using the changeset viewer.