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
190                      * @since 3.4.0
191                      * @since 4.4.0 The `$option` parameter was added.
192                      * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value.
193                      *
194                      * @param mixed  $default_value  The default value to return if the option does not exist
195                      *                               in the database.
196                      * @param string $option         Option name.
197                      * @param bool   $passed_default Was `get_option()` passed a default value?
198                      */
199                     return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
200                }
201
202                $value = wp_cache_get( $option, 'options' );
203
204                if ( false === $value ) {
205
206                     $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
207
208                     // Has to be get_row() instead of get_var() because of funkiness with 0, false, null values.
209                     if ( is_object( $row ) ) {
210                          $value = $row->option_value;
211                          wp_cache_add( $option, $value, 'options' );
212                     } else { // Option does not exist, so we must cache its non-existence.
213                          $notoptions[ $option ] = true;
214                          wp_cache_set( 'notoptions', $notoptions, 'options' );
215
216                          /** This filter is documented in wp-includes/option.php */
217                          return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
218                     }
219                }
220           }
221      } else {
222           $suppress = $wpdb->suppress_errors();
223           $row      = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
224           $wpdb->suppress_errors( $suppress );
225
226           if ( is_object( $row ) ) {
227                $value = $row->option_value;
228           } else {
229                /** This filter is documented in wp-includes/option.php */
230                return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
231           }
232      }
233
234      // If home is not set, use siteurl.
235      if ( 'home' === $option && '' === $value ) {
236           return get_option( 'siteurl' );
237      }
238
239      if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) {
 
Line Code
920       * unnecessary database calls for otherwise identical object instances.
921       *
922       * See https://core.trac.wordpress.org/ticket/38903
923       */
924      if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {
925           return false;
926      }
927
928      /** This filter is documented in wp-includes/option.php */
929      if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) {
930           return add_option( $option, $value, '', $autoload );
931      }
932
933      $serialized_value = maybe_serialize( $value );
934
935      /**
936       * Fires immediately before an option value is updated.
937       *
938       * @since 2.9.0
 
Line Code
1115
1116      /*
1117       * Make sure the option doesn't already exist.
1118       * We can check the 'notoptions' cache before we ask for a DB query.
1119       */
1120      $notoptions = wp_cache_get( 'notoptions', 'options' );
1121
1122      if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) {
1123           /** This filter is documented in wp-includes/option.php */
1124           if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) {
1125                return false;
1126           }
1127      }
1128
1129      $serialized_value = maybe_serialize( $value );
1130
1131      $autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload );
1132
1133      /**