Ticket #37923: 37923.4.diff
File 37923.4.diff, 17.3 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/ms.php
127 127 $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); 128 128 } 129 129 130 $blog_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->blogmeta WHERE blog_id = %d ", $blog_id ) ); 131 foreach ( $blog_meta_ids as $mid ) { 132 delete_metadata_by_mid( 'blog', $mid ); 133 } 134 130 135 $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) ); 131 136 132 137 /** -
src/wp-admin/includes/schema.php
265 265 PRIMARY KEY (blog_id), 266 266 KEY db_version (db_version) 267 267 ) $charset_collate; 268 CREATE TABLE $wpdb->blogmeta ( 269 meta_id bigint(20) NOT NULL auto_increment, 270 blog_id bigint(20) NOT NULL default '0', 271 meta_key varchar(255) default NULL, 272 meta_value longtext, 273 PRIMARY KEY (meta_id), 274 KEY meta_key (meta_key($max_index_length)), 275 KEY blog_id (blog_id) 276 ) $charset_collate; 268 277 CREATE TABLE $wpdb->registration_log ( 269 278 ID bigint(20) NOT NULL auto_increment, 270 279 email varchar(255) NOT NULL default '', -
src/wp-admin/includes/upgrade.php
1881 1881 } 1882 1882 } 1883 1883 } 1884 1885 // 4.9 1886 if ( $wp_current_db_version < 40001 ) { 1887 update_site_option( 'site_meta_supported', '1'); 1888 } 1884 1889 } 1885 1890 1886 1891 // -
src/wp-includes/class-wp-site-query.php
137 137 * @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. 138 138 * Default empty array. 139 139 * @type bool $update_site_cache Whether to prime the cache for found sites. Default false. 140 * @type bool $update_site_meta_cache Whether to prime the metadata cache for found sites. 141 * Default true. 140 142 * } 141 143 */ 142 144 public function __construct( $query = '' ) { … … 172 174 'count' => false, 173 175 'date_query' => null, // See WP_Date_Query 174 176 'update_site_cache' => true, 177 'update_site_meta_cache' => true, 175 178 ); 176 179 177 180 if ( ! empty( $query ) ) { … … 286 289 287 290 // Prime site network caches. 288 291 if ( $this->query_vars['update_site_cache'] ) { 289 _prime_site_caches( $site_ids );292 _prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache'] ); 290 293 } 291 294 292 295 // Fetch full site objects from the primed cache. … … 302 305 * 303 306 * @since 4.6.0 304 307 * 305 * @param array $ _sites An array of WP_Site objects.306 * @param WP_Site_Query &$this Current instance of WP_Site_Query, passed by reference.308 * @param array $results An array of sites. 309 * @param WP_Site_Query &$this Current instance of WP_Site_Query, passed by reference. 307 310 */ 308 311 $_sites = apply_filters_ref_array( 'the_sites', array( $_sites, &$this ) ); 309 312 -
src/wp-includes/formatting.php
1888 1888 } 1889 1889 1890 1890 /** 1891 * Sanitizes a string key.1892 *1893 * Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes and underscores are allowed.1894 *1895 * @since 3.0.01896 *1897 * @param string $key String key1898 * @return string Sanitized key1899 */1900 function sanitize_key( $key ) {1901 $raw_key = $key;1902 $key = strtolower( $key );1903 $key = preg_replace( '/[^a-z0-9_\-]/', '', $key );1904 1905 /**1906 * Filters a sanitized key string.1907 *1908 * @since 3.0.01909 *1910 * @param string $key Sanitized key.1911 * @param string $raw_key The key prior to sanitization.1912 */1913 return apply_filters( 'sanitize_key', $key, $raw_key );1914 }1915 1916 /**1917 1891 * Sanitizes a title, or returns a fallback title. 1918 1892 * 1919 1893 * Specifically, HTML and PHP tags are stripped. Further actions can be added -
src/wp-includes/load.php
517 517 } 518 518 519 519 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 520 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );520 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) ); 521 521 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 522 522 } 523 523 } … … 1112 1112 */ 1113 1113 return apply_filters( 'file_mod_allowed', ! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS, $context ); 1114 1114 } 1115 1116 /** 1117 * Sanitizes a string key. 1118 * 1119 * Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes and underscores are allowed. 1120 * 1121 * @since 3.0.0 1122 * 1123 * @param string $key String key 1124 * @return string Sanitized key 1125 */ 1126 function sanitize_key( $key ) { 1127 $raw_key = $key; 1128 $key = strtolower( $key ); 1129 $key = preg_replace( '/[^a-z0-9_\-]/', '', $key ); 1130 1131 /** 1132 * Filters a sanitized key string. 1133 * 1134 * @since 3.0.0 1135 * 1136 * @param string $key Sanitized key. 1137 * @param string $raw_key The key prior to sanitization. 1138 */ 1139 return apply_filters( 'sanitize_key', $key, $raw_key ); 1140 } 1141 No newline at end of file -
src/wp-includes/ms-blogs.php
465 465 wp_cache_delete( $domain_path_key, 'blog-id-cache' ); 466 466 wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' ); 467 467 wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' ); 468 wp_cache_delete( $blog_id, 'blog_meta' ); 468 469 469 470 /** 470 471 * Fires immediately after a site has been removed from the object cache. … … 541 542 * Adds any sites from the given ids to the cache that do not already exist in cache. 542 543 * 543 544 * @since 4.6.0 545 * @since 4.9.0 The $update_meta_cache parameter was added. 544 546 * @access private 545 547 * 546 548 * @see update_site_cache() 549 * @see update_sitemeta_cache() 550 * 547 551 * @global wpdb $wpdb WordPress database abstraction object. 548 552 * 549 * @param array $ids ID list. 553 * @param array $ids ID list. 554 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 550 555 */ 551 function _prime_site_caches( $ids ) {556 function _prime_site_caches( $ids, $update_meta_cache = true ) { 552 557 global $wpdb; 553 558 554 559 $non_cached_ids = _get_non_cached_ids( $ids, 'sites' ); 555 560 if ( ! empty( $non_cached_ids ) ) { 556 561 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); 557 562 558 update_site_cache( $fresh_sites );563 update_site_cache( $fresh_sites, $update_meta_cache ); 559 564 } 560 565 } 561 566 … … 566 571 * 567 572 * @param array $sites Array of site objects. 568 573 */ 569 function update_site_cache( $sites ) {574 function update_site_cache( $sites, $update_meta_cache = true ) { 570 575 if ( ! $sites ) { 571 576 return; 572 577 } 573 578 $site_ids = array(); 574 579 foreach ( $sites as $site ) { 580 $site_ids[] = $site->blog_id; 575 581 wp_cache_add( $site->blog_id, $site, 'sites' ); 576 582 wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' ); 577 583 } 584 585 if ( $update_meta_cache ) { 586 update_sitemeta_cache( $site_ids ); 587 } 588 } 589 590 /** 591 * Updates metadata cache for list of site IDs. 592 * 593 * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache. 594 * Subsequent calls to `get_site_meta()` will not need to query the database. 595 * 596 * @since 4.9.0 597 * 598 * @param array $site_ids List of site IDs. 599 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success. 600 */ 601 function update_sitemeta_cache( $site_ids ) { 602 return update_meta_cache( 'blog', $site_ids ); 578 603 } 579 604 580 605 /** … … 638 663 return $query->query( $args ); 639 664 } 640 665 666 641 667 /** 642 668 * Retrieve option value for a given blog id based on name of option. 643 669 * … … 768 794 return $return; 769 795 } 770 796 797 798 799 /** 800 * Add meta data field to a site. 801 * 802 * Site meta data is called "Custom Fields" on the Administration Screen. 803 * 804 * @since 4.9.0 805 * 806 * @param int $site_id Site ID. 807 * @param string $meta_key Metadata name. 808 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 809 * @param bool $unique Optional. Whether the same key should not be added. 810 * Default false. 811 * @return int|false Meta ID on success, false on failure. 812 */ 813 function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) { 814 // If site meta not installed, quit early 815 if( !get_site_option('site_meta_supported') ){ 816 return false; 817 } 818 819 $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); 820 821 // Bust site query cache. 822 if ( $added ) { 823 wp_cache_set( 'last_changed', microtime(), 'sites' ); 824 } 825 826 return $added; 827 } 828 829 /** 830 * Remove metadata matching criteria from a site. 831 * 832 * You can match based on the key, or key and value. Removing based on key and 833 * value, will keep from removing duplicate metadata with the same key. It also 834 * allows removing all metadata matching key, if needed. 835 * 836 * @since 4.9.0 837 * 838 * @param int $site_id Site ID. 839 * @param string $meta_key Metadata name. 840 * @param mixed $meta_value Optional. Metadata value. Must be serializable if 841 * non-scalar. Default empty. 842 * @return bool True on success, false on failure. 843 */ 844 function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) { 845 // If site meta not installed, quit early 846 if( !get_site_option('site_meta_supported') ){ 847 return false; 848 } 849 850 $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value ); 851 852 // Bust site query cache. 853 if ( $deleted ) { 854 wp_cache_set( 'last_changed', microtime(), 'sites' ); 855 } 856 857 return $deleted; 858 } 859 860 /** 861 * Retrieve site meta field for a site. 862 * 863 * @since 4.9.0 864 * 865 * @param int $site_id Site ID. 866 * @param string $key Optional. The meta key to retrieve. By default, returns 867 * data for all keys. Default empty. 868 * @param bool $single Optional. Whether to return a single value. Default false. 869 * @return mixed Will be an array if $single is false. Will be value of meta data 870 * field if $single is true. 871 */ 872 function get_site_meta( $site_id, $key = '', $single = false ) { 873 // If site meta not installed, quit early 874 if( !get_site_option('site_meta_supported') ){ 875 return false; 876 } 877 return get_metadata( 'blog', $site_id, $key, $single ); 878 } 879 880 /** 881 * Update site meta field based on site ID. 882 * 883 * Use the $prev_value parameter to differentiate between meta fields with the 884 * same key and site ID. 885 * 886 * If the meta field for the site does not exist, it will be added. 887 * 888 * @since 4.9.0 889 * 890 * @param int $site_id Site ID. 891 * @param string $meta_key Metadata key. 892 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 893 * @param mixed $prev_value Optional. Previous value to check before removing. 894 * Default empty. 895 * @return int|bool Meta ID if the key didn't exist, true on successful update, 896 * false on failure. 897 */ 898 function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) { 899 // If site meta not installed, quit early 900 if( !get_site_option('site_meta_supported') ){ 901 return false; 902 } 903 904 $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); 905 906 // Bust site query cache. 907 if ( $updated ) { 908 wp_cache_set( 'last_changed', microtime(), 'sites' ); 909 } 910 911 return $updated; 912 } 913 914 /** 915 * Delete everything from site meta matching meta key. 916 * 917 * @since 4.9.0 918 * 919 * @param string $meta_key Metadata key to search for when deleting. 920 * @return bool Whether the site meta key was deleted from the database. 921 */ 922 function delete_site_meta_by_key( $meta_key ) { 923 // If site meta not installed, quit early 924 if ( ! get_site_option( 'site_meta_supported' ) ) { 925 return false; 926 } 927 928 $deleted = delete_metadata( 'blog', null, $meta_key, '', true ); 929 930 // Bust site query cache. 931 if ( $deleted ) { 932 wp_cache_set( 'last_changed', microtime(), 'sites' ); 933 } 934 935 return $deleted; 936 } 937 771 938 /** 772 939 * Switch the current blog. 773 940 * … … 842 1009 if ( is_array( $global_groups ) ) { 843 1010 wp_cache_add_global_groups( $global_groups ); 844 1011 } else { 845 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );1012 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) ); 846 1013 } 847 1014 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 848 1015 } … … 916 1083 if ( is_array( $global_groups ) ) { 917 1084 wp_cache_add_global_groups( $global_groups ); 918 1085 } else { 919 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );1086 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) ); 920 1087 } 921 1088 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 922 1089 } -
src/wp-includes/version.php
11 11 * 12 12 * @global int $wp_db_version 13 13 */ 14 $wp_db_version = 38590;14 $wp_db_version = 40001; 15 15 16 16 /** 17 17 * Holds the TinyMCE version -
src/wp-includes/wp-db.php
271 271 * @see wpdb::tables() 272 272 * @var array 273 273 */ 274 var $ms_global_tables = array( 'blogs', ' signups', 'site', 'sitemeta',274 var $ms_global_tables = array( 'blogs', 'blogmeta', 'signups', 'site', 'sitemeta', 275 275 'sitecategories', 'registration_log', 'blog_versions' ); 276 276 277 277 /** … … 383 383 public $blogs; 384 384 385 385 /** 386 * Multisite Blog Metadata table 387 * 388 * @since 4.9.0 389 * @access public 390 * @var string 391 */ 392 public $blogmeta; 393 394 /** 386 395 * Multisite Blog Versions table 387 396 * 388 397 * @since 3.0.0 -
src/wp-settings.php
95 95 // Load early WordPress files. 96 96 require( ABSPATH . WPINC . '/compat.php' ); 97 97 require( ABSPATH . WPINC . '/class-wp-list-util.php' ); 98 require( ABSPATH . WPINC . '/meta.php' ); 98 99 require( ABSPATH . WPINC . '/functions.php' ); 99 100 require( ABSPATH . WPINC . '/class-wp-matchesmapregex.php' ); 100 101 require( ABSPATH . WPINC . '/class-wp.php' ); … … 157 158 require( ABSPATH . WPINC . '/class-wp-user-query.php' ); 158 159 require( ABSPATH . WPINC . '/class-wp-session-tokens.php' ); 159 160 require( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' ); 160 require( ABSPATH . WPINC . '/meta.php' );161 161 require( ABSPATH . WPINC . '/class-wp-meta-query.php' ); 162 162 require( ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php' ); 163 163 require( ABSPATH . WPINC . '/general-template.php' ); -
tests/phpunit/includes/testcase.php
323 323 $wp_object_cache->__remoteset(); 324 324 } 325 325 wp_cache_flush(); 326 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );326 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) ); 327 327 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 328 328 } 329 329