Ticket #37923: 37923.7.diff
File 37923.7.diff, 19.8 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/ms.php
126 126 foreach ( (array) $drop_tables as $table ) { 127 127 $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); 128 128 } 129 129 if ( is_site_meta_supported() ) { 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_site_meta_supported(), 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 $supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0; 1888 update_network_option( null, 'site_meta_supported', $supported ); 1889 } 1884 1890 } 1885 1891 1886 1892 // -
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/functions.php
4499 4499 } 4500 4500 4501 4501 /** 4502 * Determine whether site meta is enabled. 4503 * 4504 * @since 4.9.0 4505 * @global wpdb $wpdb WordPress database abstraction object. 4506 * @return int 4507 */ 4508 function is_site_meta_supported() { 4509 global $wpdb; 4510 4511 if ( ! is_multisite() ) { 4512 return 0; 4513 } 4514 4515 $network_id = get_main_network_id(); 4516 4517 $supported = get_network_option( $network_id, 'site_meta_supported', false ); 4518 if ( false === $supported ) { 4519 $supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0; 4520 update_network_option( $network_id, 'site_meta_supported', $supported ); 4521 } 4522 4523 return apply_filters( 'site_meta_supported', $supported ); 4524 } 4525 4526 /** 4502 4527 * gmt_offset modification for smart timezone handling. 4503 4528 * 4504 4529 * Overrides the gmt_offset option if we have a timezone_string available. -
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 if ( ! is_site_meta_supported() ) { 603 return false; 604 } 605 return update_meta_cache( 'blog', $site_ids ); 578 606 } 579 607 580 608 /** … … 638 666 return $query->query( $args ); 639 667 } 640 668 669 641 670 /** 642 671 * Retrieve option value for a given blog id based on name of option. 643 672 * … … 768 797 return $return; 769 798 } 770 799 800 801 802 /** 803 * Add meta data field to a site. 804 * 805 * Site meta data is called "Custom Fields" on the Administration Screen. 806 * 807 * @since 4.9.0 808 * 809 * @param int $site_id Site ID. 810 * @param string $meta_key Metadata name. 811 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 812 * @param bool $unique Optional. Whether the same key should not be added. 813 * Default false. 814 * @return int|false Meta ID on success, false on failure. 815 */ 816 function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) { 817 // If site meta not installed, quit early 818 if ( ! is_site_meta_supported() ) { 819 return false; 820 } 821 822 $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); 823 824 // Bust site query cache. 825 if ( $added ) { 826 wp_cache_set( 'last_changed', microtime(), 'sites' ); 827 } 828 829 return $added; 830 } 831 832 /** 833 * Remove metadata matching criteria from a site. 834 * 835 * You can match based on the key, or key and value. Removing based on key and 836 * value, will keep from removing duplicate metadata with the same key. It also 837 * allows removing all metadata matching key, if needed. 838 * 839 * @since 4.9.0 840 * 841 * @param int $site_id Site ID. 842 * @param string $meta_key Metadata name. 843 * @param mixed $meta_value Optional. Metadata value. Must be serializable if 844 * non-scalar. Default empty. 845 * @return bool True on success, false on failure. 846 */ 847 function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) { 848 // If site meta not installed, quit early 849 if ( ! is_site_meta_supported() ) { 850 return false; 851 } 852 853 $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value ); 854 855 // Bust site query cache. 856 if ( $deleted ) { 857 wp_cache_set( 'last_changed', microtime(), 'sites' ); 858 } 859 860 return $deleted; 861 } 862 863 /** 864 * Retrieve site meta field for a site. 865 * 866 * @since 4.9.0 867 * 868 * @param int $site_id Site ID. 869 * @param string $key Optional. The meta key to retrieve. By default, returns 870 * data for all keys. Default empty. 871 * @param bool $single Optional. Whether to return a single value. Default false. 872 * @return mixed Will be an array if $single is false. Will be value of meta data 873 * field if $single is true. 874 */ 875 function get_site_meta( $site_id, $key = '', $single = false ) { 876 // If site meta not installed, quit early 877 if ( ! is_site_meta_supported() ) { 878 return false; 879 } 880 881 return get_metadata( 'blog', $site_id, $key, $single ); 882 } 883 884 /** 885 * Update site meta field based on site ID. 886 * 887 * Use the $prev_value parameter to differentiate between meta fields with the 888 * same key and site ID. 889 * 890 * If the meta field for the site does not exist, it will be added. 891 * 892 * @since 4.9.0 893 * 894 * @param int $site_id Site ID. 895 * @param string $meta_key Metadata key. 896 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 897 * @param mixed $prev_value Optional. Previous value to check before removing. 898 * Default empty. 899 * @return int|bool Meta ID if the key didn't exist, true on successful update, 900 * false on failure. 901 */ 902 function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) { 903 // If site meta not installed, quit early 904 if ( ! is_site_meta_supported() ) { 905 return false; 906 } 907 908 $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); 909 910 // Bust site query cache. 911 if ( $updated ) { 912 wp_cache_set( 'last_changed', microtime(), 'sites' ); 913 } 914 915 return $updated; 916 } 917 918 /** 919 * Delete everything from site meta matching meta key. 920 * 921 * @since 4.9.0 922 * 923 * @param string $meta_key Metadata key to search for when deleting. 924 * @return bool Whether the site meta key was deleted from the database. 925 */ 926 function delete_site_meta_by_key( $meta_key ) { 927 // If site meta not installed, quit early 928 if ( ! is_site_meta_supported() ) { 929 return false; 930 } 931 932 $deleted = delete_metadata( 'blog', null, $meta_key, '', true ); 933 934 // Bust site query cache. 935 if ( $deleted ) { 936 wp_cache_set( 'last_changed', microtime(), 'sites' ); 937 } 938 939 return $deleted; 940 } 941 771 942 /** 772 943 * Switch the current blog. 773 944 * … … 842 1013 if ( is_array( $global_groups ) ) { 843 1014 wp_cache_add_global_groups( $global_groups ); 844 1015 } 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' ) );1016 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 1017 } 847 1018 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 848 1019 } … … 916 1087 if ( is_array( $global_groups ) ) { 917 1088 wp_cache_add_global_groups( $global_groups ); 918 1089 } 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' ) );1090 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 1091 } 921 1092 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 922 1093 } -
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