Skip to content

Commit aef5ef2

Browse files
committed
Docs: Add more information about how to use filters that run before WordPress initialises.
Fixes #50134 git-svn-id: https://develop.svn.wordpress.org/trunk@49489 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8fffa6c commit aef5ef2

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/wp-includes/class-wp-hook.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,30 @@ public function current_priority() {
356356
/**
357357
* Normalizes filters set up before WordPress has initialized to WP_Hook objects.
358358
*
359+
* The `$filters` parameter should be an array keyed by hook name, with values
360+
* containing either:
361+
*
362+
* - A `WP_Hook` instance
363+
* - An array of callbacks keyed by their priorities
364+
*
365+
* Examples:
366+
*
367+
* $filters = array(
368+
* 'wp_fatal_error_handler_enabled' => array(
369+
* 10 => array(
370+
* array(
371+
* 'accepted_args' => 0,
372+
* 'function' => function() {
373+
* return false;
374+
* },
375+
* ),
376+
* ),
377+
* ),
378+
* );
379+
*
359380
* @since 4.7.0
360381
*
361-
* @param array $filters Filters to normalize.
382+
* @param array $filters Filters to normalize. See documentation above for details.
362383
* @return WP_Hook[] Array of normalized filters.
363384
*/
364385
public static function build_preinitialized_hooks( $filters ) {

src/wp-includes/error-protection.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,27 @@ function wp_is_fatal_error_handler_enabled() {
111111
/**
112112
* Filters whether the fatal error handler is enabled.
113113
*
114+
* **Important:** This filter runs before it can be used by plugins. It cannot
115+
* be used by plugins, mu-plugins, or themes. To use this filter you must define
116+
* a `$wp_filter` global before WordPress loads, usually in `wp-config.php`.
117+
*
118+
* Example:
119+
*
120+
* $GLOBALS['wp_filter'] = array(
121+
* 'wp_fatal_error_handler_enabled' => array(
122+
* 10 => array(
123+
* array(
124+
* 'accepted_args' => 0,
125+
* 'function' => function() {
126+
* return false;
127+
* },
128+
* ),
129+
* ),
130+
* ),
131+
* );
132+
*
133+
* Alternatively you can use the `WP_DISABLE_FATAL_ERROR_HANDLER` constant.
134+
*
114135
* @since 5.2.0
115136
*
116137
* @param bool $enabled True if the fatal error handler is enabled, false otherwise.

0 commit comments

Comments
 (0)