Ticket #44467: 44467.3.diff
File 44467.3.diff, 19.3 KB (added by , 7 years ago) |
---|
-
src/wp-includes/comment.php
442 442 * @return int|bool Meta ID on success, false on failure. 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 452 448 /** … … 465 461 * @return bool True on success, false on failure. 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 475 467 /** … … 506 498 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. 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 516 504 /** … … 3512 3500 'done' => $done, 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 } -
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
613 613 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 618 635 if ( empty( $meta ) ) { … … 660 677 $column = sanitize_key( $meta_type . '_id' ); 661 678 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 662 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 } 698 663 699 // Fetch the meta and go on if it's found. 664 700 if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { 665 701 $original_key = $meta->meta_key; … … 755 791 $column = sanitize_key( $meta_type . '_id' ); 756 792 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 757 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 } 810 758 811 // Fetch the meta and go on if it's found. 759 812 if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { 760 813 $object_id = $meta->{$column}; … … 841 894 842 895 $object_ids = array_map( 'intval', $object_ids ); 843 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 } 913 844 914 $cache_key = $meta_type . '_meta'; 845 915 $ids = array(); 846 916 $cache = array(); -
src/wp-includes/ms-blogs.php
662 662 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success. 663 663 */ 664 664 function update_sitemeta_cache( $site_ids ) { 665 if ( ! is_site_meta_supported() ) {666 return false;667 }668 669 665 return update_meta_cache( 'blog', $site_ids ); 670 666 } 671 667 … … 1063 1059 * @return int|false Meta ID on success, false on failure. 1064 1060 */ 1065 1061 function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) { 1066 // Bail if site meta table is not installed. 1067 if ( ! is_site_meta_supported() ) { 1068 /* translators: %s: database table name */ 1069 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 1070 return false; 1071 } 1072 1073 $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); 1074 1075 // Bust site query cache. 1076 if ( $added ) { 1077 wp_cache_set( 'last_changed', microtime(), 'sites' ); 1078 } 1079 1080 return $added; 1062 return add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); 1081 1063 } 1082 1064 1083 1065 /** … … 1096 1078 * @return bool True on success, false on failure. 1097 1079 */ 1098 1080 function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) { 1099 // Bail if site meta table is not installed. 1100 if ( ! is_site_meta_supported() ) { 1101 /* translators: %s: database table name */ 1102 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 1103 return false; 1104 } 1105 1106 $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value ); 1107 1108 // Bust site query cache. 1109 if ( $deleted ) { 1110 wp_cache_set( 'last_changed', microtime(), 'sites' ); 1111 } 1112 1113 return $deleted; 1081 return delete_metadata( 'blog', $site_id, $meta_key, $meta_value ); 1114 1082 } 1115 1083 1116 1084 /** … … 1126 1094 * field if $single is true. 1127 1095 */ 1128 1096 function get_site_meta( $site_id, $key = '', $single = false ) { 1129 // Bail if site meta table is not installed.1130 if ( ! is_site_meta_supported() ) {1131 /* translators: %s: database table name */1132 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );1133 return false;1134 }1135 1136 1097 return get_metadata( 'blog', $site_id, $key, $single ); 1137 1098 } 1138 1099 … … 1155 1116 * false on failure. 1156 1117 */ 1157 1118 function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) { 1158 // Bail if site meta table is not installed. 1159 if ( ! is_site_meta_supported() ) { 1160 /* translators: %s: database table name */ 1161 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 1162 return false; 1163 } 1164 1165 $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); 1166 1167 // Bust site query cache. 1168 if ( $updated ) { 1169 wp_cache_set( 'last_changed', microtime(), 'sites' ); 1170 } 1171 1172 return $updated; 1119 return update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); 1173 1120 } 1174 1121 1175 1122 /** … … 1181 1128 * @return bool Whether the site meta key was deleted from the database. 1182 1129 */ 1183 1130 function delete_site_meta_by_key( $meta_key ) { 1184 // Bail if site meta table is not installed. 1185 if ( ! is_site_meta_supported() ) { 1186 /* translators: %s: database table name */ 1187 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 1188 return false; 1189 } 1190 1191 $deleted = delete_metadata( 'blog', null, $meta_key, '', true ); 1192 1193 // Bust site query cache. 1194 if ( $deleted ) { 1195 wp_cache_set( 'last_changed', microtime(), 'sites' ); 1196 } 1197 1198 return $deleted; 1131 return delete_metadata( 'blog', null, $meta_key, '', true ); 1199 1132 } 1200 1133 1201 1134 /** … … 1891 1824 function wp_update_blog_public_option_on_site_update( $site_id, $public ) { 1892 1825 update_blog_option( $site_id, 'blog_public', $public ); 1893 1826 } 1827 1828 /** 1829 * Sets the last changed time for the 'sites' cache group. 1830 * 1831 * @since 5.0.0 1832 */ 1833 function wp_cache_set_sites_last_changed() { 1834 wp_cache_set( 'last_changed', microtime(), 'sites' ); 1835 } 1836 1837 /** 1838 * Aborts calls to site meta if it is not supported. 1839 * 1840 * @since 5.0.0 1841 * 1842 * @param mixed $check Skip-value for whether to proceed site meta function execution. 1843 * @return mixed Original value of $check, or false if site meta is not supported. 1844 */ 1845 function wp_check_site_meta_support_prefilter( $check ) { 1846 if ( ! is_site_meta_supported() ) { 1847 /* translators: %s: database table name */ 1848 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 1849 return false; 1850 } 1851 1852 return $check; 1853 } -
src/wp-includes/ms-default-filters.php
51 51 add_action( 'wp_update_site', 'wp_maybe_clean_new_site_cache_on_update', 10, 2 ); 52 52 add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 ); 53 53 54 // Site meta 55 add_action( 'added_blog_meta', 'wp_cache_set_sites_last_changed' ); 56 add_action( 'updated_blog_meta', 'wp_cache_set_sites_last_changed' ); 57 add_action( 'deleted_blog_meta', 'wp_cache_set_sites_last_changed' ); 58 add_filter( 'get_blog_metadata', 'wp_check_site_meta_support_prefilter' ); 59 add_filter( 'add_blog_metadata', 'wp_check_site_meta_support_prefilter' ); 60 add_filter( 'update_blog_metadata', 'wp_check_site_meta_support_prefilter' ); 61 add_filter( 'delete_blog_metadata', 'wp_check_site_meta_support_prefilter' ); 62 add_filter( 'get_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' ); 63 add_filter( 'update_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' ); 64 add_filter( 'delete_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' ); 65 add_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' ); 66 54 67 // Register Nonce 55 68 add_action( 'signup_hidden_fields', 'signup_nonce_fields' ); 56 69 -
src/wp-includes/post.php
1910 1910 $post_id = $the_post; 1911 1911 } 1912 1912 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; 1913 return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); 1918 1914 } 1919 1915 1920 1916 /** … … 1938 1934 $post_id = $the_post; 1939 1935 } 1940 1936 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; 1937 return delete_metadata( 'post', $post_id, $meta_key, $meta_value ); 1946 1938 } 1947 1939 1948 1940 /** … … 1985 1977 $post_id = $the_post; 1986 1978 } 1987 1979 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; 1980 return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); 1993 1981 } 1994 1982 1995 1983 /** … … 2001 1989 * @return bool Whether the post meta key was deleted from the database. 2002 1990 */ 2003 1991 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; 1992 return delete_metadata( 'post', null, $post_meta_key, '', true ); 2009 1993 } 2010 1994 2011 1995 /** … … 6785 6769 6786 6770 return $clauses; 6787 6771 } 6772 6773 /** 6774 * Sets the last changed time for the 'posts' cache group. 6775 * 6776 * @since 5.0.0 6777 */ 6778 function wp_cache_set_posts_last_changed() { 6779 wp_cache_set( 'last_changed', microtime(), 'posts' ); 6780 } -
src/wp-includes/taxonomy.php
1211 1211 * False on failure. 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 1233 1221 /** … … 1241 1229 * @return bool True on success, false on failure. 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 1259 1235 /** … … 1268 1244 * @return mixed If `$single` is false, an array of metadata values. If `$single` is true, a single metadata value. 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 } 1278 1249 … … 1293 1264 * WP_Error when term_id is ambiguous between taxonomies. False on failure. 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 1315 1274 /** … … 1324 1283 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success. 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 } 1334 1288 … … 1343 1297 * @return array|false Array with meta data, or false when the meta table is not installed. 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 1351 1305 global $wpdb; … … 4632 4586 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 }