Home   tech  

Sequence of important actions run by wordpress

WordPress runs a variety of actions during a typical request lifecycle, triggering specific hooks that developers can use to execute custom code at various stages. Understanding the sequence of these actions can greatly help in theme and plugin development. Below is a simplified sequence of important actions that WordPress fires in a typical page request. This sequence focuses on front-end requests rather than admin pages.

Initial Setup

  1. muplugins_loaded: Fires once all must-use plugins are loaded.
  2. registered_taxonomy: Fires after a taxonomy is registered.
  3. registered_post_type: Fires after a post type is registered.

Setup Environment

  1. plugins_loaded: All plugins are loaded. It's the first action hooked to after plugins are loaded.
  2. sanitize_comment_cookies: Sanitizes the comment cookies if they're set.
  3. setup_theme: Fires before the theme is loaded.
  4. unload_textdomain: Fires before unloading translations of a text domain.
  5. load_textdomain: Fires after loading the translations of a text domain.
  6. after_setup_theme: The theme's functions.php file is invoked. It's time to add theme support and define functions.

Set Up Query

  1. init: WordPress core features are set up; custom post types and taxonomies should be registered by now.
  2. widgets_init: Registers widgets. Sidebars can also be registered at this point.
  3. register_sidebar: Fires once for each sidebar being registered.
  4. wp_register_sidebar_widget: Fires once a sidebar widget has been registered.
  5. wp_loaded: WP Object is set up, and this hook is fired.

Parse Request

  1. parse_request: Fires before the WordPress query is set up.
  2. send_headers: Sends HTTP headers.

Query Posts

  1. pre_get_posts: Fires before the query is executed.
  2. posts_selection: Fires once the post query has been executed.

Load Template

  1. template_redirect: Before deciding which template to load.
  2. wp_enqueue_scripts, admin_enqueue_scripts, and login_enqueue_scripts: Used to enqueue scripts and styles. wp_enqueue_scripts is for the front end.

The Loop

  1. loop_start: Fires just before The Loop begins.
  2. the_post: Runs during The Loop to set up post data.
  3. loop_end: Fires just after The Loop ends.

Footer and Shutdown

  1. wp_footer: Used to hook into the footer, for enqueuing scripts, adding HTML, etc.
  2. get_footer: Fires before the footer template file is loaded.
  3. shutdown: Executes just before PHP shuts down execution.

Remember, this sequence is simplified and focuses on the frontend; admin pages and AJAX requests have their sequences. Moreover, between these actions, there are numerous other actions and filters that WordPress also executes, which developers can hook into for more specific needs or to alter the default behavior.

Published on: Mar 11, 2024, 04:13 AM  
 

Comments

Add your comment