Ticket #37923: 37923.19.diff
File 37923.19.diff, 8.1 KB (added by , 6 years ago) |
---|
-
src/wp-admin/includes/schema.php
1302 1302 * 1303 1303 * @param int $site_id Site ID to populate meta for. 1304 1304 * @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. 1305 1306 */ 1306 1307 function populate_site_meta( $site_id, array $meta = array() ) { 1307 1308 global $wpdb; … … 1308 1309 1309 1310 $site_id = (int) $site_id; 1310 1311 1311 if ( ! is_site_meta_supported() ) {1312 return;1313 }1314 1312 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 1315 1323 if ( empty( $meta ) ) { 1316 return ;1324 return false; 1317 1325 } 1318 1326 1319 1327 $insert = ''; … … 1329 1337 1330 1338 $wpdb->query( "INSERT INTO $wpdb->blogmeta ( blog_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared 1331 1339 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; 1333 1351 } -
src/wp-includes/ms-blogs.php
745 745 } 746 746 747 747 /** 748 * Sets the last changed time for the 'sites' cache group. 749 * 750 * @since 5.1.0 751 */ 752 function wp_cache_set_sites_last_changed() { 753 wp_cache_set( 'last_changed', microtime(), 'sites' ); 754 } 755 756 /** 748 757 * Updates metadata cache for list of site IDs. 749 758 * 750 759 * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache. … … 756 765 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success. 757 766 */ 758 767 function update_sitemeta_cache( $site_ids ) { 759 if ( ! is_site_meta_supported() ) {760 return false;761 }762 763 768 return update_meta_cache( 'blog', $site_ids ); 764 769 } 765 770 … … 1475 1480 * @return int|false Meta ID on success, false on failure. 1476 1481 */ 1477 1482 function 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 ); 1493 1484 } 1494 1485 1495 1486 /** … … 1508 1499 * @return bool True on success, false on failure. 1509 1500 */ 1510 1501 function 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 ); 1526 1503 } 1527 1504 1528 1505 /** … … 1538 1515 * field if $single is true. 1539 1516 */ 1540 1517 function 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 1548 1518 return get_metadata( 'blog', $site_id, $key, $single ); 1549 1519 } 1550 1520 … … 1567 1537 * false on failure. 1568 1538 */ 1569 1539 function 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 );; 1585 1541 } 1586 1542 1587 1543 /** … … 1593 1549 * @return bool Whether the site meta key was deleted from the database. 1594 1550 */ 1595 1551 function 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 ); 1611 1553 } 1612 1554 1613 1555 /** … … 2309 2251 2310 2252 update_blog_option( $site_id, 'blog_public', $public ); 2311 2253 } 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 */ 2263 function 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
53 53 add_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10, 1 ); 54 54 add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 ); 55 55 56 // Site meta 57 add_action( 'added_site_meta', 'wp_cache_set_sites_last_changed' ); 58 add_action( 'updated_site_meta', 'wp_cache_set_sites_last_changed' ); 59 add_action( 'deleted_site_meta', 'wp_cache_set_sites_last_changed' ); 60 add_action( 'populated_site_meta', 'wp_cache_set_sites_last_changed' ); 61 add_filter( 'get_site_metadata', 'wp_check_site_meta_support_prefilter' ); 62 add_filter( 'add_site_metadata', 'wp_check_site_meta_support_prefilter' ); 63 add_filter( 'update_site_metadata', 'wp_check_site_meta_support_prefilter' ); 64 add_filter( 'delete_site_metadata', 'wp_check_site_meta_support_prefilter' ); 65 add_filter( 'get_site_metadata_by_mid', 'wp_check_site_meta_support_prefilter' ); 66 add_filter( 'update_site_metadata_by_mid', 'wp_check_site_meta_support_prefilter' ); 67 add_filter( 'delete_site_metadata_by_mid', 'wp_check_site_meta_support_prefilter' ); 68 add_filter( 'update_site_metadata_cache', 'wp_check_site_meta_support_prefilter' ); 69 add_filter( 'populate_site_meta', 'wp_check_site_meta_support_prefilter' ); 70 56 71 // Register Nonce 57 72 add_action( 'signup_hidden_fields', 'signup_nonce_fields' ); 58 73