menu_valid_path

6 menu.inc menu_valid_path($form_item)

Validates the path of a menu link being created or edited.

Return value

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

Related topics

3 calls to menu_valid_path()

File

includes/menu.inc, line 2523
API for the Drupal menu system.

Code

function menu_valid_path($form_item) {
  global $menu_admin;
  $item = array();
  $path = $form_item['link_path'];
  // We indicate that a menu administrator is running the menu access check.
  $menu_admin = TRUE;
  if ($path == '<front>' || menu_path_is_external($path)) {
    $item = array('access' => TRUE);
  }
  elseif (preg_match('/\/\%/', $path)) {
    // Path is dynamic (ie 'user/%'), so check directly against menu_router table.
    if ($item = db_fetch_array(db_query("SELECT * FROM {menu_router} where path = '%s' ", $path))) {
      $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'];
}

Comments

Verify Page Existance

I used the following code to make sure paths exist before displaying a link:

<?php
global $base_url;
$path $base_url .'/path-to-page-needing-verification';
if (
menu_valid_path(array('link_path' => $path))) {
  print
'<a href="'. $path .'">Click Here</a>';
}
?>

I've tested it with the relative path ("/industrial") but it appears to require the full path. You can use $base_url to convert

---

The function has been replaced by drupal_valid_path(), in Drupal 7 and forward.

Login or register to post comments