Ticket #37053: 37053.2.diff
File 37053.2.diff, 3.2 KB (added by , 9 years ago) |
---|
-
src/wp-includes/ms-load.php
156 156 * Retrieve a site object by its domain and path. 157 157 * 158 158 * @since 3.9.0 159 * @since 4.7.0 Now always returns a `WP_Site` object. 159 160 * 160 161 * @global wpdb $wpdb WordPress database abstraction object. 161 162 * 162 163 * @param string $domain Domain to check. 163 164 * @param string $path Path to check. 164 165 * @param int|null $segments Path segments to use. Defaults to null, or the full path. 165 * @return object|false Site object if successful. False when no site is found.166 * @return WP_Site|false Site object if successful. False when no site is found. 166 167 */ 167 168 function get_site_by_path( $domain, $path, $segments = null ) { 168 169 $path_segments = array_filter( explode( '/', trim( $path, '/' ) ) ); … … 205 206 * 206 207 * @since 3.9.0 207 208 * 208 * @param null|bool| object$site Site value to return by path.209 * @param string $domain The requested domain.210 * @param string $path The requested path, in full.211 * @param int|null $segments The suggested number of paths to consult.212 * Default null, meaning the entire path was to be consulted.213 * @param array $paths The paths to search for, based on $path and $segments.209 * @param null|bool|WP_Site $site Site value to return by path. 210 * @param string $domain The requested domain. 211 * @param string $path The requested path, in full. 212 * @param int|null $segments The suggested number of paths to consult. 213 * Default null, meaning the entire path was to be consulted. 214 * @param array $paths The paths to search for, based on $path and $segments. 214 215 */ 215 216 $pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths ); 216 217 if ( null !== $pre ) { 218 if ( false !== $pre && ! $pre instanceof WP_Site ) { 219 $pre = new WP_Site( $pre ); 220 } 217 221 return $pre; 218 222 } 219 223 … … 251 255 $site = array_shift( $result ); 252 256 253 257 if ( $site ) { 254 // @todo get_blog_details()255 258 return $site; 256 259 } 257 260 -
tests/phpunit/tests/multisite/bootstrap.php
208 208 $this->assertEqualSetsWithIndex( $expected, $actual ); 209 209 } 210 210 211 /** 212 * @ticket 37053 213 */ 214 public function test_get_site_by_path_returns_wp_site() { 215 add_filter( 'pre_get_site_by_path', array( $this, 'filter_pre_get_site_by_path' ), 10, 3 ); 216 217 $site = get_site_by_path( 'example.com', '/foo/' ); 218 219 remove_filter( 'pre_get_site_by_path', array( $this, 'filter_pre_get_site_by_path' ), 10 ); 220 221 $this->assertInstanceOf( 'WP_Site', $site ); 222 } 223 211 224 public function filter_path_segments_to_two() { 212 225 return 2; 213 226 } 227 228 public function filter_pre_get_site_by_path( $site, $domain, $path ) { 229 $site = new stdClass(); 230 $site->blog_id = 100; 231 $site->domain = $domain; 232 $site->path = $path; 233 $site->site_id = 1; 234 235 return $site; 236 } 214 237 } 215 238 216 239 endif;