Splitting the admin area across several files
One plugin can have more than one admin entry file — core does it (download ships both admin_config.php and admin_download.php). This is worth doing when the plugin has a settings page and one or more entity managers: it keeps each file to one concern, and it gives admin_menu.php something to actually do.
myplugin/
admin/
admin_config.php <- preferences only
admin_entities.php <- e_admin_ui for the plugin's table
admin_menu.php <- shared menu, included by bothEach file needs its own dispatcher, its own permission gate, and its own auth.php / runPage() / footer.php sequence.
Linking between the files
$adminMenu supports a 'url' (or 'uri') key, which processMenuItem() maps to the link's href:
protected $adminMenu = array(
'main/list' => array('caption' => LAN_..._ENTITIES,
'url' => '{e_PLUGIN}myplugin/admin/admin_entities.php'),
'main/prefs' => array('caption' => LAN_PREFS,
'url' => '{e_PLUGIN}myplugin/admin/admin_config.php'),
);Add an <adminLinks> entry in plugin.xml for each entry file so both are reachable from the plugin manager.
Two things that bite
LAN loading order. Load the language file at the very top of admin_menu.php, before any dispatcher class is defined. Class property defaults (protected $adminMenu = array('...' => array('caption' => LAN_FOO))) are evaluated at parse time — if the LAN file is not loaded yet, you get undefined constants, which on PHP 8 is a fatal error, not a notice.
e_CURRENT_PLUGIN survives the admin/ subdirectory. It is derived from the first path segment after the plugins directory, so myplugin/admin/admin_config.php still resolves to myplugin. Moving the admin area into a subdirectory does not break getperms('P') or the e_help.php sidebar block. If the help block disappears, look at the addon cache instead (below).
Last updated