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

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


$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.


includes/path.inc, line 554
Functions to handle paths in Drupal, including path aliasing.


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'] = $item['path'];
      $item['link_title'] = $item['title'];
      $item['external'] = FALSE;
      $item['options'] = '';
  else {
    $item = menu_get_item($path);
  $menu_admin = FALSE;
  return $item && $item['access'];


thedavidmeister’s picture

Unlike many other Drupal "path" functions, drupal_valid_path() considers absolute/external urls to be valid "paths".