Hooks Reference Backend

1. Early Initialization (Before Admin UI Loads)

These hooks fire before the admin interface is rendered:

  • muplugins_loaded – After must-use plugins load 12.
  • plugins_loaded – After active plugins load (before admin checks) 213.
  • auth_cookie_valid – After user authentication 2.
  • set_current_user – Sets the current user object 2.
  • init – Core initialization (register post types, taxonomies) 112.
    • widgets_init – Fires at init priority 1 for sidebar registration 27.
  • admin_bar_init – Initializes the admin toolbar 26.
  • wp_loaded – WordPress fully loaded (plugins, themes, user auth complete) 213.

2. Admin-Specific Setup

Hooks for admin dashboard initialization:

  • admin_init – Ideal for admin settings, enqueueing scripts/styles, or permissions checks 612.
  • admin_menu – Adds top-level menus/submenus 613.
    • network_admin_menu – For Multisite network admin menus 6.
  • current_screen – Detects which admin screen is loaded (e.g., edit.php) 612.
  • load-{$page_hook} – Runs before a specific admin page loads (e.g., load-toplevel_page_my-plugin) 613.

3. Admin UI Rendering

Hooks during page rendering:

  • admin_enqueue_scripts – Proper place to enqueue admin JS/CSS 612.
  • admin_head – Inside <head> of admin pages 612.
    • admin_head-{$hook_suffix} – For specific admin pages 6.
  • admin_notices – Displays admin notices (e.g., success/error messages) 612.
  • admin_print_scripts / admin_print_styles – Before scripts/styles are printed 6.
  • in_admin_header – After admin toolbar, before content 6.
  • admin_footer – Before closing </body> 612.

4. Post/Page Editing

Hooks specific to post-editing screens:

  • add_meta_boxes – Register meta boxes for posts/pages 412.
  • save_post – When a post is saved/updated 612.
  • transition_post_status – When post status changes (e.g., draft → publish) 212.
  • post_submitbox_misc_actions – Adds content to the publish meta box 6.

5. Late-Stage & Cleanup

  • shutdown – Final hook before PHP terminates (logs, cleanup) 513.
  • wp_dashboard_setup – Customize the admin dashboard widgets 613.

Key Admin-Only Hooks Cheatsheet

HookPurposeExample Use Case
admin_initInitialize admin settingsRegister plugin options
admin_menuAdd admin menusCreate a custom plugin page
admin_enqueue_scriptsLoad admin JS/CSSAdd a datepicker to a meta box
current_screenTarget specific admin screensRun code only on edit.php
save_postPost save/updateSync data to external API
admin_noticesShow alerts“Settings saved” notification

Pro Tips

  1. Conditional Loading: Use is_admin() or $pagenow checks to target specific admin areas 13.
  2. AJAX Handling: Use wp_ajax_{action} for logged-in users and wp_ajax_nopriv_{action} for guests 612.
  3. Custom Hooks: Create extensible plugins with do_action('my_plugin_hook') 512.