pre_option_(option) хук-фильтрWP 1.5.0

Filters the value of an existing option before it is retrieved.

The dynamic portion of the hook name, $option, refers to the option name.

Returning a value other than false from the filter will short-circuit retrieval and return that value instead.

Использование

add_filter( 'pre_option_(option)', 'wp_kama_pre_option_filter', 10, 3 );

/**
 * Function for `pre_option_(option)` filter-hook.
 * 
 * @param mixed  $pre_option    The value to return instead of the option value. This differs from `$default_value`, which is used as the fallback value in the event the option doesn't exist elsewhere in get_option().
 * @param string $option        Option name.
 * @param mixed  $default_value The fallback value to return if the option does not exist.
 *
 * @return mixed
 */
function wp_kama_pre_option_filter( $pre_option, $option, $default_value ){

	// filter...
	return $pre_option;
}
$pre_option(разное)
The value to return instead of the option value. This differs from $default_value, which is used as the fallback value in the event the option doesn't exist elsewhere in get_option().
По умолчанию: false (to skip past the short-circuit)
$option(строка)
Option name.
$default_value(разное)
The fallback value to return if the option does not exist.
По умолчанию: false

Список изменений

С версии 1.5.0 Введена.
С версии 4.4.0 The $option parameter was added.
С версии 4.9.0 The $default_value parameter was added.

Где вызывается хук

get_option()
pre_option_(option)
wp-includes/option.php 132
$pre = apply_filters( "pre_option_{$option}", false, $option, $default_value );

Где используется хук в WordPress

wp-admin/includes/bookmark.php 338
add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
wp-admin/includes/bookmark.php 340
remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
wp-admin/options-discussion.php 341
add_filter( 'pre_option_show_avatars', '__return_true', 100 );
wp-admin/options-discussion.php 351
remove_filter( 'pre_option_show_avatars', '__return_true', 100 );
wp-includes/class-wp-customize-manager.php 685
add_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
wp-includes/class-wp-customize-manager.php 688
add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
wp-includes/class-wp-customize-manager.php 689
add_filter( 'pre_option_template', array( $this, 'get_template' ) );
wp-includes/class-wp-customize-manager.php 692
add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
wp-includes/class-wp-customize-manager.php 693
add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
wp-includes/class-wp-customize-manager.php 723
remove_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
wp-includes/class-wp-customize-manager.php 726
remove_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
wp-includes/class-wp-customize-manager.php 727
remove_filter( 'pre_option_template', array( $this, 'get_template' ) );
wp-includes/class-wp-customize-manager.php 730
remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
wp-includes/class-wp-customize-manager.php 731
remove_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
wp-includes/class-wp-customize-setting.php 379
add_filter( "pre_option_{$id_base}", array( $this, '_preview_filter' ) );
wp-includes/class-wp-customize-widgets.php 2133
add_filter( "pre_option_{$option_name}", array( $this, 'capture_filter_pre_get_option' ) );
wp-includes/class-wp-customize-widgets.php 2175
remove_filter( "pre_option_{$option_name}", array( $this, 'capture_filter_pre_get_option' ) );
wp-includes/default-filters.php 466
add_filter( 'pre_option_gmt_offset', 'wp_timezone_override_offset' );
wp-includes/default-filters.php 472
add_filter( 'pre_option_embed_autourls', '__return_true' );