[wp-trac] [WordPress Trac] #38650: Provide some guidance on what conditionals can/should be used in default-filters.php
WordPress Trac
noreply at wordpress.org
Thu Sep 19 07:33:54 UTC 2024
#38650: Provide some guidance on what conditionals can/should be used in default-
filters.php
----------------------------+---------------------
Reporter: helen | Owner: jorbin
Type: enhancement | Status: closed
Priority: low | Milestone: 6.7
Component: Bootstrap/Load | Version:
Severity: minor | Resolution: fixed
Keywords: has-patch | Focuses:
----------------------------+---------------------
Changes (by maqboolahmed5243):
* focuses: docs =>
Comment:
You're absolutely right, the limitations in default-filters.php can be
confusing, especially with functions like get_option() and
is_customize_preview() not being safe to use directly. The file's role
isn't immediately clear, and without a good understanding of how load
sequences work, it’s easy to run into issues.
An inline comment explaining the purpose of the file and outlining safe
functions (like those from load.php) would definitely be helpful for
anyone unfamiliar with the internals. This could prevent a lot of trial
and error. Thanks for pointing this out—it’s a solid suggestion to improve
clarity!
{{{#!php
<?php
/**
* default-filters.php
*
* This file registers the default filters and actions essential to
WordPress
* core functionality. It’s loaded very early in the WordPress
bootstrapping
* process, before many core components and settings are available.
*
* Safe to use:
* - Functions and conditionals defined in load.php (e.g., is_admin(),
current_user_can()).
* - Low-level hooks and actions that don't rely on options, query
variables, or themes.
*
* Unsafe to use:
* - get_option(), get_theme_mod(), or anything that interacts with the
options table.
* - Conditional tags like is_singular(), is_page(),
is_customize_preview(), etc.,
* which depend on query variables, the theme, or customizer data.
*
* Important: Stick to lightweight logic that doesn't require full
WordPress
* initialization. Defer more complex operations to later hooks, such as
* after_setup_theme or init.
*/
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38650#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list