Make WordPress Core

Ticket #37923: 37923.19.diff

File 37923.19.diff, 8.1 KB (added by spacedmonkey, 6 years ago)
  • src/wp-admin/includes/schema.php

     
    13021302 *
    13031303 * @param int   $site_id Site ID to populate meta for.
    13041304 * @param array $meta    Optional. Custom meta $key => $value pairs to use. Default empty array.
     1305 * @return bool  Return true is successful and false if site meta not supported.
    13051306 */
    13061307function populate_site_meta( $site_id, array $meta = array() ) {
    13071308        global $wpdb;
     
    13081309
    13091310        $site_id = (int) $site_id;
    13101311
    1311         if ( ! is_site_meta_supported() ) {
    1312                 return;
    1313         }
    13141312
     1313        /**
     1314         * Filters meta for a site on creation.
     1315         *
     1316         * @since 5.1.0
     1317         *
     1318         * @param array $sitemeta   Associative array of site meta keys and values to be inserted.
     1319         * @param int   $network_id ID of site to populate.
     1320         */
     1321        $meta = apply_filters( 'populate_site_meta', $meta, $site_id );
     1322
    13151323        if ( empty( $meta ) ) {
    1316                 return;
     1324                return false;
    13171325        }
    13181326
    13191327        $insert = '';
     
    13291337
    13301338        $wpdb->query( "INSERT INTO $wpdb->blogmeta ( blog_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
    13311339
    1332         wp_cache_set( 'last_changed', microtime(), 'sites' );
     1340        /**
     1341         * Fires after site meta is created.
     1342         *
     1343         * @since 5.1.0
     1344         *
     1345         * @param array $sitemeta   Associative array of site meta keys and values to be inserted.
     1346         * @param int   $network_id ID of site to populate.
     1347         */
     1348        do_action( 'populated_site_meta', $meta, $site_id );
     1349
     1350        return true;
    13331351}
  • src/wp-includes/ms-blogs.php

     
    745745}
    746746
    747747/**
     748 * Sets the last changed time for the 'sites' cache group.
     749 *
     750 * @since 5.1.0
     751 */
     752function wp_cache_set_sites_last_changed() {
     753        wp_cache_set( 'last_changed', microtime(), 'sites' );
     754}
     755
     756/**
    748757 * Updates metadata cache for list of site IDs.
    749758 *
    750759 * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache.
     
    756765 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
    757766 */
    758767function update_sitemeta_cache( $site_ids ) {
    759         if ( ! is_site_meta_supported() ) {
    760                 return false;
    761         }
    762 
    763768        return update_meta_cache( 'blog', $site_ids );
    764769}
    765770
     
    14751480 * @return int|false Meta ID on success, false on failure.
    14761481 */
    14771482function 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.0.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;
     1483        return add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
    14931484}
    14941485
    14951486/**
     
    15081499 * @return bool True on success, false on failure.
    15091500 */
    15101501function 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.0.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;
     1502        return delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
    15261503}
    15271504
    15281505/**
     
    15381515 *               field if $single is true.
    15391516 */
    15401517function 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.0.0' );
    1545                 return false;
    1546         }
    1547 
    15481518        return get_metadata( 'blog', $site_id, $key, $single );
    15491519}
    15501520
     
    15671537 *                  false on failure.
    15681538 */
    15691539function 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.0.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;
     1540        return update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );;
    15851541}
    15861542
    15871543/**
     
    15931549 * @return bool Whether the site meta key was deleted from the database.
    15941550 */
    15951551function 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.0.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;
     1552        return delete_metadata( 'blog', null, $meta_key, '', true );
    16111553}
    16121554
    16131555/**
     
    23092251
    23102252        update_blog_option( $site_id, 'blog_public', $public );
    23112253}
     2254
     2255/**
     2256 * Aborts calls to site meta if it is not supported.
     2257 *
     2258 * @since 5.1.0
     2259 *
     2260 * @param mixed $check Skip-value for whether to proceed site meta function execution.
     2261 * @return mixed Original value of $check, or false if site meta is not supported.
     2262 */
     2263function wp_check_site_meta_support_prefilter( $check ) {
     2264        if ( ! is_site_meta_supported() ) {
     2265                /* translators: %s: database table name */
     2266                _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
     2267                return false;
     2268        }
     2269
     2270        return $check;
     2271}
     2272 No newline at end of file
  • src/wp-includes/ms-default-filters.php

     
    5353add_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10, 1 );
    5454add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 );
    5555
     56// Site meta
     57add_action( 'added_site_meta', 'wp_cache_set_sites_last_changed' );
     58add_action( 'updated_site_meta', 'wp_cache_set_sites_last_changed' );
     59add_action( 'deleted_site_meta', 'wp_cache_set_sites_last_changed' );
     60add_action( 'populated_site_meta', 'wp_cache_set_sites_last_changed' );
     61add_filter( 'get_site_metadata', 'wp_check_site_meta_support_prefilter' );
     62add_filter( 'add_site_metadata', 'wp_check_site_meta_support_prefilter' );
     63add_filter( 'update_site_metadata', 'wp_check_site_meta_support_prefilter' );
     64add_filter( 'delete_site_metadata', 'wp_check_site_meta_support_prefilter' );
     65add_filter( 'get_site_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
     66add_filter( 'update_site_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
     67add_filter( 'delete_site_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
     68add_filter( 'update_site_metadata_cache', 'wp_check_site_meta_support_prefilter' );
     69add_filter( 'populate_site_meta', 'wp_check_site_meta_support_prefilter' );
     70
    5671// Register Nonce
    5772add_action( 'signup_hidden_fields', 'signup_nonce_fields' );
    5873