Skip to content

Instantly share code, notes, and snippets.

@einkoro
Last active November 11, 2022 11:01
Show Gist options
  • Save einkoro/6e12498f0f9d8ff8acb0cdcf4256b6ff to your computer and use it in GitHub Desktop.
Save einkoro/6e12498f0f9d8ff8acb0cdcf4256b6ff to your computer and use it in GitHub Desktop.
Custom WordPress Valet driver for installs that aren't in the root project directory
<?php
class CustomWordPressValetDriver extends WordPressValetDriver
{
/**
* Custom suffix for site path.
*
* @var string
*/
const sitePathSuffix = '/www';
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
return file_exists($sitePath . self::sitePathSuffix . '/wp-config.php');
}
/**
* Determine if the incoming request is for a static file.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string|false
*/
public function isStaticFile($sitePath, $siteName, $uri)
{
return parent::isStaticFile($sitePath . self::sitePathSuffix, $siteName, $uri);
}
/**
* Get the fully resolved path to the application's front controller.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string
*/
public function frontControllerPath($sitePath, $siteName, $uri)
{
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
return parent::frontControllerPath($sitePath . self::sitePathSuffix, $siteName, $uri);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment