Opened 7 months ago

Last modified 7 months ago

#22141 new enhancement

add_submenu_page file callback

Reported by: BenRacicot Owned by:
Priority: normal Milestone: Awaiting Review
Component: General Version: 3.4.2
Severity: normal Keywords: 2nd-opinion
Cc:

Description

Under the recommendation of the community I have decided to file a track regarding add_submenu_page. It currently allows for a callback function in which a dev could include a file but how about allowing add_submenu_page an argument to include a file in replacement of a callback function? This would remove several lines of code and clean up many developers functions.php files as well as custom admin page files.

Thanks for listening and I hope I can help.
-Ben

Change History (3)

  • Keywords 2nd-opinion added; dev-feedback removed

Hey Ben,

First, some context:

The whole API related to add_submenu_page() needs a lot of work. The logic is spread all over the place and is mixed with the menu generating code #12718.

Also, add_submenu_page() already has 6 parameters. If we want to add another parameter, we should think about converting them to an associative array first.

Instead of adding yet another parameter that only works for this function and create an inconsistency with add_menu_page(), we could add a helper callback that just loads a file you specify.

Example usage:

add_submenu_page( 'tools.php', 'My Utility', 'My Utility', 'manage_options', 'my-utility', _delayed_load( 'my-utility-ui.php' ) );

And here's how the implementation of _delayed_load() would look like:

function _delayed_load( $file ) {
	return function() use ( $file ) {
		include $file;
	};
}

This only works in PHP 5.3, but it can be made to work for PHP 5.2 by using a helper class.

Version 2, edited 7 months ago by scribu (previous) (next) (diff)

comment:2 follow-up: ↓ 3   nacin7 months ago

I actually don't really like the idea of using a file here. Unfortunately, it makes it very easy for bad developers to expose a form to the point where direct file POSTs could essentially result in CSRF.

comment:3 in reply to: ↑ 2   BenRacicot7 months ago

Nice Scribu!

Maybe I'm missing something, that seems to simple. Nacin, I can't think how an included file in an admin page could be CSRF'ed. But I'm still in my rookie year haha.

Note: See TracTickets for help on using tickets.