Ticket #37923: 37923.13.diff
File 37923.13.diff, 15.2 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/ms.php
135 135 $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); 136 136 } 137 137 138 if ( is_site_meta_supported() ) { 139 $blog_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->blogmeta WHERE blog_id = %d ", $blog_id ) ); 140 foreach ( $blog_meta_ids as $mid ) { 141 delete_metadata_by_mid( 'blog', $mid ); 142 } 143 } 144 138 145 $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) ); 139 146 140 147 /** -
src/wp-admin/includes/schema.php
267 267 PRIMARY KEY (blog_id), 268 268 KEY db_version (db_version) 269 269 ) $charset_collate; 270 CREATE TABLE $wpdb->blogmeta ( 271 meta_id bigint(20) unsigned NOT NULL auto_increment, 272 blog_id bigint(20) signed NOT NULL default '0', 273 meta_key varchar(255) default NULL, 274 meta_value longtext, 275 PRIMARY KEY (meta_id), 276 KEY term_id (term_id), 277 KEY meta_key (meta_key($max_index_length)) 278 ) $charset_collate; 270 279 CREATE TABLE $wpdb->registration_log ( 271 280 ID bigint(20) NOT NULL auto_increment, 272 281 email varchar(255) NOT NULL default '', -
src/wp-admin/includes/upgrade.php
2133 2133 } 2134 2134 } 2135 2135 } 2136 2137 // 4.9 2138 if ( $wp_current_db_version < 40001 ) { 2139 $network_id = get_main_network_id(); 2140 delete_network_option( $network_id, 'site_meta_supported' ); 2141 is_site_meta_supported(); 2142 } 2136 2143 } 2137 2144 2138 2145 // -
src/wp-includes/class-wp-site-query.php
288 288 289 289 // Prime site network caches. 290 290 if ( $this->query_vars['update_site_cache'] ) { 291 _prime_site_caches( $site_ids );291 _prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache'] ); 292 292 } 293 293 294 294 // Fetch full site objects from the primed cache. -
src/wp-includes/functions.php
4704 4704 } 4705 4705 4706 4706 /** 4707 * Determines whether site meta is enabled. 4708 * 4709 * This function checks whether the 'blogmeta' database table exists. The result is saved as 4710 * a setting for the main network, making it essentially a global setting. Subsequent requests 4711 * will refer to this setting instead of running the query. The $force parameter can be used 4712 * to bypass the setting, and reset it accordingly, however this is not recommended. 4713 * 4714 * The 'is_site_meta_supported' filter can be used to bypass the database checks completely. 4715 * 4716 * @since 4.9.0 4717 * 4718 * @global wpdb $wpdb WordPress database abstraction object. 4719 * 4720 * @return bool True if site meta is supported, false otherwise. 4721 */ 4722 function is_site_meta_supported() { 4723 global $wpdb; 4724 4725 if ( ! is_multisite() ) { 4726 return false; 4727 } 4728 4729 $network_id = get_main_network_id(); 4730 4731 if ( false === ( $supported = get_network_option( $network_id, 'site_meta_supported', false ) ) ) { 4732 $supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0; 4733 4734 update_network_option( $network_id, 'site_meta_supported', $supported ); 4735 } 4736 4737 return (bool) $supported; 4738 } 4739 4740 /** 4707 4741 * gmt_offset modification for smart timezone handling. 4708 4742 * 4709 4743 * Overrides the gmt_offset option if we have a timezone_string available. -
src/wp-includes/load.php
567 567 } 568 568 569 569 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 570 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' ) );570 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' ) ); 571 571 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 572 572 } 573 573 } -
src/wp-includes/ms-blogs.php
474 474 wp_cache_delete( $domain_path_key, 'blog-id-cache' ); 475 475 wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' ); 476 476 wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' ); 477 wp_cache_delete( $blog_id, 'blog_meta' ); 477 478 478 479 /** 479 480 * Fires immediately after a site has been removed from the object cache. … … 585 586 * 586 587 * @param array $sites Array of site objects. 587 588 */ 588 function update_site_cache( $sites ) {589 function update_site_cache( $sites, $update_meta_cache = true ) { 589 590 if ( ! $sites ) { 590 591 return; 591 592 } 592 593 $site_ids = array(); 593 594 foreach ( $sites as $site ) { 595 $site_ids[] = $site->blog_id; 594 596 wp_cache_add( $site->blog_id, $site, 'sites' ); 595 597 wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' ); 596 598 } 599 600 if ( $update_meta_cache ) { 601 update_sitemeta_cache( $site_ids ); 602 } 603 } 604 605 /** 606 * Updates metadata cache for list of site IDs. 607 * 608 * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache. 609 * Subsequent calls to `get_site_meta()` will not need to query the database. 610 * 611 * @since 4.9.0 612 * 613 * @param array $site_ids List of site IDs. 614 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success. 615 */ 616 function update_sitemeta_cache( $site_ids ) { 617 if ( ! is_site_meta_supported() ) { 618 return false; 619 } 620 621 return update_meta_cache( 'blog', $site_ids ); 597 622 } 598 623 599 624 /** … … 658 683 return $query->query( $args ); 659 684 } 660 685 686 661 687 /** 662 688 * Retrieve option value for a given blog id based on name of option. 663 689 * … … 796 822 return $return; 797 823 } 798 824 825 826 827 /** 828 * Add meta data field to a site. 829 * 830 * Site meta data is called "Custom Fields" on the Administration Screen. 831 * 832 * @since 4.9.0 833 * 834 * @param int $site_id Site ID. 835 * @param string $meta_key Metadata name. 836 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 837 * @param bool $unique Optional. Whether the same key should not be added. 838 * Default false. 839 * @return int|false Meta ID on success, false on failure. 840 */ 841 function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) { 842 // Bail if site meta table is not installed. 843 if ( ! is_site_meta_supported() ) { 844 return false; 845 } 846 847 $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); 848 849 // Bust site query cache. 850 if ( $added ) { 851 // @todo use clean_blog_cache here 852 wp_cache_set( 'last_changed', microtime(), 'sites' ); 853 } 854 855 return $added; 856 } 857 858 /** 859 * Remove metadata matching criteria from a site. 860 * 861 * You can match based on the key, or key and value. Removing based on key and 862 * value, will keep from removing duplicate metadata with the same key. It also 863 * allows removing all metadata matching key, if needed. 864 * 865 * @since 4.9.0 866 * 867 * @param int $site_id Site ID. 868 * @param string $meta_key Metadata name. 869 * @param mixed $meta_value Optional. Metadata value. Must be serializable if 870 * non-scalar. Default empty. 871 * @return bool True on success, false on failure. 872 */ 873 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 return false; 877 } 878 879 $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value ); 880 881 // Bust site query cache. 882 if ( $deleted ) { 883 // @todo use clean_blog_cache here 884 wp_cache_set( 'last_changed', microtime(), 'sites' ); 885 } 886 887 return $deleted; 888 } 889 890 /** 891 * Retrieve site meta field for a site. 892 * 893 * @since 4.9.0 894 * 895 * @param int $site_id Site ID. 896 * @param string $key Optional. The meta key to retrieve. By default, returns 897 * data for all keys. Default empty. 898 * @param bool $single Optional. Whether to return a single value. Default false. 899 * @return mixed Will be an array if $single is false. Will be value of meta data 900 * field if $single is true. 901 */ 902 function get_site_meta( $site_id, $key = '', $single = false ) { 903 // Bail if site meta table is not installed. 904 if ( ! is_site_meta_supported() ) { 905 return false; 906 } 907 908 return get_metadata( 'blog', $site_id, $key, $single ); 909 } 910 911 /** 912 * Update site meta field based on site ID. 913 * 914 * Use the $prev_value parameter to differentiate between meta fields with the 915 * same key and site ID. 916 * 917 * If the meta field for the site does not exist, it will be added. 918 * 919 * @since 4.9.0 920 * 921 * @param int $site_id Site ID. 922 * @param string $meta_key Metadata key. 923 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 924 * @param mixed $prev_value Optional. Previous value to check before removing. 925 * Default empty. 926 * @return int|bool Meta ID if the key didn't exist, true on successful update, 927 * false on failure. 928 */ 929 function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) { 930 // Bail if site meta table is not installed. 931 if ( ! is_site_meta_supported() ) { 932 return false; 933 } 934 935 $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); 936 937 // Bust site query cache. 938 if ( $updated ) { 939 // @todo use clean_blog_cache here 940 wp_cache_set( 'last_changed', microtime(), 'sites' ); 941 } 942 943 return $updated; 944 } 945 946 /** 947 * Delete everything from site meta matching meta key. 948 * 949 * @since 4.9.0 950 * 951 * @param string $meta_key Metadata key to search for when deleting. 952 * @return bool Whether the site meta key was deleted from the database. 953 */ 954 function delete_site_meta_by_key( $meta_key ) { 955 // Bail if site meta table is not installed. 956 if ( ! is_site_meta_supported() ) { 957 return false; 958 } 959 960 $deleted = delete_metadata( 'blog', null, $meta_key, '', true ); 961 962 // Bust site query cache. 963 if ( $deleted ) { 964 // @todo use clean_blog_cache here 965 wp_cache_set( 'last_changed', microtime(), 'sites' ); 966 } 967 968 return $deleted; 969 } 970 799 971 /** 800 972 * Switch the current blog. 801 973 * … … 869 1041 if ( is_array( $global_groups ) ) { 870 1042 wp_cache_add_global_groups( $global_groups ); 871 1043 } else { 872 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' ) );1044 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' ) ); 873 1045 } 874 1046 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 875 1047 } … … 937 1109 if ( is_array( $global_groups ) ) { 938 1110 wp_cache_add_global_groups( $global_groups ); 939 1111 } else { 940 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' ) );1112 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' ) ); 941 1113 } 942 1114 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 943 1115 } -
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
400 400 public $blogs; 401 401 402 402 /** 403 * Multisite Blog Metadata table 404 * 405 * @since 4.9.0 406 * @var string 407 */ 408 public $blogmeta; 409 410 /** 403 411 * Multisite Blog Versions table 404 412 * 405 413 * @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 . '/formatting.php' ); 99 require( ABSPATH . WPINC . '/meta.php' ); 98 100 require( ABSPATH . WPINC . '/functions.php' ); 99 101 require( ABSPATH . WPINC . '/class-wp-matchesmapregex.php' ); 100 102 require( ABSPATH . WPINC . '/class-wp.php' ); … … 143 145 // Load most of WordPress. 144 146 require( ABSPATH . WPINC . '/class-wp-walker.php' ); 145 147 require( ABSPATH . WPINC . '/class-wp-ajax-response.php' ); 146 require( ABSPATH . WPINC . '/formatting.php' );147 148 require( ABSPATH . WPINC . '/capabilities.php' ); 148 149 require( ABSPATH . WPINC . '/class-wp-roles.php' ); 149 150 require( ABSPATH . WPINC . '/class-wp-role.php' ); … … 158 159 require( ABSPATH . WPINC . '/class-wp-user-query.php' ); 159 160 require( ABSPATH . WPINC . '/class-wp-session-tokens.php' ); 160 161 require( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' ); 161 require( ABSPATH . WPINC . '/meta.php' );162 162 require( ABSPATH . WPINC . '/class-wp-meta-query.php' ); 163 163 require( ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php' ); 164 164 require( ABSPATH . WPINC . '/general-template.php' ); -
tests/phpunit/includes/testcase.php
328 328 $wp_object_cache->__remoteset(); 329 329 } 330 330 wp_cache_flush(); 331 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' ) );331 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' ) ); 332 332 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 333 333 } 334 334