Filter hook 'pre_get_site_by_path'

in WP Core File wp-includes/ms-load.php at line 212

View Source

pre_get_site_by_path

Filter Hook
Description
Determines a site by its domain and path. This allows one to short-circuit the default logic, perhaps by replacing it with a routine that is more optimal for your setup. Return null to avoid the short-circuit. Return false if no site can be found at the requested domain and path. Otherwise, return a site object.

Hook Information

File Location wp-includes/ms-load.php View on GitHub
Hook Type Filter
Line Number 212

Hook Parameters

Type Name Description
null|false|WP_Site $site Site value to return by path. Default null to continue retrieving the site.
string $domain The requested domain.
string $path The requested path, in full.
int|null $segments The suggested number of paths to consult. Default null, meaning the entire path was to be consulted.
string[] $paths The paths to search for, based on $path and $segments.

Usage Examples

Basic Usage
<?php
// Hook into pre_get_site_by_path
add_filter('pre_get_site_by_path', 'my_custom_filter', 10, 5);

function my_custom_filter($site, $domain, $path, $segments, $paths) {
    // Your custom filtering logic here
    return $site;
}

Source Code Context

wp-includes/ms-load.php:212 - How this hook is used in WordPress core
<?php
 207  	 * @param string             $path     The requested path, in full.
 208  	 * @param int|null           $segments The suggested number of paths to consult.
 209  	 *                                     Default null, meaning the entire path was to be consulted.
 210  	 * @param string[]           $paths    The paths to search for, based on $path and $segments.
 211  	 */
 212  	$pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths );
 213  	if ( null !== $pre ) {
 214  		if ( false !== $pre && ! $pre instanceof WP_Site ) {
 215  			$pre = new WP_Site( $pre );
 216  		}
 217  		return $pre;

PHP Documentation

<?php
/**
	 * Determines a site by its domain and path.
	 *
	 * This allows one to short-circuit the default logic, perhaps by
	 * replacing it with a routine that is more optimal for your setup.
	 *
	 * Return null to avoid the short-circuit. Return false if no site
	 * can be found at the requested domain and path. Otherwise, return
	 * a site object.
	 *
	 * @since 3.9.0
	 *
	 * @param null|false|WP_Site $site     Site value to return by path. Default null
	 *                                     to continue retrieving the site.
	 * @param string             $domain   The requested domain.
	 * @param string             $path     The requested path, in full.
	 * @param int|null           $segments The suggested number of paths to consult.
	 *                                     Default null, meaning the entire path was to be consulted.
	 * @param string[]           $paths    The paths to search for, based on $path and $segments.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 5
  • File: wp-includes/ms-load.php
Related Hooks

Related hooks will be displayed here in future updates.