Make WordPress Core


Ignore:
Timestamp:
03/16/2018 02:14:04 AM (7 years ago)
Author:
flixos90
Message:

Multisite: Introduce metadata for sites.

A new global multisite table wp_blogmeta is added to the database schema, and a set of *_site_meta() API functions are introduced.

The implementation fails gracefully when the new table is not yet available, which may happen especially shortly after the core update, before the network has been upgraded to the new database schema. The presence of the table is detected once and stored as a global setting on the main network.

Core does not yet use site metadata, but there are several use-cases to be implemented or explored in the near future, and it allows plugins to extend sites with arbitrary data, which will come in particularly handy with the upcoming REST API endpoint for sites.

Props spacedmonkey, johnjamesjacoby, jeremyfelt, flixos90.
Fixes #37923.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r42824 r42836  
    47284728
    47294729/**
     4730 * Determines whether site meta is enabled.
     4731 *
     4732 * This function checks whether the 'blogmeta' database table exists. The result is saved as
     4733 * a setting for the main network, making it essentially a global setting. Subsequent requests
     4734 * will refer to this setting instead of running the query.
     4735 *
     4736 * @since 5.0.0
     4737 *
     4738 * @global wpdb $wpdb WordPress database abstraction object.
     4739 *
     4740 * @return bool True if site meta is supported, false otherwise.
     4741 */
     4742function is_site_meta_supported() {
     4743    global $wpdb;
     4744
     4745    if ( ! is_multisite() ) {
     4746        return false;
     4747    }
     4748
     4749    $network_id = get_main_network_id();
     4750
     4751    $supported = get_network_option( $network_id, 'site_meta_supported', false );
     4752    if ( false === $supported ) {
     4753        $supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0;
     4754
     4755        update_network_option( $network_id, 'site_meta_supported', $supported );
     4756    }
     4757
     4758    return (bool) $supported;
     4759}
     4760
     4761/**
    47304762 * gmt_offset modification for smart timezone handling.
    47314763 *
Note: See TracChangeset for help on using the changeset viewer.