From 895cede84a023dee3715b6bf3f01eed15072c4e0 Mon Sep 17 00:00:00 2001 From: Drew Jaynes Date: Thu, 6 Jul 2017 15:11:32 +0000 Subject: [PATCH] Options: Pass `$default` as a new parameter to the `pre_option_{$option}` and `pre_site_option_{$option}` filters. This change standardizes some language in the parameter descriptions between the two hook docs in an effort to reduce confusion between the `$pre_option` pseudo-parameters and the new `$default` ones. `$pre_option` is the truthy value used to short-circuit the `get_*option()` call, `$default` is the value passed to the `get_*option()` returned in the event that 1) a short circuit isn't performed, 2) the option doesn't exist. Props sc0ttkclark. Fixes #41254. git-svn-id: https://develop.svn.wordpress.org/trunk@41013 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/option.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 9f7cc8698e..7715426608 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -44,12 +44,19 @@ function get_option( $option, $default = false ) { * * @since 1.5.0 * @since 4.4.0 The `$option` parameter was added. + * @since 4.9.0 The `$default` parameter was added. * - * @param bool|mixed $pre_option Value to return instead of the option value. - * Default false to skip it. + * + * @param bool|mixed $pre_option The value to return instead of the option value. This differs from + * `$default`, which is used as the fallback value in the event the option + * doesn't exist elsewhere in get_option(). Default false (to skip past the + * short-circuit). * @param string $option Option name. + * @param mixed $default The fallback value to return if the option does not exist. + * Default is false. */ - $pre = apply_filters( "pre_option_{$option}", false, $option ); + $pre = apply_filters( "pre_option_{$option}", false, $option, $default ); + if ( false !== $pre ) return $pre; @@ -1116,12 +1123,18 @@ function get_network_option( $network_id, $option, $default = false ) { * @since 3.0.0 * @since 4.4.0 The `$option` parameter was added. * @since 4.7.0 The `$network_id` parameter was added. + * @since 4.9.0 The `$default` parameter was added. * - * @param mixed $pre_option The default value to return if the option does not exist. + * @param mixed $pre_option The value to return instead of the option value. This differs from + * `$default`, which is used as the fallback value in the event the + * option doesn't exist elsewhere in get_network_option(). Default + * is false (to skip past the short-circuit). * @param string $option Option name. * @param int $network_id ID of the network. + * @param mixed $default The fallback value to return if the option does not exist. + * Default is false. */ - $pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id ); + $pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default ); if ( false !== $pre ) { return $pre;