Changeset 54637
- Timestamp:
- 10/18/2022 06:14:01 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-network-query.php
r54133 r54637 87 87 * 88 88 * @since 4.6.0 89 * @since 6.1.0 Introduced the 'update_network_meta_cache' parameter.90 89 * 91 90 * @param string|array $query { 92 91 * Optional. Array or query string of network query parameters. Default empty. 93 92 * 94 * @type int[] $network__in Array of network IDs to include. Default empty. 95 * @type int[] $network__not_in Array of network IDs to exclude. Default empty. 96 * @type bool $count Whether to return a network count (true) or array of network objects. 97 * Default false. 98 * @type string $fields Network fields to return. Accepts 'ids' (returns an array of network IDs) 99 * or empty (returns an array of complete network objects). Default empty. 100 * @type int $number Maximum number of networks to retrieve. Default empty (no limit). 101 * @type int $offset Number of networks to offset the query. Used to build LIMIT clause. 102 * Default 0. 103 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. 104 * @type string|array $orderby Network status or array of statuses. Accepts 'id', 'domain', 'path', 105 * 'domain_length', 'path_length' and 'network__in'. Also accepts false, 106 * an empty array, or 'none' to disable `ORDER BY` clause. Default 'id'. 107 * @type string $order How to order retrieved networks. Accepts 'ASC', 'DESC'. Default 'ASC'. 108 * @type string $domain Limit results to those affiliated with a given domain. Default empty. 109 * @type string[] $domain__in Array of domains to include affiliated networks for. Default empty. 110 * @type string[] $domain__not_in Array of domains to exclude affiliated networks for. Default empty. 111 * @type string $path Limit results to those affiliated with a given path. Default empty. 112 * @type string[] $path__in Array of paths to include affiliated networks for. Default empty. 113 * @type string[] $path__not_in Array of paths to exclude affiliated networks for. Default empty. 114 * @type string $search Search term(s) to retrieve matching networks for. Default empty. 115 * @type bool $update_network_cache Whether to prime the cache for found networks. Default true. 116 * @type bool $update_network_meta_cache Whether to prime the metadata (option) cache for found networks. 117 * Default true. 93 * @type int[] $network__in Array of network IDs to include. Default empty. 94 * @type int[] $network__not_in Array of network IDs to exclude. Default empty. 95 * @type bool $count Whether to return a network count (true) or array of network objects. 96 * Default false. 97 * @type string $fields Network fields to return. Accepts 'ids' (returns an array of network IDs) 98 * or empty (returns an array of complete network objects). Default empty. 99 * @type int $number Maximum number of networks to retrieve. Default empty (no limit). 100 * @type int $offset Number of networks to offset the query. Used to build LIMIT clause. 101 * Default 0. 102 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. 103 * @type string|array $orderby Network status or array of statuses. Accepts 'id', 'domain', 'path', 104 * 'domain_length', 'path_length' and 'network__in'. Also accepts false, 105 * an empty array, or 'none' to disable `ORDER BY` clause. Default 'id'. 106 * @type string $order How to order retrieved networks. Accepts 'ASC', 'DESC'. Default 'ASC'. 107 * @type string $domain Limit results to those affiliated with a given domain. Default empty. 108 * @type string[] $domain__in Array of domains to include affiliated networks for. Default empty. 109 * @type string[] $domain__not_in Array of domains to exclude affiliated networks for. Default empty. 110 * @type string $path Limit results to those affiliated with a given path. Default empty. 111 * @type string[] $path__in Array of paths to include affiliated networks for. Default empty. 112 * @type string[] $path__not_in Array of paths to exclude affiliated networks for. Default empty. 113 * @type string $search Search term(s) to retrieve matching networks for. Default empty. 114 * @type bool $update_network_cache Whether to prime the cache for found networks. Default true. 118 115 * } 119 116 */ 120 117 public function __construct( $query = '' ) { 121 118 $this->query_var_defaults = array( 122 'network__in' => '', 123 'network__not_in' => '', 124 'count' => false, 125 'fields' => '', 126 'number' => '', 127 'offset' => '', 128 'no_found_rows' => true, 129 'orderby' => 'id', 130 'order' => 'ASC', 131 'domain' => '', 132 'domain__in' => '', 133 'domain__not_in' => '', 134 'path' => '', 135 'path__in' => '', 136 'path__not_in' => '', 137 'search' => '', 138 'update_network_cache' => true, 139 'update_network_meta_cache' => true, 119 'network__in' => '', 120 'network__not_in' => '', 121 'count' => false, 122 'fields' => '', 123 'number' => '', 124 'offset' => '', 125 'no_found_rows' => true, 126 'orderby' => 'id', 127 'order' => 'ASC', 128 'domain' => '', 129 'domain__in' => '', 130 'domain__not_in' => '', 131 'path' => '', 132 'path__in' => '', 133 'path__not_in' => '', 134 'search' => '', 135 'update_network_cache' => true, 140 136 ); 141 137 … … 248 244 $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); 249 245 250 // Ignore the se arguments,as the queried result will be the same regardless.251 unset( $_args['fields'], $_args['update_network_cache'] , $_args['update_network_meta_cache']);246 // Ignore the $fields, $update_network_cache arguments as the queried result will be the same regardless. 247 unset( $_args['fields'], $_args['update_network_cache'] ); 252 248 253 249 $key = md5( serialize( $_args ) ); … … 291 287 292 288 if ( $this->query_vars['update_network_cache'] ) { 293 _prime_network_caches( $network_ids , $this->query_vars['update_network_meta_cache']);289 _prime_network_caches( $network_ids ); 294 290 } 295 291 -
trunk/src/wp-includes/class-wp-site-query.php
r54133 r54637 352 352 $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); 353 353 354 // Ignore the se arguments,as the queried result will be the same regardless.354 // Ignore the $fields, $update_site_cache, $update_site_meta_cache argument as the queried result will be the same regardless. 355 355 unset( $_args['fields'], $_args['update_site_cache'], $_args['update_site_meta_cache'] ); 356 356 -
trunk/src/wp-includes/load.php
r54447 r54637 744 744 'site-options', 745 745 'site-transient', 746 'site_meta',747 746 'rss', 748 747 'users', -
trunk/src/wp-includes/ms-blogs.php
r54080 r54637 565 565 'site-options', 566 566 'site-transient', 567 'site_meta',568 567 'rss', 569 568 'users', … … 657 656 'site-options', 658 657 'site-transient', 659 'site_meta',660 658 'rss', 661 659 'users', -
trunk/src/wp-includes/ms-functions.php
r54482 r54637 114 114 */ 115 115 function get_blog_count( $network_id = null ) { 116 return (int)get_network_option( $network_id, 'blog_count' );116 return get_network_option( $network_id, 'blog_count' ); 117 117 } 118 118 … … 2564 2564 * @param int $space_allowed Upload quota in megabytes for the current blog. 2565 2565 */ 2566 return (int)apply_filters( 'get_space_allowed', $space_allowed );2566 return apply_filters( 'get_space_allowed', $space_allowed ); 2567 2567 } 2568 2568 -
trunk/src/wp-includes/ms-network.php
r54080 r54637 85 85 $network_ids = (array) $ids; 86 86 wp_cache_delete_multiple( $network_ids, 'networks' ); 87 wp_cache_delete_multiple( $network_ids, 'site_meta' );88 87 89 88 foreach ( $network_ids as $id ) { … … 109 108 * 110 109 * @since 4.6.0 111 * @since 6.1.0 Introduced the `$update_meta_cache` parameter.112 110 * 113 * @param array $networks Array of network row objects. 114 * @param bool $update_meta_cache Whether to update site meta cache. Default true. 111 * @param array $networks Array of network row objects. 115 112 */ 116 function update_network_cache( $networks , $update_meta_cache = true) {113 function update_network_cache( $networks ) { 117 114 $data = array(); 118 115 foreach ( (array) $networks as $network ) { 119 116 $data[ $network->id ] = $network; 120 117 } 121 122 118 wp_cache_add_multiple( $data, 'networks' ); 123 if ( $update_meta_cache ) {124 $network_ids = array_keys( $data );125 update_meta_cache( 'site', $network_ids );126 }127 119 } 128 120 … … 131 123 * 132 124 * @since 4.6.0 133 * @since 6.1.0 Introduced the `$update_meta_cache` parameter.134 125 * @since 6.1.0 This function is no longer marked as "private". 135 126 * … … 137 128 * @global wpdb $wpdb WordPress database abstraction object. 138 129 * 139 * @param array $network_ids Array of network IDs. 140 * @param bool $update_meta_cache Whether to update site meta cache. Default true. 130 * @param array $network_ids Array of network IDs. 141 131 */ 142 function _prime_network_caches( $network_ids , $update_meta_cache = true) {132 function _prime_network_caches( $network_ids ) { 143 133 global $wpdb; 144 134 … … 147 137 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared 148 138 149 update_network_cache( $fresh_networks , $update_meta_cache);139 update_network_cache( $fresh_networks ); 150 140 } 151 141 } -
trunk/src/wp-includes/option.php
r54345 r54637 349 349 * 350 350 * @since 3.0.0 351 * @since 6.1.0 Now uses update_meta_cache(). 351 * 352 * @global wpdb $wpdb WordPress database abstraction object. 352 353 * 353 354 * @param int $network_id Optional site ID for which to query the options. Defaults to the current site. 354 355 */ 355 356 function wp_load_core_site_options( $network_id = null ) { 356 if ( ! is_multisite() || wp_installing() ) { 357 global $wpdb; 358 359 if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) { 357 360 return; 358 361 } … … 362 365 } 363 366 364 update_meta_cache( 'site', $network_id ); 367 $core_options = array( 'site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' ); 368 369 $core_options_in = "'" . implode( "', '", $core_options ) . "'"; 370 $options = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $network_id ) ); 371 372 $data = array(); 373 foreach ( $options as $option ) { 374 $key = $option->meta_key; 375 $cache_key = "{$network_id}:$key"; 376 $option->meta_value = maybe_unserialize( $option->meta_value ); 377 378 $data[ $cache_key ] = $option->meta_value; 379 } 380 wp_cache_set_multiple( $data, 'site-options' ); 365 381 } 366 382 … … 1371 1387 * 1372 1388 * @since 4.4.0 1373 * @since 6.1.0 Now uses get_metadata().1374 1389 * 1375 1390 * @see get_option() 1376 * @see get_metadata() 1391 * 1392 * @global wpdb $wpdb WordPress database abstraction object. 1377 1393 * 1378 1394 * @param int $network_id ID of the network. Can be null to default to the current network ID. … … 1382 1398 */ 1383 1399 function get_network_option( $network_id, $option, $default = false ) { 1400 global $wpdb; 1401 1384 1402 if ( $network_id && ! is_numeric( $network_id ) ) { 1385 1403 return false; … … 1422 1440 } 1423 1441 1424 if ( ! is_multisite() ) { 1442 // Prevent non-existent options from triggering multiple queries. 1443 $notoptions_key = "$network_id:notoptions"; 1444 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1445 1446 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1447 1425 1448 /** 1426 1449 * Filters the value of a specific default network option. … … 1437 1460 * @param int $network_id ID of the network. 1438 1461 */ 1439 $default = apply_filters( "default_site_option_{$option}", $default, $option, $network_id ); 1462 return apply_filters( "default_site_option_{$option}", $default, $option, $network_id ); 1463 } 1464 1465 if ( ! is_multisite() ) { 1466 /** This filter is documented in wp-includes/option.php */ 1467 $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1440 1468 $value = get_option( $option, $default ); 1441 1469 } else { 1442 $meta = get_metadata_raw( 'site', $network_id, $option ); 1443 if ( is_array( $meta ) && ! empty( $meta ) ) { 1444 $value = array_shift( $meta ); 1445 } else { 1446 /** This filter is documented in wp-includes/option.php */ 1447 $value = apply_filters( "default_site_option_{$option}", $default, $option, $network_id ); 1448 1449 /** This action is documented in wp-includes/meta.php */ 1450 $value = apply_filters( 'default_site_metadata', $value, $network_id, $option, true, 'site' ); 1451 } 1470 $cache_key = "$network_id:$option"; 1471 $value = wp_cache_get( $cache_key, 'site-options' ); 1472 1473 if ( ! isset( $value ) || false === $value ) { 1474 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1475 1476 // Has to be get_row() instead of get_var() because of funkiness with 0, false, null values. 1477 if ( is_object( $row ) ) { 1478 $value = $row->meta_value; 1479 $value = maybe_unserialize( $value ); 1480 wp_cache_set( $cache_key, $value, 'site-options' ); 1481 } else { 1482 if ( ! is_array( $notoptions ) ) { 1483 $notoptions = array(); 1484 } 1485 1486 $notoptions[ $option ] = true; 1487 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1488 1489 /** This filter is documented in wp-includes/option.php */ 1490 $value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); 1491 } 1492 } 1493 } 1494 1495 if ( ! is_array( $notoptions ) ) { 1496 $notoptions = array(); 1497 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1452 1498 } 1453 1499 … … 1475 1521 * 1476 1522 * @since 4.4.0 1477 * @since 6.1.0 Now uses add_metadata().1478 1523 * 1479 1524 * @see add_option() 1480 * @see add_metadata() 1525 * 1526 * @global wpdb $wpdb WordPress database abstraction object. 1481 1527 * 1482 1528 * @param int $network_id ID of the network. Can be null to default to the current network ID. … … 1486 1532 */ 1487 1533 function add_network_option( $network_id, $option, $value ) { 1534 global $wpdb; 1535 1488 1536 if ( $network_id && ! is_numeric( $network_id ) ) { 1489 1537 return false; … … 1515 1563 $value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id ); 1516 1564 1565 $notoptions_key = "$network_id:notoptions"; 1566 1517 1567 if ( ! is_multisite() ) { 1518 1568 $result = add_option( $option, $value, '', 'no' ); 1519 1569 } else { 1520 $value = sanitize_option( $option, $value ); 1521 $result = add_metadata( 'site', $network_id, wp_slash( $option ), wp_slash( $value ), true ); 1570 $cache_key = "$network_id:$option"; 1571 1572 // Make sure the option doesn't already exist. 1573 // We can check the 'notoptions' cache before we ask for a DB query. 1574 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1575 1576 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 1577 if ( false !== get_network_option( $network_id, $option, false ) ) { 1578 return false; 1579 } 1580 } 1581 1582 $value = sanitize_option( $option, $value ); 1583 1584 $serialized_value = maybe_serialize( $value ); 1585 $result = $wpdb->insert( 1586 $wpdb->sitemeta, 1587 array( 1588 'site_id' => $network_id, 1589 'meta_key' => $option, 1590 'meta_value' => $serialized_value, 1591 ) 1592 ); 1593 1594 if ( ! $result ) { 1595 return false; 1596 } 1597 1598 wp_cache_set( $cache_key, $value, 'site-options' ); 1599 1600 // This option exists now. 1601 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // Yes, again... we need it to be fresh. 1602 1603 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1604 unset( $notoptions[ $option ] ); 1605 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1606 } 1522 1607 } 1523 1608 … … 1561 1646 * 1562 1647 * @since 4.4.0 1563 * @since 6.1.0 Now uses delete_metadata().1564 1648 * 1565 1649 * @see delete_option() 1566 * @see delete_metadata()1567 1650 * 1568 1651 * @global wpdb $wpdb WordPress database abstraction object. … … 1573 1656 */ 1574 1657 function delete_network_option( $network_id, $option ) { 1658 global $wpdb; 1659 1575 1660 if ( $network_id && ! is_numeric( $network_id ) ) { 1576 1661 return false; … … 1601 1686 $result = delete_option( $option ); 1602 1687 } else { 1603 $result = delete_metadata( 'site', $network_id, wp_slash( $option ), '' ); 1688 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1689 if ( is_null( $row ) || ! $row->meta_id ) { 1690 return false; 1691 } 1692 $cache_key = "$network_id:$option"; 1693 wp_cache_delete( $cache_key, 'site-options' ); 1694 1695 $result = $wpdb->delete( 1696 $wpdb->sitemeta, 1697 array( 1698 'meta_key' => $option, 1699 'site_id' => $network_id, 1700 ) 1701 ); 1604 1702 } 1605 1703 … … 1641 1739 * 1642 1740 * @since 4.4.0 1643 * @since 6.1.0 Now uses update_metadata().1644 1741 * 1645 1742 * @see update_option() 1646 * @see update_metadata() 1743 * 1744 * @global wpdb $wpdb WordPress database abstraction object. 1647 1745 * 1648 1746 * @param int $network_id ID of the network. Can be null to default to the current network ID. … … 1652 1750 */ 1653 1751 function update_network_option( $network_id, $option, $value ) { 1752 global $wpdb; 1753 1654 1754 if ( $network_id && ! is_numeric( $network_id ) ) { 1655 1755 return false; … … 1701 1801 } 1702 1802 1803 $notoptions_key = "$network_id:notoptions"; 1804 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1805 1806 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1807 unset( $notoptions[ $option ] ); 1808 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1809 } 1810 1703 1811 if ( ! is_multisite() ) { 1704 1812 $result = update_option( $option, $value, 'no' ); 1705 1813 } else { 1706 $value = sanitize_option( $option, $value ); 1707 $result = update_metadata( 'site', $network_id, wp_slash( $option ), wp_slash( $value ) ); 1814 $value = sanitize_option( $option, $value ); 1815 1816 $serialized_value = maybe_serialize( $value ); 1817 $result = $wpdb->update( 1818 $wpdb->sitemeta, 1819 array( 'meta_value' => $serialized_value ), 1820 array( 1821 'site_id' => $network_id, 1822 'meta_key' => $option, 1823 ) 1824 ); 1825 1826 if ( $result ) { 1827 $cache_key = "$network_id:$option"; 1828 wp_cache_set( $cache_key, $value, 'site-options' ); 1829 } 1708 1830 } 1709 1831 -
trunk/tests/phpunit/tests/ajax/Compression.php
r54080 r54637 155 155 156 156 // Check the site option is not changed due to lack of nonce. 157 $this->assertSame( 0, (int)get_site_option( 'can_compress_scripts' ) );157 $this->assertSame( 0, get_site_option( 'can_compress_scripts' ) ); 158 158 159 159 // Add a nonce. … … 168 168 169 169 // Check the site option is changed. 170 $this->assertSame( 1, (int)get_site_option( 'can_compress_scripts' ) );170 $this->assertSame( 1, get_site_option( 'can_compress_scripts' ) ); 171 171 } 172 172 … … 195 195 196 196 // Check the site option is not changed due to lack of nonce. 197 $this->assertSame( 1, (int)get_site_option( 'can_compress_scripts' ) );197 $this->assertSame( 1, get_site_option( 'can_compress_scripts' ) ); 198 198 199 199 // Add a nonce. … … 208 208 209 209 // Check the site option is changed. 210 $this->assertSame( 0, (int)get_site_option( 'can_compress_scripts' ) );210 $this->assertSame( 0, get_site_option( 'can_compress_scripts' ) ); 211 211 } 212 212 -
trunk/tests/phpunit/tests/multisite/network.php
r54482 r54637 172 172 wp_update_network_counts(); 173 173 174 $this->assert Same( $site_count_start, $actual );174 $this->assertEquals( $site_count_start, $actual ); 175 175 } 176 176 … … 203 203 $site_count = get_blog_count( self::$different_network_id ); 204 204 205 $this->assert Same( count( self::$different_site_ids ), $site_count );205 $this->assertEquals( count( self::$different_site_ids ), $site_count ); 206 206 } 207 207 -
trunk/tests/phpunit/tests/option/multisite.php
r54080 r54637 151 151 $this->assertFalse( get_blog_option( $blog_id, $key2 ) ); 152 152 // $this->assertFalse( get_option( $key2 ) ); // Check get_option(). 153 } 154 155 /** 156 * @group multisite 157 * 158 * @covers ::get_site_option 159 */ 160 public function test_site_notoptions() { 161 $network_id = get_current_network_id(); 162 $notoptions_key = "{$network_id}:notoptions"; 163 164 $_notoptions = wp_cache_get( 'notoptions', 'site-options' ); 165 $this->assertEmpty( $_notoptions ); 166 $_notoptions1 = wp_cache_get( $notoptions_key, 'site-options' ); 167 $this->assertEmpty( $_notoptions1 ); 168 169 get_site_option( 'burrito' ); 170 171 $notoptions = wp_cache_get( 'notoptions', 'site-options' ); 172 $this->assertEmpty( $notoptions ); 173 $notoptions1 = wp_cache_get( $notoptions_key, 'site-options' ); 174 $this->assertNotEmpty( $notoptions1 ); 153 175 } 154 176 -
trunk/tests/phpunit/tests/option/networkOption.php
r54402 r54637 138 138 139 139 /** 140 * @ticket 37181 141 * 140 * @ticket 43506 142 141 * @group ms-required 143 142 * … … 146 145 * @covers ::wp_cache_delete 147 146 */ 148 public function test_meta_api_use_values_in_network_option() { 149 $network_id = self::factory()->network->create(); 150 $option = __FUNCTION__; 151 $value = __FUNCTION__; 152 153 add_metadata( 'site', $network_id, $option, $value, true ); 154 $this->assertEqualSets( get_metadata( 'site', $network_id, $option ), array( get_network_option( $network_id, $option, true ) ) ); 155 } 156 157 /** 158 * @ticket 37181 159 * 160 * @group ms-required 161 */ 162 function test_funky_network_meta() { 163 $network_id = self::factory()->network->create(); 164 $option = __FUNCTION__; 165 $classy = new StdClass(); 166 $classy->ID = 1; 167 $classy->stringy = 'I love slashes\\\\'; 168 $funky_meta[] = $classy; 169 170 $classy = new StdClass(); 171 $classy->ID = 2; 172 $classy->stringy = 'I love slashes\\\\ more'; 173 $funky_meta[] = $classy; 174 175 // Add a network meta item. 176 $this->assertIsInt( add_metadata( 'site', $network_id, $option, $funky_meta, true ) ); 177 178 // Check they exists. 179 $this->assertEqualSets( $funky_meta, get_network_option( $network_id, $option ) ); 180 } 181 182 /** 183 * @ticket 37181 184 * 185 * @group ms-required 186 */ 187 public function test_meta_api_multiple_values_in_network_option() { 188 $network_id = self::factory()->network->create(); 189 $option = __FUNCTION__; 190 add_metadata( 'site', $network_id, $option, 'monday', true ); 191 add_metadata( 'site', $network_id, $option, 'tuesday', true ); 192 add_metadata( 'site', $network_id, $option, 'wednesday', true ); 193 $this->assertSame( 'monday', get_network_option( $network_id, $option, true ) ); 194 } 195 196 /** 197 * @ticket 37181 198 * 147 public function test_get_network_option_sets_notoptions_if_option_found() { 148 $network_id = get_current_network_id(); 149 $notoptions_key = "$network_id:notoptions"; 150 151 $original_cache = wp_cache_get( $notoptions_key, 'site-options' ); 152 if ( false !== $original_cache ) { 153 wp_cache_delete( $notoptions_key, 'site-options' ); 154 } 155 156 // Retrieve any existing option. 157 get_network_option( $network_id, 'site_name' ); 158 159 $cache = wp_cache_get( $notoptions_key, 'site-options' ); 160 if ( false !== $original_cache ) { 161 wp_cache_set( $notoptions_key, $original_cache, 'site-options' ); 162 } 163 164 $this->assertSame( array(), $cache ); 165 } 166 167 /** 168 * @ticket 43506 199 169 * @group ms-required 200 170 * … … 202 172 * @covers ::wp_cache_get 203 173 */ 204 public function test_network_option_count_queries_on_non_existing() { 205 $network_id = self::factory()->network->create(); 206 $option = __FUNCTION__; 207 add_network_option( $network_id, $option, 'monday' ); 208 get_network_option( $network_id, $option ); 209 $num_queries_pre_get = get_num_queries(); 210 get_network_option( $network_id, 'do_not_exist' ); 211 $num_queries_after_get = get_num_queries(); 212 213 $this->assertSame( $num_queries_pre_get, $num_queries_after_get ); 214 } 215 216 /** 217 * @ticket 37181 218 * 219 * @group ms-required 220 */ 221 public function test_register_meta_network_option_single_false() { 222 $network_id = self::factory()->network->create(); 223 $option = __FUNCTION__; 224 $value = __FUNCTION__; 225 register_meta( 226 'site', 227 $option, 228 array( 229 'type' => 'string', 230 'default' => $value, 231 'single' => false, 232 ) 233 ); 234 235 $this->assertSame( $value, get_network_option( $network_id, $option ) ); 236 } 237 238 /** 239 * @ticket 37181 240 * 241 * @group ms-required 242 */ 243 public function test_register_meta_network_option_single_true() { 244 $network_id = self::factory()->network->create(); 245 $option = __FUNCTION__; 246 $value = __FUNCTION__; 247 register_meta( 248 'site', 249 $option, 250 array( 251 'type' => 'string', 252 'default' => $value, 253 'single' => true, 254 ) 255 ); 256 257 $this->assertSame( $value, get_network_option( $network_id, $option ) ); 174 public function test_get_network_option_sets_notoptions_if_option_not_found() { 175 $network_id = get_current_network_id(); 176 $notoptions_key = "$network_id:notoptions"; 177 178 $original_cache = wp_cache_get( $notoptions_key, 'site-options' ); 179 if ( false !== $original_cache ) { 180 wp_cache_delete( $notoptions_key, 'site-options' ); 181 } 182 183 // Retrieve any non-existing option. 184 get_network_option( $network_id, 'this_does_not_exist' ); 185 186 $cache = wp_cache_get( $notoptions_key, 'site-options' ); 187 if ( false !== $original_cache ) { 188 wp_cache_set( $notoptions_key, $original_cache, 'site-options' ); 189 } 190 191 $this->assertSame( array( 'this_does_not_exist' => true ), $cache ); 258 192 } 259 193 … … 263 197 * @ticket 44956 264 198 * 265 * @group ms-required266 *267 199 * @covers ::update_network_option 268 200 */ 269 201 public function test_update_network_option_array_with_object() { 270 $network_id = self::factory()->network->create();271 $option = __FUNCTION__;272 202 $array_w_object = array( 273 203 'url' => 'http://src.wordpress-develop.dev/wp-content/uploads/2016/10/cropped-Blurry-Lights.jpg', … … 279 209 ); 280 210 281 add_metadata( 'site', $network_id, $option, $array_w_object, true ); 282 $this->assertEqualSets( $array_w_object, get_network_option( $network_id, $option ) ); 283 } 284 285 /** 286 * @ticket 37181 287 * 288 * @group ms-required 289 * 290 * @covers ::add_network_option 291 * 292 * @dataProvider data_types_options 293 */ 294 public function test_type_add_network_option( $name, $value, $expected ) { 295 $result = add_network_option( null, $name, $value ); 296 $this->assertTrue( $result, 'Network option was not added' ); 297 298 $test_value = get_network_option( null, $name ); 299 $this->assertSame( $expected, $test_value, 'Values do not match' ); 300 } 301 302 /** 303 * @ticket 37181 304 * 305 * @covers ::add_network_option 306 * 307 * @dataProvider data_slashed_options 308 */ 309 public function test_slash_add_network_option( $name, $value ) { 310 $result = add_network_option( null, $name, $value ); 311 $this->assertTrue( $result, 'Network option was not added' ); 312 $this->assertSame( $value, get_network_option( null, $name ), 'Values do not match' ); 313 } 314 315 /** 316 * @ticket 37181 317 * 318 * @covers ::update_network_option 319 * 320 * @dataProvider data_slashed_options 321 */ 322 public function test_slash_update_network_option( $name, $value ) { 323 $result = update_network_option( null, $name, $value ); 324 $this->assertTrue( $result, 'Network option was not updated' ); 325 $this->assertSame( $value, get_network_option( null, $name ), 'Values do not match' ); 326 } 327 328 /** 329 * @ticket 37181 330 * 331 * @covers ::delete_network_option() 332 * 333 * @dataProvider data_slashed_options 334 */ 335 public function test_slash_delete_network_option( $name, $value ) { 336 $result = add_network_option( null, $name, $value ); 337 $this->assertTrue( $result, 'Network option was not added' ); 338 $this->assertSame( $value, get_network_option( null, $name ) ); 339 $result = delete_network_option( null, $name ); 340 $this->assertTrue( $result, 'Network option was not deleted' ); 341 $this->assertFalse( get_network_option( null, $name ), 'Network option was not deleted' ); 342 } 343 344 public function data_slashed_options() { 345 return array( 346 'slashed option name' => array( 347 'option' => 'String with 1 slash \\', 348 'value' => 'foo', 349 ), 350 'slashed in middle option name' => array( 351 'option' => 'String\\thing', 352 'value' => 'foo', 353 ), 354 'slashed option value' => array( 355 'option' => 'bar', 356 'value' => 'String with 1 slash \\', 357 ), 358 'slashed option name and value' => array( 359 'option' => 'String with 1 slash \\', 360 'value' => 'String with 1 slash \\', 361 ), 362 'slashed 4 times option name and value' => array( 363 'option' => 'String with 4 slashes \\\\\\\\', 364 'value' => 'String with 4 slashes \\\\\\\\', 365 ), 366 'slashed 7 times option name and value' => array( 367 'option' => 'String with 7 slashes \\\\\\\\\\\\\\', 368 'value' => 'String with 7 slashes \\\\\\\\\\\\\\', 211 $array_w_object_2 = array( 212 'url' => 'http://src.wordpress-develop.dev/wp-content/uploads/2016/10/cropped-Blurry-Lights.jpg', 213 'meta_data' => (object) array( 214 'attachment_id' => 292, 215 'height' => 708, 216 'width' => 1260, 369 217 ), 370 218 ); 371 } 372 373 public function data_types_options() { 374 return array( 375 'array' => array( 376 'option' => 'array', 377 'value' => array(), 378 'expected' => array(), 379 ), 380 'array_keys' => array( 381 'option' => 'array', 382 'value' => array( 'key' => 'value' ), 383 'expected' => array( 'key' => 'value' ), 384 ), 385 'int' => array( 386 'option' => 'int', 387 'value' => 33, 388 'expected' => '33', 389 ), 390 'string' => array( 391 'option' => 'string', 392 'value' => 'foo', 393 'expected' => 'foo', 394 ), 395 'string_bool' => array( 396 'option' => 'string', 397 'value' => 'true', 398 'expected' => 'true', 399 ), 400 'float' => array( 401 'option' => 'float', 402 'value' => 33.5555, 403 'expected' => '33.5555', 404 ), 405 'bool' => array( 406 'option' => 'bool', 407 'value' => true, 408 'expected' => '1', 409 ), 410 'null' => array( 411 'option' => 'null', 412 'value' => null, 413 'expected' => null, 414 ), 415 ); 219 220 // Add the option, it did not exist before this. 221 add_network_option( null, 'array_w_object', $array_w_object ); 222 223 $num_queries_pre_update = get_num_queries(); 224 225 // Update the option using the same array with an object for the value. 226 $this->assertFalse( update_network_option( null, 'array_w_object', $array_w_object_2 ) ); 227 228 // Check that no new database queries were performed. 229 $this->assertSame( $num_queries_pre_update, get_num_queries() ); 416 230 } 417 231 }
Note: See TracChangeset
for help on using the changeset viewer.