WP hooks navigation: Home/browse • Actions index • Filters index
To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).
The best way to understand what a hook does is to look at where it occurs in the source code.
do_action( "hook_name" )apply_filters( "hook_name", "what_to_filter" ).Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.
This hook occurs 5 times in this file.
| Line | Code |
|---|---|
| 179 | * @since 3.4.0 |
| 180 | * @since 4.4.0 The `$option` parameter was added. |
| 181 | * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value. |
| 182 | * |
| 183 | * @param mixed $default_value The default value to return if the option does not exist |
| 184 | * in the database. |
| 185 | * @param string $option Option name. |
| 186 | * @param bool $passed_default Was `get_option()` passed a default value? |
| 187 | */ |
| 188 | return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default ); |
| 189 | } |
| 190 | |
| 191 | $alloptions = wp_load_alloptions(); |
| 192 | |
| 193 | if ( isset( $alloptions[ $option ] ) ) { |
| 194 | $value = $alloptions[ $option ]; |
| 195 | } else { |
| 196 | $value = wp_cache_get( $option, 'options' ); |
| 197 | |
| Line | Code |
| 205 | } else { // Option does not exist, so we must cache its non-existence. |
| 206 | if ( ! is_array( $notoptions ) ) { |
| 207 | $notoptions = array(); |
| 208 | } |
| 209 | |
| 210 | $notoptions[ $option ] = true; |
| 211 | wp_cache_set( 'notoptions', $notoptions, 'options' ); |
| 212 | |
| 213 | /** This filter is documented in wp-includes/option.php */ |
| 214 | return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default ); |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | } else { |
| 219 | $suppress = $wpdb->suppress_errors(); |
| 220 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
| 221 | $wpdb->suppress_errors( $suppress ); |
| 222 | |
| 223 | if ( is_object( $row ) ) { |
| 224 | $value = $row->option_value; |
| 225 | } else { |
| 226 | /** This filter is documented in wp-includes/option.php */ |
| 227 | return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default ); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // If home is not set, use siteurl. |
| 232 | if ( 'home' === $option && '' === $value ) { |
| 233 | return get_option( 'siteurl' ); |
| 234 | } |
| 235 | |
| 236 | if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) { |
| Line | Code |
| 508 | * unnecessary database calls for otherwise identical object instances. |
| 509 | * |
| 510 | * See https://core.trac.wordpress.org/ticket/38903 |
| 511 | */ |
| 512 | if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | /** This filter is documented in wp-includes/option.php */ |
| 517 | if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) { |
| 518 | // Default setting for new options is 'yes'. |
| 519 | if ( null === $autoload ) { |
| 520 | $autoload = 'yes'; |
| 521 | } |
| 522 | |
| 523 | return add_option( $option, $value, '', $autoload ); |
| 524 | } |
| 525 | |
| 526 | $serialized_value = maybe_serialize( $value ); |
| Line | Code |
| 666 | |
| 667 | /* |
| 668 | * Make sure the option doesn't already exist. |
| 669 | * We can check the 'notoptions' cache before we ask for a DB query. |
| 670 | */ |
| 671 | $notoptions = wp_cache_get( 'notoptions', 'options' ); |
| 672 | |
| 673 | if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { |
| 674 | /** This filter is documented in wp-includes/option.php */ |
| 675 | if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) { |
| 676 | return false; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | $serialized_value = maybe_serialize( $value ); |
| 681 | $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; |
| 682 | |
| 683 | /** |
| 684 | * Fires before an option is added. |