Ticket #37923: 37923.5.diff
File 37923.5.diff, 19.0 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 '', … … 1018 1027 'subdomain_install' => intval( $subdomain_install ), 1019 1028 'global_terms_enabled' => global_terms_enabled() ? '1' : '0', 1020 1029 'ms_files_rewriting' => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0', 1030 'site_meta_supported' => is_multisite() ? get_network_option( null, 'site_meta_supported' ) : 1, 1021 1031 'initial_db_version' => get_option( 'initial_db_version' ), 1022 1032 'active_sitewide_plugins' => array(), 1023 1033 'WPLANG' => get_locale(), -
src/wp-admin/includes/upgrade.php
1881 1881 } 1882 1882 } 1883 1883 } 1884 1885 // 4.9 1886 if ( $wp_current_db_version < 40001 ) { 1887 $exists = 0; 1888 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ) { 1889 $exists = 1; 1890 } 1891 update_network_option( null, 'site_meta_supported', $exists ); 1892 } 1884 1893 } 1885 1894 1886 1895 // -
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 544 * @ access private545 * @since 4.9.0 The $update_meta_cache parameter was added. 545 546 * 546 547 * @see update_site_cache() 548 * @see update_sitemeta_cache() 549 * 547 550 * @global wpdb $wpdb WordPress database abstraction object. 548 551 * 549 * @param array $ids ID list. 552 * @param array $ids ID list. 553 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 550 554 */ 551 function _prime_site_caches( $ids ) {555 function _prime_site_caches( $ids, $update_meta_cache = true ) { 552 556 global $wpdb; 553 557 554 558 $non_cached_ids = _get_non_cached_ids( $ids, 'sites' ); 555 559 if ( ! empty( $non_cached_ids ) ) { 556 560 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); 557 561 558 update_site_cache( $fresh_sites );562 update_site_cache( $fresh_sites, $update_meta_cache ); 559 563 } 560 564 } 561 565 … … 566 570 * 567 571 * @param array $sites Array of site objects. 568 572 */ 569 function update_site_cache( $sites ) {573 function update_site_cache( $sites, $update_meta_cache = true ) { 570 574 if ( ! $sites ) { 571 575 return; 572 576 } 573 577 $site_ids = array(); 574 578 foreach ( $sites as $site ) { 579 $site_ids[] = $site->blog_id; 575 580 wp_cache_add( $site->blog_id, $site, 'sites' ); 576 581 wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' ); 577 582 } 583 584 if ( $update_meta_cache ) { 585 update_sitemeta_cache( $site_ids ); 586 } 587 } 588 589 /** 590 * Updates metadata cache for list of site IDs. 591 * 592 * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache. 593 * Subsequent calls to `get_site_meta()` will not need to query the database. 594 * 595 * @since 4.9.0 596 * 597 * @param array $site_ids List of site IDs. 598 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success. 599 */ 600 function update_sitemeta_cache( $site_ids ) { 601 if ( ! get_network_option( null, 'site_meta_supported' ) ) { 602 return false; 603 } 604 return update_meta_cache( 'blog', $site_ids ); 578 605 } 579 606 580 607 /** … … 638 665 return $query->query( $args ); 639 666 } 640 667 668 641 669 /** 642 670 * Retrieve option value for a given blog id based on name of option. 643 671 * … … 768 796 return $return; 769 797 } 770 798 799 800 801 /** 802 * Add meta data field to a site. 803 * 804 * Site meta data is called "Custom Fields" on the Administration Screen. 805 * 806 * @since 4.9.0 807 * 808 * @param int $site_id Site ID. 809 * @param string $meta_key Metadata name. 810 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 811 * @param bool $unique Optional. Whether the same key should not be added. 812 * Default false. 813 * @return int|false Meta ID on success, false on failure. 814 */ 815 function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) { 816 // If site meta not installed, quit early 817 if ( ! get_network_option( null, 'site_meta_supported' ) ) { 818 return false; 819 } 820 821 $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); 822 823 // Bust site query cache. 824 if ( $added ) { 825 wp_cache_set( 'last_changed', microtime(), 'sites' ); 826 } 827 828 return $added; 829 } 830 831 /** 832 * Remove metadata matching criteria from a site. 833 * 834 * You can match based on the key, or key and value. Removing based on key and 835 * value, will keep from removing duplicate metadata with the same key. It also 836 * allows removing all metadata matching key, if needed. 837 * 838 * @since 4.9.0 839 * 840 * @param int $site_id Site ID. 841 * @param string $meta_key Metadata name. 842 * @param mixed $meta_value Optional. Metadata value. Must be serializable if 843 * non-scalar. Default empty. 844 * @return bool True on success, false on failure. 845 */ 846 function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) { 847 // If site meta not installed, quit early 848 if ( ! get_network_option( null, 'site_meta_supported' ) ) { 849 return false; 850 } 851 852 $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value ); 853 854 // Bust site query cache. 855 if ( $deleted ) { 856 wp_cache_set( 'last_changed', microtime(), 'sites' ); 857 } 858 859 return $deleted; 860 } 861 862 /** 863 * Retrieve site meta field for a site. 864 * 865 * @since 4.9.0 866 * 867 * @param int $site_id Site ID. 868 * @param string $key Optional. The meta key to retrieve. By default, returns 869 * data for all keys. Default empty. 870 * @param bool $single Optional. Whether to return a single value. Default false. 871 * @return mixed Will be an array if $single is false. Will be value of meta data 872 * field if $single is true. 873 */ 874 function get_site_meta( $site_id, $key = '', $single = false ) { 875 // If site meta not installed, quit early 876 if ( ! get_network_option( null, 'site_meta_supported' ) ) { 877 return false; 878 } 879 880 return get_metadata( 'blog', $site_id, $key, $single ); 881 } 882 883 /** 884 * Update site meta field based on site ID. 885 * 886 * Use the $prev_value parameter to differentiate between meta fields with the 887 * same key and site ID. 888 * 889 * If the meta field for the site does not exist, it will be added. 890 * 891 * @since 4.9.0 892 * 893 * @param int $site_id Site ID. 894 * @param string $meta_key Metadata key. 895 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 896 * @param mixed $prev_value Optional. Previous value to check before removing. 897 * Default empty. 898 * @return int|bool Meta ID if the key didn't exist, true on successful update, 899 * false on failure. 900 */ 901 function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) { 902 // If site meta not installed, quit early 903 if ( ! get_network_option( null, 'site_meta_supported' ) ) { 904 return false; 905 } 906 907 $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); 908 909 // Bust site query cache. 910 if ( $updated ) { 911 wp_cache_set( 'last_changed', microtime(), 'sites' ); 912 } 913 914 return $updated; 915 } 916 917 /** 918 * Delete everything from site meta matching meta key. 919 * 920 * @since 4.9.0 921 * 922 * @param string $meta_key Metadata key to search for when deleting. 923 * @return bool Whether the site meta key was deleted from the database. 924 */ 925 function delete_site_meta_by_key( $meta_key ) { 926 // If site meta not installed, quit early 927 if ( ! get_network_option( null, 'site_meta_supported' ) ) { 928 return false; 929 } 930 931 $deleted = delete_metadata( 'blog', null, $meta_key, '', true ); 932 933 // Bust site query cache. 934 if ( $deleted ) { 935 wp_cache_set( 'last_changed', microtime(), 'sites' ); 936 } 937 938 return $deleted; 939 } 940 771 941 /** 772 942 * Switch the current blog. 773 943 * … … 842 1012 if ( is_array( $global_groups ) ) { 843 1013 wp_cache_add_global_groups( $global_groups ); 844 1014 } 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' ) );1015 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 1016 } 847 1017 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 848 1018 } … … 916 1086 if ( is_array( $global_groups ) ) { 917 1087 wp_cache_add_global_groups( $global_groups ); 918 1088 } 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' ) );1089 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 1090 } 921 1091 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 922 1092 } -
src/wp-includes/option.php
225 225 if ( empty($network_id) ) 226 226 $network_id = get_current_network_id(); 227 227 228 $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' );228 $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting', 'site_meta_supported' ); 229 229 230 230 $core_options_in = "'" . implode("', '", $core_options) . "'"; 231 231 $options = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $network_id ) ); -
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 * @var string 390 */ 391 public $blogmeta; 392 393 /** 386 394 * Multisite Blog Versions table 387 395 * 388 396 * @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