Discussion:
add_submenu_page() with no parent
Jonathan Brinley
2013-08-13 12:53:51 UTC
Permalink
According to the codex (
http://codex.wordpress.org/Function_Reference/add_submenu_page#Parameters)
you can call add_submenu_page() with NULL or options.php as the parent to
create an admin page that doesn't appear in the admin menu. options.php
does, indeed, work for this, and NULL seems to work on multisite, but not
single site installs.

On a single site install, the permissions check
in user_can_access_admin_page() gets the incorrect page hook name when it
calls get_plugin_page_hookname(). A page registered with a NULL parent gets
the hook "dashboard_page_*", but get_plugin_page_hookname() returns
"admin_page_*". On multisite, it correctly returns "dashboard_page_*".

So, finally, to my question: is this a bug in the documentation, or a bug
in the code? It looks like NULL is unpredictable, and options.php is the
only safe way to register an orphan admin page.

Have a nice day,
Jonathan
--
Jonathan M. Brinley

***@gmail.com
http://xplus3.net/
Pascal Birchler
2013-08-13 13:47:39 UTC
Permalink
Looks like an error in the Codex to me, since this isn't documented in
the function
definition<http://core.trac.wordpress.org/browser/tags/3.6/wp-admin/includes/plugin.php#L980>.
I don't know if this was possible earlier, though. Maybe someone else knows
more about this function's history?
Post by Jonathan Brinley
According to the codex (
http://codex.wordpress.org/Function_Reference/add_submenu_page#Parameters)
you can call add_submenu_page() with NULL or options.php as the parent to
create an admin page that doesn't appear in the admin menu. options.php
does, indeed, work for this, and NULL seems to work on multisite, but not
single site installs.
On a single site install, the permissions check
in user_can_access_admin_page() gets the incorrect page hook name when it
calls get_plugin_page_hookname(). A page registered with a NULL parent gets
the hook "dashboard_page_*", but get_plugin_page_hookname() returns
"admin_page_*". On multisite, it correctly returns "dashboard_page_*".
So, finally, to my question: is this a bug in the documentation, or a bug
in the code? It looks like NULL is unpredictable, and options.php is the
only safe way to register an orphan admin page.
Have a nice day,
Jonathan
--
Jonathan M. Brinley
http://xplus3.net/
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
J.D. Grimes
2013-08-13 16:30:06 UTC
Permalink
There are ways of doing this, but its currently not a "feature" of the function. See these tickets:

https://core.trac.wordpress.org/ticket/21424
https://core.trac.wordpress.org/ticket/18850

- J.D.
Post by Pascal Birchler
Looks like an error in the Codex to me, since this isn't documented in
the function
definition<http://core.trac.wordpress.org/browser/tags/3.6/wp-admin/includes/plugin.php#L980>.
I don't know if this was possible earlier, though. Maybe someone else knows
more about this function's history?
Post by Jonathan Brinley
According to the codex (
http://codex.wordpress.org/Function_Reference/add_submenu_page#Parameters)
you can call add_submenu_page() with NULL or options.php as the parent to
create an admin page that doesn't appear in the admin menu. options.php
does, indeed, work for this, and NULL seems to work on multisite, but not
single site installs.
On a single site install, the permissions check
in user_can_access_admin_page() gets the incorrect page hook name when it
calls get_plugin_page_hookname(). A page registered with a NULL parent gets
the hook "dashboard_page_*", but get_plugin_page_hookname() returns
"admin_page_*". On multisite, it correctly returns "dashboard_page_*".
So, finally, to my question: is this a bug in the documentation, or a bug
in the code? It looks like NULL is unpredictable, and options.php is the
only safe way to register an orphan admin page.
Have a nice day,
Jonathan
--
Jonathan M. Brinley
http://xplus3.net/
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...