What is the WordPress `pre_option_{option_name}` filter and how can it be used to short-circuit options retrieval?

WordPress Fundamental Hard

WordPress Fundamental — Hard

What is the WordPress `pre_option_{option_name}` filter and how can it be used to short-circuit options retrieval?

Key points

  • The filter triggers before querying the database for an option value
  • Returning a non-false value from the callback stops the database query
  • Enables option overrides through environment variables or external config
  • Avoids the need for database writes when mocking options for testing

Ready to go further?

Related questions