Make WordPress Core

Ticket #37053: 37053.2.diff

File 37053.2.diff, 3.2 KB (added by flixos90, 9 years ago)
  • src/wp-includes/ms-load.php

     
    156156 * Retrieve a site object by its domain and path.
    157157 *
    158158 * @since 3.9.0
     159 * @since 4.7.0 Now always returns a `WP_Site` object.
    159160 *
    160161 * @global wpdb $wpdb WordPress database abstraction object.
    161162 *
    162163 * @param string   $domain   Domain to check.
    163164 * @param string   $path     Path to check.
    164165 * @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.
    166167 */
    167168function get_site_by_path( $domain, $path, $segments = null ) {
    168169        $path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );
     
    205206         *
    206207         * @since 3.9.0
    207208         *
    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.
    214215         */
    215216        $pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths );
    216217        if ( null !== $pre ) {
     218                if ( false !== $pre && ! $pre instanceof WP_Site ) {
     219                        $pre = new WP_Site( $pre );
     220                }
    217221                return $pre;
    218222        }
    219223
     
    251255        $site = array_shift( $result );
    252256
    253257        if ( $site ) {
    254                 // @todo get_blog_details()
    255258                return $site;
    256259        }
    257260
  • tests/phpunit/tests/multisite/bootstrap.php

     
    208208                $this->assertEqualSetsWithIndex( $expected, $actual );
    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
    216239endif;