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 |
---|---|
154 | * @since 3.4.0 |
155 | * @since 4.4.0 The `$option` parameter was added. |
156 | * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value. |
157 | * |
158 | * @param mixed $default The default value to return if the option does not exist |
159 | * in the database. |
160 | * @param string $option Option name. |
161 | * @param bool $passed_default Was `get_option()` passed a default value? |
162 | */ |
163 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
164 | } |
165 |
|
166 | $alloptions = wp_load_alloptions(); |
167 |
|
168 | if ( isset( $alloptions[ $option ] ) ) { |
169 | $value = $alloptions[ $option ]; |
170 | } else { |
171 | $value = wp_cache_get( $option, 'options' ); |
172 |
|
Line | Code |
180 | } else { // Option does not exist, so we must cache its non-existence. |
181 | if ( ! is_array( $notoptions ) ) { |
182 | $notoptions = array(); |
183 | } |
184 |
|
185 | $notoptions[ $option ] = true; |
186 | wp_cache_set( 'notoptions', $notoptions, 'options' ); |
187 |
|
188 | /** This filter is documented in wp-includes/option.php */ |
189 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
190 | } |
191 | } |
192 | } |
193 | } else { |
194 | $suppress = $wpdb->suppress_errors(); |
195 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
196 | $wpdb->suppress_errors( $suppress ); |
197 |
|
198 | if ( is_object( $row ) ) { |
199 | $value = $row->option_value; |
200 | } else { |
201 | /** This filter is documented in wp-includes/option.php */ |
202 | return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
203 | } |
204 | } |
205 |
|
206 | // If home is not set, use siteurl. |
207 | if ( 'home' === $option && '' === $value ) { |
208 | return get_option( 'siteurl' ); |
209 | } |
210 |
|
211 | if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) { |
Line | Code |
454 | * unnecessary database calls for otherwise identical object instances. |
455 | * |
456 | * See https://core.trac.wordpress.org/ticket/38903 |
457 | */ |
458 | if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
459 | return false; |
460 | } |
461 |
|
462 | /** This filter is documented in wp-includes/option.php */ |
463 | if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) { |
464 | // Default setting for new options is 'yes'. |
465 | if ( null === $autoload ) { |
466 | $autoload = 'yes'; |
467 | } |
468 |
|
469 | return add_option( $option, $value, '', $autoload ); |
470 | } |
471 |
|
472 | $serialized_value = maybe_serialize( $value ); |
Line | Code |
610 |
|
611 | $value = sanitize_option( $option, $value ); |
612 |
|
613 | // Make sure the option doesn't already exist. |
614 | // We can check the 'notoptions' cache before we ask for a DB query. |
615 | $notoptions = wp_cache_get( 'notoptions', 'options' ); |
616 |
|
617 | if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { |
618 | /** This filter is documented in wp-includes/option.php */ |
619 | if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) { |
620 | return false; |
621 | } |
622 | } |
623 |
|
624 | $serialized_value = maybe_serialize( $value ); |
625 | $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; |
626 |
|
627 | /** |
628 | * Fires before an option is added. |