[wp-trac] [WordPress Trac] #48363: Empty string in database for boolean meta not cast to false

WordPress Trac noreply at wordpress.org
Fri Oct 18 00:09:45 UTC 2019


#48363: Empty string in database for boolean meta not cast to false
----------------------------+-----------------------------
 Reporter:  chrisvanpatten  |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  REST API        |    Version:  trunk
 Severity:  normal          |   Keywords:
  Focuses:  rest-api        |
----------------------------+-----------------------------
 In WordPress 5.3 RC1, when registering post meta as a boolean and saving a
 {{{false}}} value via the REST API, it is persisted to the database as an
 empty string, but the empty string is not cast back to {{{false}}} on
 output, and is instead rendered in the API as {{{null}}}.

 {{{
 <?php

 register_meta(
         'post',
         'my_meta_key',
         [
                 'type'         => 'boolean',
                 'single'       => true,
                 'show_in_rest' => true,
         ]
 );
 }}}

 Expected in API:

 {{{
 ...
 "meta": {
     "my_meta_key": false
 }
 ...
 }}}

 Actual:

 {{{
 ...
 "meta": {
     "my_meta_key": null
 }
 ...
 }}}

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


More information about the wp-trac mailing list