function drupal_valid_path

7.x path.inc drupal_valid_path($path, $dynamic_allowed = FALSE)

Checks a path exists and the current user has access to it.

Parameters

$path: The path to check.

$dynamic_allowed: Whether paths with menu wildcards (like user/%) should be allowed.

Return value

TRUE if it is a valid path AND the current user has access permission, FALSE otherwise.

4 calls to drupal_valid_path()
menu_edit_item_validate in drupal-7.x/modules/menu/menu.admin.inc
Validate form values for a menu link being added or edited.
path_admin_form_validate in drupal-7.x/modules/path/path.admin.inc
Form validation handler for path_admin_form().
system_site_information_settings_validate in drupal-7.x/modules/system/system.admin.inc
Validates the submitted site-information form.
theme_textfield in drupal-7.x/includes/form.inc
Returns HTML for a textfield form element.

File

drupal-7.x/includes/path.inc, line 553
Functions to handle paths in Drupal, including path aliasing.

Code

function drupal_valid_path($path, $dynamic_allowed = FALSE) {
  global $menu_admin;
  // We indicate that a menu administrator is running the menu access check.
  $menu_admin = TRUE;
  if ($path == '<front>' || url_is_external($path)) {
    $item = array('access' => TRUE);
  }
  elseif ($dynamic_allowed && preg_match('/\/\%/', $path)) {
    // Path is dynamic (ie 'user/%'), so check directly against menu_router table.
    if ($item = db_query("SELECT * FROM {menu_router} where path = :path", array(':path' => $path))->fetchAssoc()) {
      $item['link_path'] = $form_item['link_path'];
      $item['link_title'] = $form_item['link_title'];
      $item['external'] = FALSE;
      $item['options'] = '';
      _menu_link_translate($item);
    }
  }
  else {
    $item = menu_get_item($path);
  }
  $menu_admin = FALSE;
  return $item && $item['access'];
}