Make WordPress Core

Opened 14 years ago

Closed 6 years ago

Last modified 2 years ago

#18850 closed enhancement (wontfix)

hidden admin page

Reported by: ibotty's profile ibotty Owned by:
Milestone: 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 (15)

#1 @jane
14 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?

#2 @ibotty
14 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?

#3 @nacin
14 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.

#4 @johnjamesjacoby
13 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 13 years ago by johnjamesjacoby (previous) (diff)

#5 @SidHarrell
13 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.

#6 @SidHarrell
13 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!";
}

#7 @SergeyBiryukov
13 years ago

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

Closed #20878 as a duplicate.

#8 @SergeyBiryukov
13 years ago

Closed #21424 as a duplicate.

#9 @joe.woidpress
13 years 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.)

#10 @SergeyBiryukov
12 years ago

#25591 was marked as a duplicate.

#11 @mordauk
11 years 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.

#12 @SergeyBiryukov
11 years ago

#28700 was marked as a duplicate.

#13 @swissspidy
10 years ago

#34248 was marked as a duplicate.

#14 @chriscct7
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

This is already possible as mentioned in comment 11 or more easily just use add_submenu_page with a parent ID of null which is a method widely adopted at this point.

Example:

add_action( 'admin_menu', function() {
    add_submenu_page(
        null,
        __( 'Welcome', 'textdomain' ),
        __( 'Welcome', 'textdomain' ),
        'manage_options',
        'my-welcome',
        'prefix_render'
    );
} );

#15 @renathoc
2 years ago

This is already possible as mentioned in comment 11 or more easily just use add_submenu_page with a parent ID of null which is a method widely adopted at this point.

Just adding that probably the null is not a good option anymore, since it will try to run a strpos passing null as first argument, and PHP 8 is giving a deprecation notice for that.

Note: See TracTickets for help on using tickets.