[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
Mon Sep 23 05:57:57 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:
----------------------------+---------------------
Comment (by maqboolahmedbaloch143):
You're absolutely right. The confusion stems from the fact that default-
filters.php is loaded very early in the WordPress initialization process,
before certain core files are fully available. A comment at the top of the
file explaining what's safe to use would definitely help developers avoid
unexpected issues.
Something like this could be helpful:
{{{#!php
<?php/**
* default-filters.php
*
* This file is loaded early in WordPress, before many core components are
available.
* Safe to use:
* - Functions and conditionals defined in load.php (e.g., is_admin(),
current_user_can()).
* - Basic hooks and actions that don’t depend on options, themes, or
query variables.
*
* Unsafe to use:
* - get_option(), get_theme_mod(), and anything relying on database
options.
* - Conditional tags (is_singular(), is_customize_preview()) that depend
on the query or theme setup.
*/
}}}
This will clarify the scope and prevent errors related to using functions
that rely on later parts of the WordPress lifecycle.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38650#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list