[resolved] Strange behaviour of add_submenu_page() / add_menu_page() (3 posts)

  1. Robert Heller
    Posted 4 years ago #

    I am in the process of re-coding a simple plugin to use a classes, instead of a random collection of global functions and variables. I am also coding it to use the WP_List_Table class. I have encounterer a very strange problem. I am sure it is a simple typo in my code somewhere, but I cannot find it. I expect that a fresh set of eyes will spot the problem.

    The plugin adds two main admin menu items, each with one sub-menu item. The first menu item is created fine, but its sub-menu item is created wrong. The second menu item and its sub-menu item are both created properly. I am using a class member function to display the admin pages (the function argument for both calls to add_menu_page and both calls to add_submenu_page is of the form array( $this, 'member_function_name' ), and for the both main menu items and the second sub-menu item, the URL generated is of the form /wp-admin/admin.php?page=slug, but for the first sub-menu the URL is /wp-admin/slug and I cannot figure out why it is doing that. I even tried creating a fresh wordpress site on my test server, and the same thing happens as on my proper test site on my test server.

    I have what I have so far available at the URL


    (Note: the plugin is not finished -- only the first page (FM Show Sched) is 'complete' (but not fully debugged). The problem is with the 'Add New' sub-page for FM Show Sched. The FM Open Mics page and its sub-page are not written yet -- there will be an error about require_once failing -- this is because I haven't written that code yet!

  2. Robert Heller
    Posted 4 years ago #

    BTW: I am using WP 3.1.2 on a 64-bit (x86_64) Linux machine (CentOS 5.6, httpd-2.2.3-45.el5.centos.1, php-5.1.6-27.el5_5.3, mysql-5.0.77-4.el5_5.5).

  3. Robert Heller
    Posted 4 years ago #

    Found the problem: it seems that using add_action('_admin_menu' ...) is not the right thing to do, changing it to add_action('admin_menu' ...) solves the problem. Weird... The example code I was looking at used add_action('_admin_menu' ...), but now I suspect that the example code is wrong on some level (there are other things wrong with it as well).

Topic Closed

This topic has been closed to new replies.

About this Topic