function drush_site_path

8.0.x environment.inc drush_site_path($path = NULL)
6.x environment.inc drush_site_path($path = NULL)
7.x environment.inc drush_site_path($path = NULL)
3.x environment.inc drush_site_path($path = NULL)
4.x environment.inc drush_site_path($path = NULL)
5.x environment.inc drush_site_path($path = NULL)
master environment.inc drush_site_path($path = NULL)

Like Drupal conf_path, but searching from beneath. Allows proper site uri detection in site sub-directories.

Essentially looks for a settings.php file.

Parameters

string: Search starting path. Defaults to current working directory.

Return value

Current site path (folder containing settings.php) or FALSE if not found.

1 call to drush_site_path()

File

includes/environment.inc, line 833
Functions used by drush to query the environment and setting the current configuration.

Code

function drush_site_path($path = NULL) {
  static $site_path;

  if (!isset($site_path)) {
    $site_path = FALSE;

    $path = empty($path) ? drush_cwd() : $path;
    // Check the current path.
    if (file_exists($path . '/settings.php')) {
      $site_path = $path;
    }
    else {
      // Move up dir by dir and check each.
      while ($path = _drush_shift_path_up($path)) {
        if (file_exists($path . '/settings.php')) {
          $site_path = $path;
          break;
        }
      }
    }

    $site_root = drush_locate_root();
    if (file_exists($site_root . '/sites/sites.php')) {
      $sites = array();
      // This will overwrite $sites with the desired mappings.
      include ($site_root . '/sites/sites.php');
      // We do a reverse lookup here to determine the URL given the site key.
      if ($match = array_search($site_path, $sites)) {
        $site_path = $match;
      }
    }

    // Last resort: try from site root
    if (!$site_path) {
      if ($site_root) {
        if (file_exists($site_root . '/sites/default/settings.php')) {
          $site_path = $site_root . '/sites/default';
        }
      }
    }
  }

  return $site_path;
}