rest_pre_get_setting
Filter HookDescription
Filters the value of a setting recognized by the REST API. Allow hijacking the setting value and overriding the built-in behavior by returning a non-null value. The returned value will be presented as the setting value instead.Hook Information
File Location |
wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
View on GitHub
|
Hook Type | Filter |
Line Number | 98 |
Hook Parameters
Type | Name | Description |
---|---|---|
mixed
|
$result
|
Value to use for the requested setting. Can be a scalar matching the registered schema for the setting, or null to follow the default get_option() behavior. |
string
|
$name
|
Setting name (as shown in REST API responses). |
array
|
$args
|
Arguments passed to register_setting() for this setting. |
Usage Examples
Basic Usage
<?php
// Hook into rest_pre_get_setting
add_filter('rest_pre_get_setting', 'my_custom_filter', 10, 3);
function my_custom_filter($result, $name, $args) {
// Your custom filtering logic here
return $result;
}
Source Code Context
wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php:98
- How this hook is used in WordPress core
<?php
93 * matching the registered schema for the setting, or null to
94 * follow the default get_option() behavior.
95 * @param string $name Setting name (as shown in REST API responses).
96 * @param array $args Arguments passed to register_setting() for this setting.
97 */
98 $response[ $name ] = apply_filters( 'rest_pre_get_setting', null, $name, $args );
99
100 if ( is_null( $response[ $name ] ) ) {
101 // Default to a null value as "null" in the response means "not set".
102 $response[ $name ] = get_option( $args['option_name'], $args['schema']['default'] );
103 }
PHP Documentation
<?php
/**
* Filters the value of a setting recognized by the REST API.
*
* Allow hijacking the setting value and overriding the built-in behavior by returning a
* non-null value. The returned value will be presented as the setting value instead.
*
* @since 4.7.0
*
* @param mixed $result Value to use for the requested setting. Can be a scalar
* matching the registered schema for the setting, or null to
* follow the default get_option() behavior.
* @param string $name Setting name (as shown in REST API responses).
* @param array $args Arguments passed to register_setting() for this setting.
*/
Quick Info
- Hook Type: Filter
- Parameters: 3
- File: wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
Related Hooks
Related hooks will be displayed here in future updates.