Router - Source Excerpt 02
Summary
This source excerpt preserves a bounded section of Antichrist.net/wp-content/plugins/uaix-locale-router/src/Router.php so readers can inspect the evidence without opening the full source file.
**Source path:** Antichrist.net/wp-content/plugins/uaix-locale-router/src/Router.php
* Whether the request carried a locale prefix.
*
* @return bool
*/
public static function has_locale_prefix() {
return self::$had_locale_prefix;
}
/**
* Determine whether the current request should bypass locale routing.
*
* @return bool
*/
private static function should_skip_bootstrap() {
if ( is_admin() || wp_doing_ajax() || wp_doing_cron() ) {
return true;
}
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
return true;
}
return false;
}
/**
* Determine whether locale routing is enabled.
*
* @return bool
*/
private static function is_plugin_enabled() {
$settings = Plugin::settings();
return ! empty( $settings['enabled'] );
}
/**
* Determine whether locale-prefixed REST routes are allowed.
*
* @return bool
*/
private static function allows_prefixed_rest_routes() {
$settings = Plugin::settings();
return ! empty( $settings['enabled'] ) && 'prefixed' === $settings['rest_localization_mode'];
}
/**
* Determine whether an excluded path is an allowed prefixed REST route.
*
* @param string $path Path input.
* @return bool
*/
private static function is_prefixed_rest_path( $path ) {
if ( ! self::allows_prefixed_rest_routes() ) {
return false;
}
$segments = Path::segments( $path );
return ! empty( $segments ) && 'wp-json' === strtolower( $segments[0] );
}
/**
* Determine whether a path should bypass localization.
*
* @param string $path Path input.
* @return bool
*/
public static function is_excluded_path( $path ) {
$path = Path::normalize_path( $path );
$segments = Path::segments( $path );
$settings = Plugin::settings();
if ( '/' === $path ) {
return false;
}
if ( Path::is_static_asset_path( $path ) ) {
return true;
}
if ( self::is_exact_bare_route_exception( $path ) ) {
return true;
}
if ( ! empty( $segments ) ) {
$first = strtolower( $segments[0] );
if ( in_array( $first, array( 'wp-admin', 'wp-content', 'wp-includes', 'wp-json', 'feed', '.well-known' ), true ) ) {
return true;
}
}
if ( preg_match( '#^/(?:wp-login\.php|wp-cron\.php|xmlrpc\.php|admin-ajax\.php|favicon\.ico)$#i', $path ) ) {
return true;
}
if ( ! empty( $settings['exclusion_patterns'] ) ) {
$patterns = preg_split( '/\r\n|\r|\n/', (string) $settings['exclusion_patterns'] );
foreach ( $patterns as $pattern ) {
$pattern = trim( (string) $pattern );
if ( '' !== $pattern && false !== strpos( strtolower( $path ), strtolower( $pattern ) ) ) {
return true;
}
}
}
return false;
}
/**
* Determine whether a path is one of the exact bare-route exceptions.
*
* @param string $path Path input.
* @return bool
*/
private static function is_exact_bare_route_exception( $path ) {
$normalized = strtolower( Path::normalize_path( $path ) );
$normalized = '/' === $normalized ? '/' : untrailingslashit( $normalized );
return in_array( $normalized, self::get_bare_route_exceptions(), true );
}
}