WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 4 days ago

#18850 new enhancement

hidden admin page

Reported by: ibotty Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: Cc:

Description

it should be possible to create a hidden admin page.

this is useful for pages, that require parameters which are better inserted in other pages (e. g. using the post_row_actions filter).

if this is already possible, it should be documented somewhere where it might be found.

(btw: i'm not sure, what the difference between feature request and enhancement is. please redeclare as fit)

Change History (11)

comment:1 jane3 years ago

  • Keywords changed from admin page, hidden to admin page hidden
  • Type changed from enhancement to feature request

A hidden admin page? Hidden from who, and for what purpose?

comment:2 ibotty3 years ago

maybe i did not make myself very clear. sorry about it.

using the filter hook post_row_actions you can insert additional 'actions' into a post view. say you want to have a special 'post edit view'. you select the post in the post overview (the page with the WP_Posts_List_Table) and you link to your "hidden" page. this page does not make sense without a post-id and this post is only selected somewhere else. so this page should be accessible as if it were in wp-admin, but not be in the menu. (this page should behave similar to options.php in this regard.)

did i make myself clear now?

comment:3 nacin3 years ago

  • Type changed from feature request to enhancement

Makes sense, basically, options.php, as you said.

I'm willing to bet this is possible in the current API, only that it's clunky. Not even sure the approach I'd take to do it, but I imagine there are a few.

FWIW, custom post types do allow show_in_menu => false.

comment:4 johnjamesjacoby2 years ago

+1 to this. It would allow plugins to make Welcome/Credits pages similar to WordPress core, without needing to pollute the admin menu.

Last edited 2 years ago by johnjamesjacoby (previous) (diff)

comment:5 SidHarrell2 years ago

I found this: http://stackoverflow.com/questions/3902760/how-do-you-add-a-wordpress-admin-page-without-adding-it-to-the-menu

I used it like so:

public function register_page() {
		global $_registered_pages;

		$menu_slug = 'restaurant_category_editor';
		$hookname = get_plugin_page_hookname($menu_slug, '');
		if (!empty($hookname)) {
			add_action($hookname, array(&$this, 'render_edit_page'));
		}
		$_registered_pages[$hookname] = true;
	}

And when I browse to: http://chinadelight.info/wp-admin/admin.php?page=restaurant_category_editor
I get my "hello world!" output of the redering function.
should be easy enough to turn into a core function by moving the $menu_slug and the callback into the parameters.

comment:6 SidHarrell2 years ago

I made it more generic, so:

add_action('admin_menu', 'add_non_menu_pages');

function add_non_menu_pages() {
    global $_registered_pages;
    $pages = get_non_menu_pages();
    foreach ($pages as $menu_slug => $callback) {
                $hookname = get_plugin_page_hookname($menu_slug, '');
                if (!empty($hookname)) {
                        add_action($hookname, $callback);
                }
                $_registered_pages[$hookname] = true;
        }
}

function get_non_menu_pages() {
    return array(
        'pricing_editor' => 'render_edit_page'
    );
}

function render_edit_page() {
    echo "hello world!";
}

comment:7 SergeyBiryukov23 months ago

  • Component changed from General to Administration
  • Keywords admin page hidden removed

Closed #20878 as a duplicate.

comment:8 SergeyBiryukov21 months ago

Closed #21424 as a duplicate.

comment:9 joe.woidpress21 months ago

Ah-ha. It seems I just made a duplicate of this request http://core.trac.wordpress.org/ticket/21424.

If you read my closed ticket, my hack to get this functionality was to create a submenu page of a submenu page (using add_submenu_page on something that was already a submenu).

This works well enough, but doesn't sit well with me. If we could get an official core function that does this it'd be great. (It'd also be cool if a submenu of a submenu kept the visible parent item open while the "hidden" page was being displayed.)

comment:10 SergeyBiryukov6 months ago

#25591 was marked as a duplicate.

comment:11 mordauk4 days ago

This can be done by creating a submenu of index.php and then removing it and then removing it during the admin_head action. For example:

function pw_my_hidden_admin_page() {
	add_dashboard_page(
		'Welcome'
		'Welcome to My Plugin',
		'manage_options',
		'pw-my-slug',
		'pw_render_my_welcome_page'
	);
}
add_action( 'admin_menu', 'pw_my_hidden_admin_page' );

function pw_render_my_welcome_page() {
	echo 'Hello';
}

function pw_hide_my_welcome_page() {
	remove_submenu_page( 'index.php', 'pw-my-slug' );
}
add_action( 'admin_head'', 'pw_hide_my_welcome_page' );

It's a bit clunky but it does work.

I'd love to see a better approach.

Note: See TracTickets for help on using tickets.