Adminline documentation1.x
Developers

Hooks for developers

Filters and actions to change how the menu is read, drawn, hidden and blocked, and to add to the editor.

Adminline is built on WordPress's own menu: it reads $menu and $submenu just before the menu is printed, draws your saved menu in their place, and puts the originals back right after, so other code sees the menu it registered.

Each item has a key: t:<slug> for a top-level item and s:<parent slug>><slug> for a submenu item (for example t:edit.php, s:edit.php>post-new.php, s:woocommerce>wc-orders). Added separators are sep:<id> and custom links link:<id>.

Who sees an item

adminline_item_visible decides whether someone sees an item, after the item's own setting. Return true to show it, false to hide it. It also decides blocking (a hidden, blocked item's screen is refused) and the admin bar.

// Comments only for people who can moderate them, whatever the menu settings.
add_filter( 'adminline_item_visible', function ( $visible, $item, $user ) {
	if ( 't:edit-comments.php' === $item['key'] ) {
		return user_can( $user, 'moderate_comments' );
	}
	return $visible;
}, 10, 3 );

adminline_protected_items lists the keys that are always shown to, and never blocked for, people who can manage options (Adminline's screen and Plugins). Add your own:

add_filter( 'adminline_protected_items', function ( $keys ) {
	$keys[] = 's:tools.php>site-health.php';
	return $keys;
} );

Blocking

  • adminline_blocked filters whether the current screen is blocked ($blocked, $item, $request, $user; $request has path, the file, and args, the query arguments).
  • adminline_blocked_message filters the message (HTML, passed through wp_kses_post()).

The menu itself

  • adminline_live_menu filters the menu as read, before saved changes are laid over it.
  • adminline_menu filters the tree about to be drawn for the current person.
  • adminline_active switches every change off for a request when it returns false (safe mode and the ADMINLINE_DISABLE constant use the same switch).
  • adminline_icons filters the Dashicons offered in the icon picker.

The editor

  • adminline_tabs adds tabs to Settings → Admin Menu (an array of slug => label). Print a tab with the adminline_tab_<slug> action.
  • adminline_editor_after and adminline_tools_after print after the editor and after the Tools boxes.
  • adminline_saved fires after a save, with the saved tree; adminline_reset after a reset.
  • adminline_export filters the export file's data; adminline_import fires with the imported file's data.
  • adminline_import_errors filters the problems found in an import file ($errors, $data), before anything is saved. Add a message to refuse the file; nothing is imported then.
  • In the editor's JavaScript, the adminline.panel action (wp.hooks) fires when an item's panel is drawn, and adminline.changed after any change. window.adminline gives the model and render().

For add-ons

adminline_loaded fires once Adminline has loaded (on plugins_loaded); ADMINLINE_VERSION, ADMINLINE_FILE, ADMINLINE_URL and ADMINLINE_DIR are defined from then on. Adminline Pro is built on these hooks.