Make WordPress Core


Ignore:
Timestamp:
01/08/2019 08:47:37 AM (5 years ago)
Author:
flixos90
Message:

Multisite: Move site-specific metadata integrations from the wrapper functions to the low-level Meta API functions.

This complements the work in [43729] and prepares site metadata for future REST API support.

Props spacedmonkey.
Fixes #45091. See #44467.

File:
1 edited

Legend:

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

    r44467 r44468  
    757757 */
    758758function update_sitemeta_cache( $site_ids ) {
    759     if ( ! is_site_meta_supported() ) {
    760         return false;
    761     }
    762 
    763759    return update_meta_cache( 'blog', $site_ids );
    764760}
     
    14761472 */
    14771473function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
    1478     // Bail if site meta table is not installed.
    1479     if ( ! is_site_meta_supported() ) {
    1480         /* translators: %s: database table name */
    1481         _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
    1482         return false;
    1483     }
    1484 
    1485     $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
    1486 
    1487     // Bust site query cache.
    1488     if ( $added ) {
    1489         wp_cache_set( 'last_changed', microtime(), 'sites' );
    1490     }
    1491 
    1492     return $added;
     1474    return add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
    14931475}
    14941476
     
    15091491 */
    15101492function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
    1511     // Bail if site meta table is not installed.
    1512     if ( ! is_site_meta_supported() ) {
    1513         /* translators: %s: database table name */
    1514         _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
    1515         return false;
    1516     }
    1517 
    1518     $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
    1519 
    1520     // Bust site query cache.
    1521     if ( $deleted ) {
    1522         wp_cache_set( 'last_changed', microtime(), 'sites' );
    1523     }
    1524 
    1525     return $deleted;
     1493    return delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
    15261494}
    15271495
     
    15391507 */
    15401508function get_site_meta( $site_id, $key = '', $single = false ) {
    1541     // Bail if site meta table is not installed.
    1542     if ( ! is_site_meta_supported() ) {
    1543         /* translators: %s: database table name */
    1544         _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
    1545         return false;
    1546     }
    1547 
    15481509    return get_metadata( 'blog', $site_id, $key, $single );
    15491510}
     
    15681529 */
    15691530function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) {
    1570     // Bail if site meta table is not installed.
    1571     if ( ! is_site_meta_supported() ) {
    1572         /* translators: %s: database table name */
    1573         _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
    1574         return false;
    1575     }
    1576 
    1577     $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
    1578 
    1579     // Bust site query cache.
    1580     if ( $updated ) {
    1581         wp_cache_set( 'last_changed', microtime(), 'sites' );
    1582     }
    1583 
    1584     return $updated;
     1531    return update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
    15851532}
    15861533
     
    15941541 */
    15951542function delete_site_meta_by_key( $meta_key ) {
    1596     // Bail if site meta table is not installed.
    1597     if ( ! is_site_meta_supported() ) {
    1598         /* translators: %s: database table name */
    1599         _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
    1600         return false;
    1601     }
    1602 
    1603     $deleted = delete_metadata( 'blog', null, $meta_key, '', true );
    1604 
    1605     // Bust site query cache.
    1606     if ( $deleted ) {
    1607         wp_cache_set( 'last_changed', microtime(), 'sites' );
    1608     }
    1609 
    1610     return $deleted;
     1543    return delete_metadata( 'blog', null, $meta_key, '', true );
    16111544}
    16121545
     
    23102243    update_blog_option( $site_id, 'blog_public', $public );
    23112244}
     2245
     2246/**
     2247 * Sets the last changed time for the 'sites' cache group.
     2248 *
     2249 * @since 5.1.0
     2250 */
     2251function wp_cache_set_sites_last_changed() {
     2252    wp_cache_set( 'last_changed', microtime(), 'sites' );
     2253}
     2254
     2255/**
     2256 * Aborts calls to site meta if it is not supported.
     2257 *
     2258 * @since 5.1.0
     2259 *
     2260 * @global wpdb $wpdb WordPress database abstraction object.
     2261 *
     2262 * @param mixed $check Skip-value for whether to proceed site meta function execution.
     2263 * @return mixed Original value of $check, or false if site meta is not supported.
     2264 */
     2265function wp_check_site_meta_support_prefilter( $check ) {
     2266    if ( ! is_site_meta_supported() ) {
     2267        /* translators: %s: database table name */
     2268        _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
     2269        return false;
     2270    }
     2271
     2272    return $check;
     2273}
Note: See TracChangeset for help on using the changeset viewer.