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. Drush uses this function to find a usable site based on the user's current working directory.

Parameters

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

Return value

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

2 calls to drush_site_path()
drush_complete_cache_cid in includes/complete.inc
Generate a cache id.
_drush_bootstrap_selected_uri in includes/bootstrap.inc
Find the URI that has been selected by the cwd if it was not previously set via the --uri / -l option

File

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

Code

function drush_site_path($path = NULL) {
  $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.
    // Stop if we get to a Drupal root.   We don't care
    // if it is DRUSH_SELECTED_DRUPAL_ROOT or some other root.
    while (($path = _drush_shift_path_up($path)) && !drush_valid_root($path)) {
      if (file_exists($path . '/settings.php')) {
        $site_path = $path;
        break;
      }
    }
  }

  $site_root = drush_get_context('DRUSH_SELECTED_DRUPAL_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;
}