[wp-trac] [WordPress Trac] #41099: update_option return value ambiguous

WordPress Trac noreply at wordpress.org
Mon Jun 19 20:58:49 UTC 2017


#41099: update_option return value ambiguous
--------------------------------+-----------------------------
 Reporter:  cloughit            |      Owner:
     Type:  enhancement         |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Options, Meta APIs  |    Version:  4.8
 Severity:  normal              |   Keywords:
  Focuses:                      |
--------------------------------+-----------------------------
 WordPress 4.8

 The return value 'false' does not allow for differentiating if there was
 an error saving or if the option value already exists and is the same as
 the new value.

 Consider this scenario: a plugin sends option values via AJAX to be
 updated. The AJAX function returns the return value of 'update_option'
 which determines the feedback provided to the user, such as a 'success' or
 'failure' message.

 Rather than returning 'false' if an option already exists and is the same
 as the new option, I suggest returning NULL.  In this way the return value
 of 'update_option' can be checked as follows:

 {{{#!php
 if ( is_null( update_option( $option, $value, $autoload) ) ) { ... } //
 option exists and value is the same as existing option value
 if ( false === update_option( $option, $value, $autoload) ) { ... } // an
 error occured when saving the option
 if ( update_option( $option, $value, $autoload) ) { ... } // option
 updated successfully
 }}}

 The 'update_option' function would need line 308 changed from:

 {{{#!php
 return false;
 }}}

 to:

 {{{#!php
 return NULL;
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41099>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list