Changeset 49538
- Timestamp:
- 11/08/2020 11:45:36 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-network-query.php
r49108 r49538 213 213 * - Otherwise the filter should return an array of WP_Network objects. 214 214 * 215 * Note that if the filter returns an array of network data, it will be assigned 216 * to the `networks` property of the current WP_Network_Query instance. 217 * 218 * Filtering functions that require pagination information are encouraged to set 219 * the `found_networks` and `max_num_pages` properties of the WP_Network_Query object, 220 * passed to the filter by reference. If WP_Network_Query does not perform a database 221 * query, it will not have enough information to generate these values itself. 222 * 215 223 * @since 5.2.0 224 * @since 5.6.0 The returned array of network data is assigned to the `networks` property 225 * of the current WP_Network_Query instance. 216 226 * 217 227 * @param array|int|null $network_data Return an array of network data to short-circuit WP's network query, … … 223 233 224 234 if ( null !== $network_data ) { 235 if ( is_array( $network_data ) && ! $this->query_vars['count'] ) { 236 $this->networks = $network_data; 237 } 238 225 239 return $network_data; 226 240 } -
trunk/src/wp-includes/class-wp-site-query.php
r49108 r49538 304 304 * - Otherwise the filter should return an array of WP_Site objects. 305 305 * 306 * Note that if the filter returns an array of site data, it will be assigned 307 * to the `sites` property of the current WP_Site_Query instance. 308 * 309 * Filtering functions that require pagination information are encouraged to set 310 * the `found_sites` and `max_num_pages` properties of the WP_Site_Query object, 311 * passed to the filter by reference. If WP_Site_Query does not perform a database 312 * query, it will not have enough information to generate these values itself. 313 * 306 314 * @since 5.2.0 315 * @since 5.6.0 The returned array of site data is assigned to the `sites` property 316 * of the current WP_Site_Query instance. 307 317 * 308 318 * @param array|int|null $site_data Return an array of site data to short-circuit WP's site query, … … 314 324 315 325 if ( null !== $site_data ) { 326 if ( is_array( $site_data ) && ! $this->query_vars['count'] ) { 327 $this->sites = $site_data; 328 } 329 316 330 return $site_data; 317 331 } -
trunk/tests/phpunit/tests/comment/query.php
r48990 r49538 4927 4927 $results = $q->query( array() ); 4928 4928 4929 remove_filter( 'comments_pre_query', array( __CLASS__, 'filter_comments_pre_query_and_set_comments' ), 10 , 2);4929 remove_filter( 'comments_pre_query', array( __CLASS__, 'filter_comments_pre_query_and_set_comments' ), 10 ); 4930 4930 4931 4931 // Make sure the comments property is the same as the results. -
trunk/tests/phpunit/tests/multisite/networkQuery.php
r48987 r49538 555 555 return array( 555 ); 556 556 } 557 558 /** 559 * @ticket 51333 560 */ 561 public function test_networks_pre_query_filter_should_set_networks_property() { 562 add_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query_and_set_networks' ), 10, 2 ); 563 564 $q = new WP_Network_Query(); 565 $results = $q->query( array() ); 566 567 remove_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query_and_set_networks' ), 10 ); 568 569 // Make sure the networks property is the same as the results. 570 $this->assertSame( $results, $q->networks ); 571 572 // Make sure the network domain is `wordpress.org`. 573 $this->assertSame( 'wordpress.org', $q->networks[0]->domain ); 574 } 575 576 public static function filter_networks_pre_query_and_set_networks( $networks, $query ) { 577 return array( get_network( self::$network_ids['wordpress.org/'] ) ); 578 } 557 579 } 558 580 -
trunk/tests/phpunit/tests/multisite/siteQuery.php
r49030 r49538 1096 1096 return array( 555 ); 1097 1097 } 1098 1099 /** 1100 * @ticket 51333 1101 */ 1102 public function test_sites_pre_query_filter_should_set_sites_property() { 1103 add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query_and_set_sites' ), 10, 2 ); 1104 1105 $q = new WP_Site_Query(); 1106 $results = $q->query( array() ); 1107 1108 remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query_and_set_sites' ), 10 ); 1109 1110 // Make sure the sites property is the same as the results. 1111 $this->assertSame( $results, $q->sites ); 1112 1113 // Make sure the site domain is `wordpress.org`. 1114 $this->assertSame( 'wordpress.org', $q->sites[0]->domain ); 1115 } 1116 1117 public static function filter_sites_pre_query_and_set_sites( $sites, $query ) { 1118 return array( get_site( self::$site_ids['wordpress.org/'] ) ); 1119 } 1098 1120 } 1099 1121
Note: See TracChangeset
for help on using the changeset viewer.