- Timestamp:
- 12/12/2018 03:02:00 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43729
- Property svn:mergeinfo changed
-
trunk/src/wp-includes/comment.php
r43571 r43982 443 443 */ 444 444 function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) { 445 $added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); 446 if ( $added ) { 447 wp_cache_set( 'last_changed', microtime(), 'comment' ); 448 } 449 return $added; 445 return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); 450 446 } 451 447 … … 466 462 */ 467 463 function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) { 468 $deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value ); 469 if ( $deleted ) { 470 wp_cache_set( 'last_changed', microtime(), 'comment' ); 471 } 472 return $deleted; 464 return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value ); 473 465 } 474 466 … … 507 499 */ 508 500 function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) { 509 $updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value ); 510 if ( $updated ) { 511 wp_cache_set( 'last_changed', microtime(), 'comment' ); 512 } 513 return $updated; 501 return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value ); 514 502 } 515 503 … … 3513 3501 ); 3514 3502 } 3503 3504 /** 3505 * Sets the last changed time for the 'comment' cache group. 3506 * 3507 * @since 5.0.0 3508 */ 3509 function wp_cache_set_comments_last_changed() { 3510 wp_cache_set( 'last_changed', microtime(), 'comment' ); 3511 } -
trunk/src/wp-includes/default-filters.php
r43571 r43982 98 98 // Meta 99 99 add_filter( 'register_meta_args', '_wp_register_meta_args_whitelist', 10, 2 ); 100 101 // Post meta 102 add_action( 'added_post_meta', 'wp_cache_set_posts_last_changed' ); 103 add_action( 'updated_post_meta', 'wp_cache_set_posts_last_changed' ); 104 add_action( 'deleted_post_meta', 'wp_cache_set_posts_last_changed' ); 105 106 // Term meta 107 add_action( 'added_term_meta', 'wp_cache_set_terms_last_changed' ); 108 add_action( 'updated_term_meta', 'wp_cache_set_terms_last_changed' ); 109 add_action( 'deleted_term_meta', 'wp_cache_set_terms_last_changed' ); 110 add_filter( 'get_term_metadata', 'wp_check_term_meta_support_prefilter' ); 111 add_filter( 'add_term_metadata', 'wp_check_term_meta_support_prefilter' ); 112 add_filter( 'update_term_metadata', 'wp_check_term_meta_support_prefilter' ); 113 add_filter( 'delete_term_metadata', 'wp_check_term_meta_support_prefilter' ); 114 add_filter( 'get_term_metadata_by_mid', 'wp_check_term_meta_support_prefilter' ); 115 add_filter( 'update_term_metadata_by_mid', 'wp_check_term_meta_support_prefilter' ); 116 add_filter( 'delete_term_metadata_by_mid', 'wp_check_term_meta_support_prefilter' ); 117 add_filter( 'update_term_metadata_cache', 'wp_check_term_meta_support_prefilter' ); 118 119 // Comment meta 120 add_action( 'added_comment_meta', 'wp_cache_set_comments_last_changed' ); 121 add_action( 'updated_comment_meta', 'wp_cache_set_comments_last_changed' ); 122 add_action( 'deleted_comment_meta', 'wp_cache_set_comments_last_changed' ); 100 123 101 124 // Places to balance tags on input -
trunk/src/wp-includes/meta.php
r43582 r43982 614 614 $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id'; 615 615 616 /** 617 * Filters whether to retrieve metadata of a specific type by meta ID. 618 * 619 * The dynamic portion of the hook, `$meta_type`, refers to the meta 620 * object type (comment, post, term, or user). Returning a non-null value 621 * will effectively short-circuit the function. 622 * 623 * @since 5.0.0 624 * 625 * @param mixed $value The value get_metadata_by_mid() should return. 626 * @param int $meta_id Meta ID. 627 */ 628 $check = apply_filters( "get_{$meta_type}_metadata_by_mid", null, $meta_id ); 629 if ( null !== $check ) { 630 return $check; 631 } 632 616 633 $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) ); 617 634 … … 660 677 $column = sanitize_key( $meta_type . '_id' ); 661 678 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 679 680 /** 681 * Filters whether to update metadata of a specific type by meta ID. 682 * 683 * The dynamic portion of the hook, `$meta_type`, refers to the meta 684 * object type (comment, post, term, or user). Returning a non-null value 685 * will effectively short-circuit the function. 686 * 687 * @since 5.0.0 688 * 689 * @param null|bool $check Whether to allow updating metadata for the given type. 690 * @param int $meta_id Meta ID. 691 * @param mixed $meta_value Meta value. Must be serializable if non-scalar. 692 * @param string|bool $meta_key Meta key, if provided. 693 */ 694 $check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key ); 695 if ( null !== $check ) { 696 return (bool) $check; 697 } 662 698 663 699 // Fetch the meta and go on if it's found. … … 755 791 $column = sanitize_key( $meta_type . '_id' ); 756 792 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 793 794 /** 795 * Filters whether to delete metadata of a specific type by meta ID. 796 * 797 * The dynamic portion of the hook, `$meta_type`, refers to the meta 798 * object type (comment, post, term, or user). Returning a non-null value 799 * will effectively short-circuit the function. 800 * 801 * @since 5.0.0 802 * 803 * @param null|bool $delete Whether to allow metadata deletion of the given type. 804 * @param int $meta_id Meta ID. 805 */ 806 $check = apply_filters( "delete_{$meta_type}_metadata_by_mid", null, $meta_id ); 807 if ( null !== $check ) { 808 return (bool) $check; 809 } 757 810 758 811 // Fetch the meta and go on if it's found. … … 841 894 842 895 $object_ids = array_map( 'intval', $object_ids ); 896 897 /** 898 * Filters whether to update the metadata cache of a specific type. 899 * 900 * The dynamic portion of the hook, `$meta_type`, refers to the meta 901 * object type (comment, post, term, or user). Returning a non-null value 902 * will effectively short-circuit the function. 903 * 904 * @since 5.0.0 905 * 906 * @param mixed $check Whether to allow updating the meta cache of the given type. 907 * @param array $object_ids Array of object IDs to update the meta cache for. 908 */ 909 $check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids ); 910 if ( null !== $check ) { 911 return (bool) $check; 912 } 843 913 844 914 $cache_key = $meta_type . '_meta'; -
trunk/src/wp-includes/post.php
r43638 r43982 1907 1907 function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { 1908 1908 // Make sure meta is added to the post, not a revision. 1909 if ( $the_post = wp_is_post_revision( $post_id ) ) { 1909 $the_post = wp_is_post_revision( $post_id ); 1910 if ( $the_post ) { 1910 1911 $post_id = $the_post; 1911 1912 } 1912 1913 1913 $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); 1914 if ( $added ) { 1915 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1916 } 1917 return $added; 1914 return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); 1918 1915 } 1919 1916 … … 1935 1932 function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { 1936 1933 // Make sure meta is added to the post, not a revision. 1937 if ( $the_post = wp_is_post_revision( $post_id ) ) { 1934 $the_post = wp_is_post_revision( $post_id ); 1935 if ( $the_post ) { 1938 1936 $post_id = $the_post; 1939 1937 } 1940 1938 1941 $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value ); 1942 if ( $deleted ) { 1943 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1944 } 1945 return $deleted; 1939 return delete_metadata( 'post', $post_id, $meta_key, $meta_value ); 1946 1940 } 1947 1941 … … 1982 1976 function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) { 1983 1977 // Make sure meta is added to the post, not a revision. 1984 if ( $the_post = wp_is_post_revision( $post_id ) ) { 1978 $the_post = wp_is_post_revision( $post_id ); 1979 if ( $the_post ) { 1985 1980 $post_id = $the_post; 1986 1981 } 1987 1982 1988 $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); 1989 if ( $updated ) { 1990 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1991 } 1992 return $updated; 1983 return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); 1993 1984 } 1994 1985 … … 2002 1993 */ 2003 1994 function delete_post_meta_by_key( $post_meta_key ) { 2004 $deleted = delete_metadata( 'post', null, $post_meta_key, '', true ); 2005 if ( $deleted ) { 2006 wp_cache_set( 'last_changed', microtime(), 'posts' ); 2007 } 2008 return $deleted; 1995 return delete_metadata( 'post', null, $post_meta_key, '', true ); 2009 1996 } 2010 1997 … … 6786 6773 return $clauses; 6787 6774 } 6775 6776 /** 6777 * Sets the last changed time for the 'posts' cache group. 6778 * 6779 * @since 5.0.0 6780 */ 6781 function wp_cache_set_posts_last_changed() { 6782 wp_cache_set( 'last_changed', microtime(), 'posts' ); 6783 } -
trunk/src/wp-includes/taxonomy.php
r43631 r43982 1212 1212 */ 1213 1213 function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) { 1214 // Bail if term meta table is not installed.1215 if ( get_option( 'db_version' ) < 34370 ) {1216 return false;1217 }1218 1219 1214 if ( wp_term_is_shared( $term_id ) ) { 1220 1215 return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id ); 1221 1216 } 1222 1217 1223 $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); 1224 1225 // Bust term query cache. 1226 if ( $added ) { 1227 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1228 } 1229 1230 return $added; 1218 return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); 1231 1219 } 1232 1220 … … 1242 1230 */ 1243 1231 function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) { 1244 // Bail if term meta table is not installed. 1245 if ( get_option( 'db_version' ) < 34370 ) { 1246 return false; 1247 } 1248 1249 $deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value ); 1250 1251 // Bust term query cache. 1252 if ( $deleted ) { 1253 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1254 } 1255 1256 return $deleted; 1232 return delete_metadata( 'term', $term_id, $meta_key, $meta_value ); 1257 1233 } 1258 1234 … … 1269 1245 */ 1270 1246 function get_term_meta( $term_id, $key = '', $single = false ) { 1271 // Bail if term meta table is not installed.1272 if ( get_option( 'db_version' ) < 34370 ) {1273 return false;1274 }1275 1276 1247 return get_metadata( 'term', $term_id, $key, $single ); 1277 1248 } … … 1294 1265 */ 1295 1266 function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) { 1296 // Bail if term meta table is not installed.1297 if ( get_option( 'db_version' ) < 34370 ) {1298 return false;1299 }1300 1301 1267 if ( wp_term_is_shared( $term_id ) ) { 1302 1268 return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id ); 1303 1269 } 1304 1270 1305 $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); 1306 1307 // Bust term query cache. 1308 if ( $updated ) { 1309 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1310 } 1311 1312 return $updated; 1271 return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); 1313 1272 } 1314 1273 … … 1325 1284 */ 1326 1285 function update_termmeta_cache( $term_ids ) { 1327 // Bail if term meta table is not installed.1328 if ( get_option( 'db_version' ) < 34370 ) {1329 return;1330 }1331 1332 1286 return update_meta_cache( 'term', $term_ids ); 1333 1287 } … … 1344 1298 */ 1345 1299 function has_term_meta( $term_id ) { 1346 // Bail if term meta table is not installed.1347 if ( get_option( 'db_version' ) < 34370) {1348 return false;1300 $check = wp_check_term_meta_support_prefilter( null ); 1301 if ( null !== $check ) { 1302 return $check; 1349 1303 } 1350 1304 … … 4633 4587 return $taxonomy->publicly_queryable; 4634 4588 } 4589 4590 /** 4591 * Sets the last changed time for the 'terms' cache group. 4592 * 4593 * @since 5.0.0 4594 */ 4595 function wp_cache_set_terms_last_changed() { 4596 wp_cache_set( 'last_changed', microtime(), 'terms' ); 4597 } 4598 4599 /** 4600 * Aborts calls to term meta if it is not supported. 4601 * 4602 * @since 5.0.0 4603 * 4604 * @param mixed $check Skip-value for whether to proceed term meta function execution. 4605 * @return mixed Original value of $check, or false if term meta is not supported. 4606 */ 4607 function wp_check_term_meta_support_prefilter( $check ) { 4608 if ( get_option( 'db_version' ) < 34370 ) { 4609 return false; 4610 } 4611 4612 return $check; 4613 } -
trunk/tests/phpunit/tests/comment/metaCache.php
r42343 r43982 225 225 $this->assertSame( $num_queries, $wpdb->num_queries ); 226 226 } 227 228 /** 229 * @ticket 44467 230 */ 231 public function test_add_metadata_sets_comments_last_changed() { 232 $comment_id = self::factory()->comment->create(); 233 234 wp_cache_delete( 'last_changed', 'comment' ); 235 236 $this->assertInternalType( 'integer', add_metadata( 'comment', $comment_id, 'foo', 'bar' ) ); 237 $this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) ); 238 } 239 240 /** 241 * @ticket 44467 242 */ 243 public function test_update_metadata_sets_comments_last_changed() { 244 $comment_id = self::factory()->comment->create(); 245 246 wp_cache_delete( 'last_changed', 'comment' ); 247 248 $this->assertInternalType( 'integer', update_metadata( 'comment', $comment_id, 'foo', 'bar' ) ); 249 $this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) ); 250 } 251 252 /** 253 * @ticket 44467 254 */ 255 public function test_delete_metadata_sets_comments_last_changed() { 256 $comment_id = self::factory()->comment->create(); 257 258 update_metadata( 'comment', $comment_id, 'foo', 'bar' ); 259 wp_cache_delete( 'last_changed', 'comment' ); 260 261 $this->assertTrue( delete_metadata( 'comment', $comment_id, 'foo' ) ); 262 $this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) ); 263 } 227 264 } -
trunk/tests/phpunit/tests/post/meta.php
r43571 r43982 310 310 ); 311 311 } 312 313 /** 314 * @ticket 44467 315 */ 316 public function test_add_metadata_sets_posts_last_changed() { 317 $post_id = self::factory()->post->create(); 318 319 wp_cache_delete( 'last_changed', 'posts' ); 320 321 $this->assertInternalType( 'integer', add_metadata( 'post', $post_id, 'foo', 'bar' ) ); 322 $this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) ); 323 } 324 325 /** 326 * @ticket 44467 327 */ 328 public function test_update_metadata_sets_posts_last_changed() { 329 $post_id = self::factory()->post->create(); 330 331 wp_cache_delete( 'last_changed', 'posts' ); 332 333 $this->assertInternalType( 'integer', update_metadata( 'post', $post_id, 'foo', 'bar' ) ); 334 $this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) ); 335 } 336 337 /** 338 * @ticket 44467 339 */ 340 public function test_delete_metadata_sets_posts_last_changed() { 341 $post_id = self::factory()->post->create(); 342 343 update_metadata( 'post', $post_id, 'foo', 'bar' ); 344 wp_cache_delete( 'last_changed', 'posts' ); 345 346 $this->assertTrue( delete_metadata( 'post', $post_id, 'foo' ) ); 347 $this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) ); 348 } 312 349 } -
trunk/tests/phpunit/tests/term/meta.php
r43571 r43982 538 538 ); 539 539 } 540 541 /** 542 * @ticket 44467 543 */ 544 public function test_add_metadata_sets_terms_last_changed() { 545 $term_id = self::factory()->term->create(); 546 547 wp_cache_delete( 'last_changed', 'terms' ); 548 549 $this->assertInternalType( 'integer', add_metadata( 'term', $term_id, 'foo', 'bar' ) ); 550 $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) ); 551 } 552 553 /** 554 * @ticket 44467 555 */ 556 public function test_update_metadata_sets_terms_last_changed() { 557 $term_id = self::factory()->term->create(); 558 559 wp_cache_delete( 'last_changed', 'terms' ); 560 561 $this->assertInternalType( 'integer', update_metadata( 'term', $term_id, 'foo', 'bar' ) ); 562 $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) ); 563 } 564 565 /** 566 * @ticket 44467 567 */ 568 public function test_delete_metadata_sets_terms_last_changed() { 569 $term_id = self::factory()->term->create(); 570 571 update_metadata( 'term', $term_id, 'foo', 'bar' ); 572 wp_cache_delete( 'last_changed', 'terms' ); 573 574 $this->assertTrue( delete_metadata( 'term', $term_id, 'foo' ) ); 575 $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) ); 576 } 577 578 /** 579 * @ticket 44467 580 */ 581 public function test_metadata_functions_respect_term_meta_support() { 582 $term_id = self::factory()->term->create(); 583 584 $meta_id = add_metadata( 'term', $term_id, 'foo', 'bar' ); 585 586 // Set database version to last version before term meta support. 587 update_option( 'db_version', 34369 ); 588 589 $this->assertFalse( get_metadata( 'term', $term_id, 'foo', true ) ); 590 $this->assertFalse( add_metadata( 'term', $term_id, 'foo', 'bar' ) ); 591 $this->assertFalse( update_metadata( 'term', $term_id, 'foo', 'bar' ) ); 592 $this->assertFalse( delete_metadata( 'term', $term_id, 'foo' ) ); 593 $this->assertFalse( get_metadata_by_mid( 'term', $meta_id ) ); 594 $this->assertFalse( update_metadata_by_mid( 'term', $meta_id, 'baz' ) ); 595 $this->assertFalse( delete_metadata_by_mid( 'term', $meta_id ) ); 596 $this->assertFalse( update_meta_cache( 'term', array( $term_id ) ) ); 597 } 540 598 }
Note: See TracChangeset
for help on using the changeset viewer.