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 |
|---|---|
| 185 | * @since 3.4.0 |
| 186 | * @since 4.4.0 The `$option` parameter was added. |
| 187 | * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value. |
| 188 | * |
| 189 | * @param mixed $default_value The default value to return if the option does not exist |
| 190 | * in the database. |
| 191 | * @param string $option Option name. |
| 192 | * @param bool $passed_default Was `get_option()` passed a default value? |
| 193 | */ |
| 194 | return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default ); |
| 195 | } |
| 196 | |
| 197 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
| 198 | |
| 199 | // Has to be get_row() instead of get_var() because of funkiness with 0, false, null values. |
| 200 | if ( is_object( $row ) ) { |
| 201 | $value = $row->option_value; |
| 202 | wp_cache_add( $option, $value, 'options' ); |
| 203 | } else { // Option does not exist, so we must cache its non-existence. |
| 204 | $notoptions[ $option ] = true; |
| 205 | wp_cache_set( 'notoptions', $notoptions, 'options' ); |
| 206 | |
| 207 | /** This filter is documented in wp-includes/option.php */ |
| 208 | return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default ); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | } else { |
| 213 | $suppress = $wpdb->suppress_errors(); |
| 214 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
| 215 | $wpdb->suppress_errors( $suppress ); |
| 216 | |
| 217 | if ( is_object( $row ) ) { |
| 218 | $value = $row->option_value; |
| 219 | } else { |
| 220 | /** This filter is documented in wp-includes/option.php */ |
| 221 | return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default ); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | // If home is not set, use siteurl. |
| 226 | if ( 'home' === $option && '' === $value ) { |
| 227 | return get_option( 'siteurl' ); |
| 228 | } |
| 229 | |
| 230 | if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) { |
| Line | Code |
| 794 | * unnecessary database calls for otherwise identical object instances. |
| 795 | * |
| 796 | * See https://core.trac.wordpress.org/ticket/38903 |
| 797 | */ |
| 798 | if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
| 799 | return false; |
| 800 | } |
| 801 | |
| 802 | /** This filter is documented in wp-includes/option.php */ |
| 803 | if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) { |
| 804 | // Default setting for new options is 'yes'. |
| 805 | if ( null === $autoload ) { |
| 806 | $autoload = 'yes'; |
| 807 | } |
| 808 | |
| 809 | return add_option( $option, $value, '', $autoload ); |
| 810 | } |
| 811 | |
| 812 | $serialized_value = maybe_serialize( $value ); |
| Line | Code |
| 979 | |
| 980 | /* |
| 981 | * Make sure the option doesn't already exist. |
| 982 | * We can check the 'notoptions' cache before we ask for a DB query. |
| 983 | */ |
| 984 | $notoptions = wp_cache_get( 'notoptions', 'options' ); |
| 985 | |
| 986 | if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { |
| 987 | /** This filter is documented in wp-includes/option.php */ |
| 988 | if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) { |
| 989 | return false; |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | $serialized_value = maybe_serialize( $value ); |
| 994 | $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; |
| 995 | |
| 996 | /** |
| 997 | * Fires before an option is added. |