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 |
|---|---|
| 105 | * @since 3.4.0 |
| 106 | * @since 4.4.0 The `$option` parameter was added. |
| 107 | * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value. |
| 108 | * |
| 109 | * @param mixed $default The default value to return if the option does not exist |
| 110 | * in the database. |
| 111 | * @param string $option Option name. |
| 112 | * @param bool $passed_default Was `get_option()` passed a default value? |
| 113 | */ |
| 114 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
| 115 | } |
| 116 | |
| 117 | $alloptions = wp_load_alloptions(); |
| 118 | |
| 119 | if ( isset( $alloptions[ $option ] ) ) { |
| 120 | $value = $alloptions[ $option ]; |
| 121 | } else { |
| 122 | $value = wp_cache_get( $option, 'options' ); |
| 123 | |
| Line | Code |
| 131 | } else { // Option does not exist, so we must cache its non-existence. |
| 132 | if ( ! is_array( $notoptions ) ) { |
| 133 | $notoptions = array(); |
| 134 | } |
| 135 | |
| 136 | $notoptions[ $option ] = true; |
| 137 | wp_cache_set( 'notoptions', $notoptions, 'options' ); |
| 138 | |
| 139 | /** This filter is documented in wp-includes/option.php */ |
| 140 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } else { |
| 145 | $suppress = $wpdb->suppress_errors(); |
| 146 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
| 147 | $wpdb->suppress_errors( $suppress ); |
| 148 | |
| 149 | if ( is_object( $row ) ) { |
| 150 | $value = $row->option_value; |
| 151 | } else { |
| 152 | /** This filter is documented in wp-includes/option.php */ |
| 153 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // If home is not set, use siteurl. |
| 158 | if ( 'home' === $option && '' === $value ) { |
| 159 | return get_option( 'siteurl' ); |
| 160 | } |
| 161 | |
| 162 | if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) { |
| Line | Code |
| 402 | * unnecessary database calls for otherwise identical object instances. |
| 403 | * |
| 404 | * See https://core.trac.wordpress.org/ticket/38903 |
| 405 | */ |
| 406 | if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
| 407 | return false; |
| 408 | } |
| 409 | |
| 410 | /** This filter is documented in wp-includes/option.php */ |
| 411 | if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) { |
| 412 | // Default setting for new options is 'yes'. |
| 413 | if ( null === $autoload ) { |
| 414 | $autoload = 'yes'; |
| 415 | } |
| 416 | |
| 417 | return add_option( $option, $value, '', $autoload ); |
| 418 | } |
| 419 | |
| 420 | $serialized_value = maybe_serialize( $value ); |
| Line | Code |
| 555 | |
| 556 | $value = sanitize_option( $option, $value ); |
| 557 | |
| 558 | // Make sure the option doesn't already exist. |
| 559 | // We can check the 'notoptions' cache before we ask for a DB query. |
| 560 | $notoptions = wp_cache_get( 'notoptions', 'options' ); |
| 561 | |
| 562 | if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { |
| 563 | /** This filter is documented in wp-includes/option.php */ |
| 564 | if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) { |
| 565 | return false; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | $serialized_value = maybe_serialize( $value ); |
| 570 | $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; |
| 571 | |
| 572 | /** |
| 573 | * Fires before an option is added. |