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 |
|---|---|
| 80 | * @since 3.4.0 |
| 81 | * @since 4.4.0 The `$option` parameter was added. |
| 82 | * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value. |
| 83 | * |
| 84 | * @param mixed $default The default value to return if the option does not exist |
| 85 | * in the database. |
| 86 | * @param string $option Option name. |
| 87 | * @param bool $passed_default Was `get_option()` passed a default value? |
| 88 | */ |
| 89 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
| 90 | } |
| 91 | |
| 92 | $alloptions = wp_load_alloptions(); |
| 93 | |
| 94 | if ( isset( $alloptions[ $option ] ) ) { |
| 95 | $value = $alloptions[ $option ]; |
| 96 | } else { |
| 97 | $value = wp_cache_get( $option, 'options' ); |
| 98 | |
| Line | Code |
| 105 | wp_cache_add( $option, $value, 'options' ); |
| 106 | } else { // option does not exist, so we must cache its non-existence |
| 107 | if ( ! is_array( $notoptions ) ) { |
| 108 | $notoptions = array(); |
| 109 | } |
| 110 | $notoptions[ $option ] = true; |
| 111 | wp_cache_set( 'notoptions', $notoptions, 'options' ); |
| 112 | |
| 113 | /** This filter is documented in wp-includes/option.php */ |
| 114 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } else { |
| 119 | $suppress = $wpdb->suppress_errors(); |
| 120 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
| 121 | $wpdb->suppress_errors( $suppress ); |
| 122 | if ( is_object( $row ) ) { |
| 123 | $value = $row->option_value; |
| 124 | } else { |
| 125 | /** This filter is documented in wp-includes/option.php */ |
| 126 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // If home is not set use siteurl. |
| 131 | if ( 'home' == $option && '' == $value ) { |
| 132 | return get_option( 'siteurl' ); |
| 133 | } |
| 134 | |
| 135 | if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) ) { |
| Line | Code |
| 339 | * unnecessary database calls for otherwise identical object instances. |
| 340 | * |
| 341 | * See https://core.trac.wordpress.org/ticket/38903 |
| 342 | */ |
| 343 | if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
| 344 | return false; |
| 345 | } |
| 346 | |
| 347 | /** This filter is documented in wp-includes/option.php */ |
| 348 | if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) { |
| 349 | // Default setting for new options is 'yes'. |
| 350 | if ( null === $autoload ) { |
| 351 | $autoload = 'yes'; |
| 352 | } |
| 353 | |
| 354 | return add_option( $option, $value, '', $autoload ); |
| 355 | } |
| 356 | |
| 357 | $serialized_value = maybe_serialize( $value ); |
| Line | Code |
| 464 | $value = clone $value; |
| 465 | } |
| 466 | |
| 467 | $value = sanitize_option( $option, $value ); |
| 468 | |
| 469 | // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query |
| 470 | $notoptions = wp_cache_get( 'notoptions', 'options' ); |
| 471 | if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { |
| 472 | /** This filter is documented in wp-includes/option.php */ |
| 473 | if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) { |
| 474 | return false; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | $serialized_value = maybe_serialize( $value ); |
| 479 | $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; |
| 480 | |
| 481 | /** |
| 482 | * Fires before an option is added. |