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 |
|---|---|
| 71 | * @since 3.4.0 |
| 72 | * @since 4.4.0 The `$option` parameter was added. |
| 73 | * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value. |
| 74 | * |
| 75 | * @param mixed $default The default value to return if the option does not exist |
| 76 | * in the database. |
| 77 | * @param string $option Option name. |
| 78 | * @param bool $passed_default Was `get_option()` passed a default value? |
| 79 | */ |
| 80 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
| 81 | } |
| 82 | |
| 83 | $alloptions = wp_load_alloptions(); |
| 84 | |
| 85 | if ( isset( $alloptions[$option] ) ) { |
| 86 | $value = $alloptions[$option]; |
| 87 | } else { |
| 88 | $value = wp_cache_get( $option, 'options' ); |
| 89 | |
| Line | Code |
| 96 | wp_cache_add( $option, $value, 'options' ); |
| 97 | } else { // option does not exist, so we must cache its non-existence |
| 98 | if ( ! is_array( $notoptions ) ) { |
| 99 | $notoptions = array(); |
| 100 | } |
| 101 | $notoptions[$option] = true; |
| 102 | wp_cache_set( 'notoptions', $notoptions, 'options' ); |
| 103 | |
| 104 | /** This filter is documented in wp-includes/option.php */ |
| 105 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | } else { |
| 110 | $suppress = $wpdb->suppress_errors(); |
| 111 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
| 112 | $wpdb->suppress_errors( $suppress ); |
| 113 | if ( is_object( $row ) ) { |
| 114 | $value = $row->option_value; |
| 115 | } else { |
| 116 | /** This filter is documented in wp-includes/option.php */ |
| 117 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // If home is not set use siteurl. |
| 122 | if ( 'home' == $option && '' == $value ) |
| 123 | return get_option( 'siteurl' ); |
| 124 | |
| 125 | if ( in_array( $option, array('siteurl', 'home', 'category_base', 'tag_base') ) ) |
| 126 | $value = untrailingslashit( $value ); |
| Line | Code |
| 303 | * unnecessary database calls for otherwise identical object instances. |
| 304 | * |
| 305 | * See https://core.trac.wordpress.org/ticket/38903 |
| 306 | */ |
| 307 | if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
| 308 | return false; |
| 309 | } |
| 310 | |
| 311 | /** This filter is documented in wp-includes/option.php */ |
| 312 | if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) { |
| 313 | // Default setting for new options is 'yes'. |
| 314 | if ( null === $autoload ) { |
| 315 | $autoload = 'yes'; |
| 316 | } |
| 317 | |
| 318 | return add_option( $option, $value, '', $autoload ); |
| 319 | } |
| 320 | |
| 321 | $serialized_value = maybe_serialize( $value ); |
| Line | Code |
| 424 | if ( is_object($value) ) |
| 425 | $value = clone $value; |
| 426 | |
| 427 | $value = sanitize_option( $option, $value ); |
| 428 | |
| 429 | // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query |
| 430 | $notoptions = wp_cache_get( 'notoptions', 'options' ); |
| 431 | if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) ) |
| 432 | /** This filter is documented in wp-includes/option.php */ |
| 433 | if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) |
| 434 | return false; |
| 435 | |
| 436 | $serialized_value = maybe_serialize( $value ); |
| 437 | $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; |
| 438 | |
| 439 | /** |
| 440 | * Fires before an option is added. |
| 441 | * |
| 442 | * @since 2.9.0 |