#38930 closed defect (bug) (fixed)
Warning Raised when checking option exists
Reported by: | lucasstark | Owned by: | 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: |
Description
A warning will be raised inside of option.php, check_default_option when the following code is called on line 420.
<?php // 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)
Change History (11)
#2
@
8 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:
<?php $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
@
8 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
#4
@
8 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.
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?