WordPress.org

Ready to get started?Download WordPress

Forums

How to add Admin menu item linking directly to a page/ or widgets.php (3 posts)

  1. naastje
    Member
    Posted 1 year ago #

    Hey guys,

    Could you help me out with creating a "direct" menu item on the backend linking to a specific page and widget's and Nav Menus.

    This is what I have now:

    function mt_add_pages() {
        add_menu_page('admin-menu', 'Navigation', 5, __FILE__, 'mt_toplevel_page');
    }
    function mt_toplevel_page() {
      echo '
        <div class="wrap">
          <h2>Page Link</h2>
          <li><a href="http://www.mywebsite.com/website/wp-admin/post.php?post=1118&action=edit"><h3>Page Link</h3></a></li>
    <h2>Menus</h2>
          <li><a href="http://www.mywebsite.com/website/wp-admin/nav-menus.php"><h3>Go to Menus</h3></a></li>
    
    <h2>Widgets</h2>
          <li><a href="http://www.mywebsite.com/website/wp-admin/widgets.php"><h3>Go to widgets</h3></a></li>
    
        </div>';
    }
    add_action('admin_menu', 'mt_add_pages');

    It looks all right, it works fine, what I'm worried about is this:

    http://www.mywebsite.com/website/wp-admin/admin.php?page=home/username/domains/mywebsite.com/public_html/website/wp-content/themes/MyTheme/functions.php

    This shows up in the addres bar when I click on the "Navigation" menu item. I don't think it's a secure way to do it at all.

    Is there any other way to do something like that?

    Just like you have the menu item "Pages" with submenu "Alle pages" "New Page" but then a top level menu item "Navigation" with submenu "Page Link" "Menus" (the same menus as you go from "Appearance"-> "Menus") and "Widgets"(also the same as "Appearance" -> "Widgets" but then linked to a new top level menu item)

  2. bcworkz
    Member
    Posted 1 year ago #

    Since you are using a callback to display content, the menu slug is just a label. Don't use __FILE__, use something like 'navigation'.

    Incidentally, you should use a capability instead of a user level for the 3rd parameter. User levels will stop working at some point.

  3. naastje
    Member
    Posted 1 year ago #

    Thanks for the suggestion to change the __FILE__ to something else.

Topic Closed

This topic has been closed to new replies.

About this Topic