Make WordPress Core


Ignore:
Timestamp:
09/30/2016 04:09:45 AM (8 years ago)
Author:
jeremyfelt
Message:

Multisite: Ensure a consistent WP_Site return from get_site_by_path().

It is possible to short circuit get_site_by_path() using the pre_get_site_by_path filter. When this happens and a standard site object is provided, we can make sure it is upgraded to a proper WP_Site object before passing it on.

Props flixos90.
Fixes #37053.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/bootstrap.php

    r37475 r38681  
    209209    }
    210210
     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
    211224    public function filter_path_segments_to_two() {
    212225        return 2;
    213226    }
     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    }
    214237}
    215238
Note: See TracChangeset for help on using the changeset viewer.