Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

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.

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 5 times in this file.

Line Code
63                 * The dynamic portion of the hook name, `$option`, refers to the option name.
64                 *
65                 * @since 3.4.0
66                 * @since 4.4.0 The `$option` parameter was added.
67                 *
68                 * @param mixed  $default The default value to return if the option does not exist
69                 *                        in the database.
70                 * @param string $option  Option name.
71                 */
72                return apply_filters( 'default_option_' . $option, $default, $option );
73           }
74
75           $alloptions = wp_load_alloptions();
76
77           if ( isset( $alloptions[$option] ) ) {
78                $value = $alloptions[$option];
79           } else {
80                $value = wp_cache_get( $option, 'options' );
81
 
Line Code
88                          wp_cache_add( $option, $value, 'options' );
89                     } else { // option does not exist, so we must cache its non-existence
90                          if ( ! is_array( $notoptions ) ) {
91                                $notoptions = array();
92                          }
93                          $notoptions[$option] = true;
94                          wp_cache_set( 'notoptions', $notoptions, 'options' );
95
96                          /** This filter is documented in wp-includes/option.php */
97                          return apply_filters( 'default_option_' . $option, $default, $option );
98                     }
99                }
100           }
101      } else {
102           $suppress = $wpdb->suppress_errors();
103           $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
104           $wpdb->suppress_errors( $suppress );
105           if ( is_object( $row ) ) {
106                $value = $row->option_value;
107           } else {
108                /** This filter is documented in wp-includes/option.php */
109                return apply_filters( 'default_option_' . $option, $default, $option );
110           }
111      }
112
113      // If home is not set use siteurl.
114      if ( 'home' == $option && '' == $value )
115           return get_option( 'siteurl' );
116
117      if ( in_array( $option, array('siteurl', 'home', 'category_base', 'tag_base') ) )
118           $value = untrailingslashit( $value );
 
Line Code
286       * @param mixed  $old_value The old option value.
287       */
288      $value = apply_filters( 'pre_update_option', $value, $option, $old_value );
289
290      // If the new and old values are the same, no need to update.
291      if ( $value === $old_value )
292           return false;
293
294      /** This filter is documented in wp-includes/option.php */
295      if ( apply_filters( 'default_option_' . $option, false ) === $old_value ) {
296           // Default setting for new options is 'yes'.
297           if ( null === $autoload ) {
298                $autoload = 'yes';
299           }
300
301           return add_option( $option, $value, '', $autoload );
302      }
303
304      $serialized_value = maybe_serialize( $value );
 
Line Code
407      if ( is_object($value) )
408           $value = clone $value;
409
410      $value = sanitize_option( $option, $value );
411
412      // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
413      $notoptions = wp_cache_get( 'notoptions', 'options' );
414      if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) )
415           /** This filter is documented in wp-includes/option.php */
416           if ( apply_filters( 'default_option_' . $option, false ) !== get_option( $option ) )
417                return false;
418
419      $serialized_value = maybe_serialize( $value );
420      $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
421
422      /**
423       * Fires before an option is added.
424       *
425       * @since 2.9.0