Make WordPress Core


Ignore:
Timestamp:
09/30/2016 04:09:45 AM (10 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/src/wp-includes/ms-load.php

    r38515 r38681  
    138138 *
    139139 * @since 3.9.0
     140 * @since 4.7.0 Updated to always return a `WP_Site` object.
    140141 *
    141142 * @global wpdb $wpdb WordPress database abstraction object.
     
    144145 * @param string   $path     Path to check.
    145146 * @param int|null $segments Path segments to use. Defaults to null, or the full path.
    146  * @return object|false Site object if successful. False when no site is found.
     147 * @return WP_Site|false Site object if successful. False when no site is found.
    147148 */
    148149function get_site_by_path( $domain, $path, $segments = null ) {
     
    187188     * @since 3.9.0
    188189     *
    189      * @param null|bool|object $site     Site value to return by path.
    190      * @param string           $domain   The requested domain.
    191      * @param string           $path     The requested path, in full.
    192      * @param int|null         $segments The suggested number of paths to consult.
    193      *                                   Default null, meaning the entire path was to be consulted.
    194      * @param array            $paths    The paths to search for, based on $path and $segments.
     190     * @param null|bool|WP_Site $site     Site value to return by path.
     191     * @param string            $domain   The requested domain.
     192     * @param string            $path     The requested path, in full.
     193     * @param int|null          $segments The suggested number of paths to consult.
     194     *                                    Default null, meaning the entire path was to be consulted.
     195     * @param array             $paths    The paths to search for, based on $path and $segments.
    195196     */
    196197    $pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths );
    197198    if ( null !== $pre ) {
     199        if ( false !== $pre && ! $pre instanceof WP_Site ) {
     200            $pre = new WP_Site( $pre );
     201        }
    198202        return $pre;
    199203    }
Note: See TracChangeset for help on using the changeset viewer.