WordPress.org

Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#49566 reviewing enhancement

Change comment on `update_blog_option` to properly describe the return value

Reported by: andfinally Owned by: SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version: trunk
Component: Options, Meta APIs Keywords: has-patch
Focuses: docs Cc:

Description

update_blog_option uses update_option to set options, and that function doesn't only return false if there's an error: it can also return false if the value of the option hasn't changed.

Reading the comment on update_blog_option, you're liable to assume false always means a failure, and make mistakes like:

if ( false === update_blog_option( 9, 'import_id', 1 ) {
    return new WP_Error( 
        // error data
    );
} 

In this situation, every attempt to update an option that already has the value '1' will be treated as an error.

Attachments (2)

Update_description_of_return_value_.patch (710 bytes) - added by andfinally 4 weeks ago.
Update_description_of_return_value_2.patch (704 bytes) - added by andfinally 4 weeks ago.
Using the same return description as update_option.

Download all attachments as: .zip

Change History (5)

#1 @david.binda
4 weeks ago

The update_option function, which return value is used directly as output from the update_blog_option function, uses following:

@return bool False if value was not updated and true if value was updated.

Perhaps we could make those the same, since the update_blog_option is kind of a wrapper around the update_option?

If even that does not make it clear enough, we, IMHO, should update it in both places.

#2 @SergeyBiryukov
4 weeks ago

  • Milestone changed from Awaiting Review to 5.5
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

@andfinally
4 weeks ago

Using the same return description as update_option.

#3 @andfinally
4 weeks ago

Thanks, good point – I've attached Update_description_of_return_value_2.patch with that wording instead.

Note: See TracTickets for help on using tickets.