Opened 13 years ago
Closed 13 years ago
#21424 closed feature request (duplicate)
Adding an Admin Page Slug without and Admin Menu Link
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.4.1 |
Component: | Administration | Keywords: | |
Focuses: | Cc: |
Description
I'd like to be able to add an admin page slug that runs a function but does not appear in the admin menu.
For instance, if I create a custom object in a plugin managed in a custom database table, I'd like to be able to bring up an edit page for that plugin using a page slug and query var like:
?page=my-plugin-edit-object&object-id=6
...which could help simplify the plugin's architecture into something more pseudo-MVC like rather that having to find some sort of twisted PHP control flow.
I can currently get this functionality by using add_submenu_page with the $parent_slug parameter set to another submenu (since WordPress doesn't support more than one level of submenu nesting).
For example, in my plugin I'd do something like:
add_menu_page( 'My Plugin', 'My Plugin', 'manage_options', 'my-plugin', array( $this, 'my_plugin_main_page' ) ); add_submenu_page( 'my-plugin', 'My Plugin: Objects', 'objects', 'manage_options', 'my-plugin-objects', array( $this, 'my_plugin_objects_page' ) ); add_submenu_page( 'my-plugin-objects', 'My Plugin: Edit Object', 'edit object', 'manage_options', 'my-plugin-edit-object', array( $this, 'edit_object_page' ) );
...yet this is sort of in hack territory.
The idea here is that the admin page with the slug 'my-plugin-edit-object' shouldn't be in the main admin menu since it would be accessed only from the 'my-plugin-objects' page with a query var for the id of the object in the database (e.g. ?page=my-plugin-edit-object&object-id=6 as I have above).
Would it be possible to add some kind of "add_action_page" function to the API so that we could create plugins which have admin menu slugs which aren't designed to show up as a link in the main admin menu?
This could be quite useful and make it far easier to architect plugins in a sort of "pseudo-MVC" fashion...
...I'd also add that it'd be nice if, when creating a "sub-submenu" page using the proposed "add_action_page" function, that the parent item would remain highlighted in the admin menu when on the admin page with the registered slug.