Ticket #44467: 44467.diff
File 44467.diff, 19.2 KB (added by , 6 years ago) |
---|
-
src/wp-includes/comment.php
441 441 * @return int|bool Meta ID on success, false on failure. 442 442 */ 443 443 function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) { 444 $added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); 445 if ( $added ) { 446 wp_cache_set( 'last_changed', microtime(), 'comment' ); 447 } 448 return $added; 444 return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); 449 445 } 450 446 451 447 /** … … 464 460 * @return bool True on success, false on failure. 465 461 */ 466 462 function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) { 467 $deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value ); 468 if ( $deleted ) { 469 wp_cache_set( 'last_changed', microtime(), 'comment' ); 470 } 471 return $deleted; 463 return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value ); 472 464 } 473 465 474 466 /** … … 505 497 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. 506 498 */ 507 499 function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) { 508 $updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value ); 509 if ( $updated ) { 510 wp_cache_set( 'last_changed', microtime(), 'comment' ); 511 } 512 return $updated; 500 return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value ); 513 501 } 514 502 515 503 /** … … 3502 3490 'done' => $done, 3503 3491 ); 3504 3492 } 3493 3494 /** 3495 * Sets the last changed time for the 'comment' cache group. 3496 * 3497 * @since 5.0.0 3498 */ 3499 function wp_cache_set_comments_last_changed() { 3500 wp_cache_set( 'last_changed', microtime(), 'comment' ); 3501 } -
src/wp-includes/default-filters.php
98 98 // Meta 99 99 add_filter( 'register_meta_args', '_wp_register_meta_args_whitelist', 10, 2 ); 100 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' ); 123 101 124 // Places to balance tags on input 102 125 foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) { 103 126 add_filter( $filter, 'convert_invalid_entities' ); -
src/wp-includes/meta.php
610 610 611 611 $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id'; 612 612 613 /** 614 * Filters whether to retrieve metadata of a specific type by meta ID. 615 * 616 * The dynamic portion of the hook, `$meta_type`, refers to the meta 617 * object type (comment, post, term, or user). Returning a non-null value 618 * will effectively short-circuit the function. 619 * 620 * @since 5.0.0 621 * 622 * @param mixed $value The value get_metadata_by_mid() should return. 623 * @param int $meta_id Meta ID. 624 * @param string $meta_key Meta key. 625 */ 626 $check = apply_filters( "get_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_key ); 627 if ( null !== $check ) { 628 return $check; 629 } 630 613 631 $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) ); 614 632 615 633 if ( empty( $meta ) ) { … … 657 675 $column = sanitize_key( $meta_type . '_id' ); 658 676 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 659 677 678 /** 679 * Filters whether to update metadata of a specific type by meta ID. 680 * 681 * The dynamic portion of the hook, `$meta_type`, refers to the meta 682 * object type (comment, post, term, or user). Returning a non-null value 683 * will effectively short-circuit the function. 684 * 685 * @since 5.0.0 686 * 687 * @param null|bool $check Whether to allow updating metadata for the given type. 688 * @param int $meta_id Meta ID. 689 * @param mixed $meta_value Meta value. Must be serializable if non-scalar. 690 * @param string $meta_key Meta key, if provided. 691 */ 692 $check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key ); 693 if ( null !== $check ) { 694 return (bool) $check; 695 } 696 660 697 // Fetch the meta and go on if it's found. 661 698 if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { 662 699 $original_key = $meta->meta_key; … … 752 789 $column = sanitize_key( $meta_type . '_id' ); 753 790 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 754 791 792 /** 793 * Filters whether to delete metadata of a specific type by meta ID. 794 * 795 * The dynamic portion of the hook, `$meta_type`, refers to the meta 796 * object type (comment, post, term, or user). Returning a non-null value 797 * will effectively short-circuit the function. 798 * 799 * @since 5.0.0 800 * 801 * @param null|bool $delete Whether to allow metadata deletion of the given type. 802 * @param int $meta_id Meta ID. 803 */ 804 $check = apply_filters( "delete_{$meta_type}_metadata_by_mid", null, $meta_id ); 805 if ( null !== $check ) { 806 return (bool) $check; 807 } 808 755 809 // Fetch the meta and go on if it's found. 756 810 if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { 757 811 $object_id = $meta->{$column}; … … 838 892 839 893 $object_ids = array_map( 'intval', $object_ids ); 840 894 895 /** 896 * Filters whether to update the metadata cache of a specific type. 897 * 898 * The dynamic portion of the hook, `$meta_type`, refers to the meta 899 * object type (comment, post, term, or user). Returning a non-null value 900 * will effectively short-circuit the function. 901 * 902 * @since 5.0.0 903 * 904 * @param mixed $check Whether to allow updating the meta cache of the given type. 905 * @param array $object_ids Array of object IDs to update the meta cache for. 906 */ 907 $check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids ); 908 if ( null !== $check ) { 909 return (bool) $check; 910 } 911 841 912 $cache_key = $meta_type . '_meta'; 842 913 $ids = array(); 843 914 $cache = array(); -
src/wp-includes/ms-blogs.php
618 618 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success. 619 619 */ 620 620 function update_sitemeta_cache( $site_ids ) { 621 if ( ! is_site_meta_supported() ) {622 return false;623 }624 625 621 return update_meta_cache( 'blog', $site_ids ); 626 622 } 627 623 … … 838 834 * @return int|false Meta ID on success, false on failure. 839 835 */ 840 836 function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) { 841 // Bail if site meta table is not installed. 842 if ( ! is_site_meta_supported() ) { 843 /* translators: %s: database table name */ 844 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 845 return false; 846 } 847 848 $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); 849 850 // Bust site query cache. 851 if ( $added ) { 852 wp_cache_set( 'last_changed', microtime(), 'sites' ); 853 } 854 855 return $added; 837 return add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); 856 838 } 857 839 858 840 /** … … 871 853 * @return bool True on success, false on failure. 872 854 */ 873 855 function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) { 874 // Bail if site meta table is not installed. 875 if ( ! is_site_meta_supported() ) { 876 /* translators: %s: database table name */ 877 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 878 return false; 879 } 880 881 $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value ); 882 883 // Bust site query cache. 884 if ( $deleted ) { 885 wp_cache_set( 'last_changed', microtime(), 'sites' ); 886 } 887 888 return $deleted; 856 return delete_metadata( 'blog', $site_id, $meta_key, $meta_value ); 889 857 } 890 858 891 859 /** … … 901 869 * field if $single is true. 902 870 */ 903 871 function get_site_meta( $site_id, $key = '', $single = false ) { 904 // Bail if site meta table is not installed.905 if ( ! is_site_meta_supported() ) {906 /* translators: %s: database table name */907 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );908 return false;909 }910 911 872 return get_metadata( 'blog', $site_id, $key, $single ); 912 873 } 913 874 … … 930 891 * false on failure. 931 892 */ 932 893 function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) { 933 // Bail if site meta table is not installed. 934 if ( ! is_site_meta_supported() ) { 935 /* translators: %s: database table name */ 936 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 937 return false; 938 } 939 940 $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); 941 942 // Bust site query cache. 943 if ( $updated ) { 944 wp_cache_set( 'last_changed', microtime(), 'sites' ); 945 } 946 947 return $updated; 894 return update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); 948 895 } 949 896 950 897 /** … … 956 903 * @return bool Whether the site meta key was deleted from the database. 957 904 */ 958 905 function delete_site_meta_by_key( $meta_key ) { 959 // Bail if site meta table is not installed. 960 if ( ! is_site_meta_supported() ) { 961 /* translators: %s: database table name */ 962 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 963 return false; 964 } 965 966 $deleted = delete_metadata( 'blog', null, $meta_key, '', true ); 967 968 // Bust site query cache. 969 if ( $deleted ) { 970 wp_cache_set( 'last_changed', microtime(), 'sites' ); 971 } 972 973 return $deleted; 906 return delete_metadata( 'blog', null, $meta_key, '', true ); 974 907 } 975 908 976 909 /** … … 1537 1470 1538 1471 update_posts_count(); 1539 1472 } 1473 1474 /** 1475 * Sets the last changed time for the 'sites' cache group. 1476 * 1477 * @since 5.0.0 1478 */ 1479 function wp_cache_set_sites_last_changed() { 1480 wp_cache_set( 'last_changed', microtime(), 'sites' ); 1481 } 1482 1483 /** 1484 * Aborts calls to site meta if it is not supported. 1485 * 1486 * @since 5.0.0 1487 * 1488 * @param mixed $check Skip-value for whether to proceed site meta function execution. 1489 * @return mixed Original value of $check, or false if site meta is not supported. 1490 */ 1491 function wp_check_site_meta_support_prefilter( $check ) { 1492 if ( ! is_site_meta_supported() ) { 1493 /* translators: %s: database table name */ 1494 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 1495 return false; 1496 } 1497 1498 return $check; 1499 } -
src/wp-includes/ms-default-filters.php
42 42 add_action( 'wpmu_activate_blog', 'wpmu_welcome_notification', 10, 5 ); 43 43 add_action( 'after_signup_site', 'wpmu_signup_blog_notification', 10, 7 ); 44 44 45 // Site meta 46 add_action( 'added_blog_meta', 'wp_cache_set_sites_last_changed' ); 47 add_action( 'updated_blog_meta', 'wp_cache_set_sites_last_changed' ); 48 add_action( 'deleted_blog_meta', 'wp_cache_set_sites_last_changed' ); 49 add_filter( 'get_blog_metadata', 'wp_check_site_meta_support_prefilter' ); 50 add_filter( 'add_blog_metadata', 'wp_check_site_meta_support_prefilter' ); 51 add_filter( 'update_blog_metadata', 'wp_check_site_meta_support_prefilter' ); 52 add_filter( 'delete_blog_metadata', 'wp_check_site_meta_support_prefilter' ); 53 add_filter( 'get_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' ); 54 add_filter( 'update_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' ); 55 add_filter( 'delete_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' ); 56 add_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' ); 57 45 58 // Register Nonce 46 59 add_action( 'signup_hidden_fields', 'signup_nonce_fields' ); 47 60 -
src/wp-includes/post.php
1889 1889 $post_id = $the_post; 1890 1890 } 1891 1891 1892 $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); 1893 if ( $added ) { 1894 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1895 } 1896 return $added; 1892 return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); 1897 1893 } 1898 1894 1899 1895 /** … … 1917 1913 $post_id = $the_post; 1918 1914 } 1919 1915 1920 $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value ); 1921 if ( $deleted ) { 1922 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1923 } 1924 return $deleted; 1916 return delete_metadata( 'post', $post_id, $meta_key, $meta_value ); 1925 1917 } 1926 1918 1927 1919 /** … … 1966 1958 $post_id = $the_post; 1967 1959 } 1968 1960 1969 $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); 1970 if ( $updated ) { 1971 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1972 } 1973 return $updated; 1961 return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); 1974 1962 } 1975 1963 1976 1964 /** … … 1982 1970 * @return bool Whether the post meta key was deleted from the database. 1983 1971 */ 1984 1972 function delete_post_meta_by_key( $post_meta_key ) { 1985 $deleted = delete_metadata( 'post', null, $post_meta_key, '', true ); 1986 if ( $deleted ) { 1987 wp_cache_set( 'last_changed', microtime(), 'posts' ); 1988 } 1989 return $deleted; 1973 return delete_metadata( 'post', null, $post_meta_key, '', true ); 1990 1974 } 1991 1975 1992 1976 /** … … 6746 6730 6747 6731 return $clauses; 6748 6732 } 6733 6734 /** 6735 * Sets the last changed time for the 'posts' cache group. 6736 * 6737 * @since 5.0.0 6738 */ 6739 function wp_cache_set_posts_last_changed() { 6740 wp_cache_set( 'last_changed', microtime(), 'posts' ); 6741 } -
src/wp-includes/taxonomy.php
1180 1180 * False on failure. 1181 1181 */ 1182 1182 function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) { 1183 // Bail if term meta table is not installed.1184 if ( get_option( 'db_version' ) < 34370 ) {1185 return false;1186 }1187 1188 1183 if ( wp_term_is_shared( $term_id ) ) { 1189 1184 return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id ); 1190 1185 } 1191 1186 1192 $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); 1193 1194 // Bust term query cache. 1195 if ( $added ) { 1196 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1197 } 1198 1199 return $added; 1187 return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); 1200 1188 } 1201 1189 1202 1190 /** … … 1210 1198 * @return bool True on success, false on failure. 1211 1199 */ 1212 1200 function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) { 1213 // Bail if term meta table is not installed. 1214 if ( get_option( 'db_version' ) < 34370 ) { 1215 return false; 1216 } 1217 1218 $deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value ); 1219 1220 // Bust term query cache. 1221 if ( $deleted ) { 1222 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1223 } 1224 1225 return $deleted; 1201 return delete_metadata( 'term', $term_id, $meta_key, $meta_value ); 1226 1202 } 1227 1203 1228 1204 /** … … 1237 1213 * @return mixed If `$single` is false, an array of metadata values. If `$single` is true, a single metadata value. 1238 1214 */ 1239 1215 function get_term_meta( $term_id, $key = '', $single = false ) { 1240 // Bail if term meta table is not installed.1241 if ( get_option( 'db_version' ) < 34370 ) {1242 return false;1243 }1244 1245 1216 return get_metadata( 'term', $term_id, $key, $single ); 1246 1217 } 1247 1218 … … 1262 1233 * WP_Error when term_id is ambiguous between taxonomies. False on failure. 1263 1234 */ 1264 1235 function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) { 1265 // Bail if term meta table is not installed.1266 if ( get_option( 'db_version' ) < 34370 ) {1267 return false;1268 }1269 1270 1236 if ( wp_term_is_shared( $term_id ) ) { 1271 1237 return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id ); 1272 1238 } 1273 1239 1274 $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); 1275 1276 // Bust term query cache. 1277 if ( $updated ) { 1278 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1279 } 1280 1281 return $updated; 1240 return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); 1282 1241 } 1283 1242 1284 1243 /** … … 1293 1252 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success. 1294 1253 */ 1295 1254 function update_termmeta_cache( $term_ids ) { 1296 // Bail if term meta table is not installed.1297 if ( get_option( 'db_version' ) < 34370 ) {1298 return;1299 }1300 1301 1255 return update_meta_cache( 'term', $term_ids ); 1302 1256 } 1303 1257 … … 1312 1266 * @return array|false Array with meta data, or false when the meta table is not installed. 1313 1267 */ 1314 1268 function has_term_meta( $term_id ) { 1315 // Bail if term meta table is not installed.1316 if ( get_option( 'db_version' ) < 34370) {1317 return false;1269 $check = wp_check_term_meta_support_prefilter( null ); 1270 if ( null !== $check ) { 1271 return $check; 1318 1272 } 1319 1273 1320 1274 global $wpdb; … … 4567 4521 4568 4522 return $taxonomy->publicly_queryable; 4569 4523 } 4524 4525 /** 4526 * Sets the last changed time for the 'terms' cache group. 4527 * 4528 * @since 5.0.0 4529 */ 4530 function wp_cache_set_terms_last_changed() { 4531 wp_cache_set( 'last_changed', microtime(), 'terms' ); 4532 } 4533 4534 /** 4535 * Aborts calls to term meta if it is not supported. 4536 * 4537 * @since 5.0.0 4538 * 4539 * @param mixed $check Skip-value for whether to proceed term meta function execution. 4540 * @return mixed Original value of $check, or false if term meta is not supported. 4541 */ 4542 function wp_check_term_meta_support_prefilter( $check ) { 4543 if ( get_option( 'db_version' ) < 34370 ) { 4544 return false; 4545 } 4546 4547 return $check; 4548 }