4

As per my understanding, functions attached to plugin_loaded and admin_init hooks are called whenever any admin page is loaded. What's the difference between them?

1 Answer 1

9

plugins_loaded fires once activated plugins have loaded. This fires on both admin and public screens.

admin_init fires as an admin screen or script is being initialized. This fires only on admin screens.


The typical order for firing of hooks on the admin screen is:

  1. muplugins_loaded - this is the first hook available to must-use plugins
  2. registered_taxonomy
  3. registered_post_type
  4. plugins_loaded - this is the first hook available to regular plugins
  5. auth_cookie_valid
  6. set_current_user
  7. load_textdomain
  8. sanitize_comment_cookies
  9. setup_theme
  10. unload_textdomain
  11. after_setup_theme - this is the first hook available to themes
  12. init
  13. widgets_init
  14. register_sidebar
  15. wp_register_sidebar_widget
  16. wp_default_styles
  17. wp_default_scripts
  18. debug_bar_enqueue_scripts
  19. wp_loaded - This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
  20. auth_redirect
  21. admin_menu
  22. pre_get_users
  23. pre_user_query
  24. admin_init
  25. ... lots of other stuff

As you can see, a lot happens between plugins_loaded and admin_init.

Hooks on the public side are similar to those above, with the notable absence of admin_init.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.