Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#38930 closed defect (bug) (fixed)

Warning Raised when checking option exists

Reported by: lucasstark's profile lucasstark Owned by: ocean90's profile ocean90
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.7
Component: Options, Meta APIs Keywords: needs-testing has-patch commit dev-reviewed
Focuses: Cc:


A warning will be raised inside of option.php, check_default_option when the following code is called on line 420.

// Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
        $notoptions = wp_cache_get( 'notoptions', 'options' );
        if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) )
                /** This filter is documented in wp-includes/option.php */
                if ( apply_filters( 'default_option_' . $option, false, $option ) !== get_option( $option ) )
                        return false;

The default_option filter expects three arguments, only two are passed here.

Attachments (1)

38930.diff (1.4 KB) - added by joehoyle 7 years ago.

Download all attachments as: .zip

Change History (11)

#1 @dd32
7 years ago

  • Keywords needs-testing added
  • Milestone changed from Awaiting Review to 4.7

Pushing into 4.7 for review, as the 3rd parameter was added in 4.7 (on 3 of the 5 instances of the filter) & the warning may be coming from filter_default_option().

@lucasstark Can you give any more information over what option calls are triggering it for you?

#2 @lucasstark
7 years ago

I am using the REST API and a custom endpoint to allow users to create / manage sites inside of a multisite. Inside of my sites custom endpoint I have a create method, where I call the following:

$current_site_id = wpmu_create_blog( $prepared_data->domain, $prepared_data->path, $prepared_data->title, get_current_user_id(), array( 'public' => 1 ), 1 );

When I call that function it raises the warning when the filter "default_option_WPLANG" is applied.

#3 @lucasstark
7 years ago

The warning is coming from filter_default_option yes, since it get's called though the applying of the filter, default_option_WPLANG

7 years ago

#4 @joehoyle
7 years ago

Added a patch to pass the 3rd arg to the filter. This arg is "Was the default value passed by the caller" which is used to choose if the register_setting default should override the the false default. In this case, like update_option, it should.

I added a unit test for this rather specific case where alloptions is not loaded, which before the patch will fail from a notice.

This ticket was mentioned in Slack in #core by joehoyle. View the logs.

7 years ago

#6 @swissspidy
7 years ago

  • Keywords has-patch commit added

#7 @ocean90
7 years ago

  • Keywords dev-reviewed added

38930.diff looks good.

This ticket was mentioned in Slack in #core by helen. View the logs.

7 years ago

#9 @ocean90
7 years ago

  • Owner set to ocean90
  • Resolution set to fixed
  • Status changed from new to closed

In 39382:

Options: Pass the $passed_default parameter to the 'default_option_{$option} filter in add_option().

This was missed in [38910].

Props joehoyle, lucasstark.
See #38176.
Fixes #38930.

#10 @ocean90
7 years ago

In 39383:

Options: Pass the $passed_default parameter to the default_option_{$option} filter in add_option().

This was missed in [38910].

Merge of [39382] to the 4.7 branch.

Props joehoyle, lucasstark.
See #38176, #38930.

Note: See TracTickets for help on using tickets.