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
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
911       * unnecessary database calls for otherwise identical object instances.
912       *
913       * See https://core.trac.wordpress.org/ticket/38903
914       */
915      if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {
916           return false;
917      }
918
919      /** This filter is documented in wp-includes/option.php */
920      if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) {
921           return add_option( $option, $value, '', $autoload );
922      }
923
924      $serialized_value = maybe_serialize( $value );
925
926      /**
927       * Fires immediately before an option value is updated.
928       *
929       * @since 2.9.0
 
Line Code
1106
1107      /*
1108       * Make sure the option doesn't already exist.
1109       * We can check the 'notoptions' cache before we ask for a DB query.
1110       */
1111      $notoptions = wp_cache_get( 'notoptions', 'options' );
1112
1113      if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) {
1114           /** This filter is documented in wp-includes/option.php */
1115           if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) {
1116                return false;
1117           }
1118      }
1119
1120      $serialized_value = maybe_serialize( $value );
1121
1122      $autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload );
1123
1124      /**