Source View: default_option_{$option}

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

  • Action hooks look like this: do_action( "hook_name" )
  • Filter hooks look like this: 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.

Source View

This hook occurs 3 times in this file.

Line Code
42           return false;
43
44      if ( defined( 'WP_SETUP_CONFIG' ) )
45           return false;
46
47      if ( ! defined( 'WP_INSTALLING' ) ) {
48           // prevent non-existent options from triggering multiple queries
49           $notoptions = wp_cache_get( 'notoptions', 'options' );
50           if ( isset( $notoptions[$option] ) )
51                return apply_filters( 'default_option_' . $option, $default );
52
53           $alloptions = wp_load_alloptions();
54
55           if ( isset( $alloptions[$option] ) ) {
56                $value = $alloptions[$option];
57           } else {
58                $value = wp_cache_get( $option, 'options' );
59
60                if ( false === $value ) {
61                     $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
62
63                     // Has to be get_row instead of get_var because of funkiness with 0, false, null values
64                     if ( is_object( $row ) ) {
65                          $value = $row->option_value;
66                          wp_cache_add( $option, $value, 'options' );
67                     } else { // option does not exist, so we must cache its non-existence
68                          $notoptions[$option] = true;
69                          wp_cache_set( 'notoptions', $notoptions, 'options' );
70                          return apply_filters( 'default_option_' . $option, $default );
71                     }
72                }
73           }
74      } else {
75           $suppress = $wpdb->suppress_errors();
76           $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
77           $wpdb->suppress_errors( $suppress );
78           if ( is_object( $row ) )
79                $value = $row->option_value;
80           else
81                return apply_filters( 'default_option_' . $option, $default );
82      }
83
84      // If home is not set use siteurl.
85      if ( 'home' == $option && '' == $value )
86           return get_option( 'siteurl' );
87
88      if ( in_array( $option, array('siteurl', 'home', 'category_base', 'tag_base') ) )
89           $value = untrailingslashit( $value );
90