[wp-trac] [WordPress Trac] #43559: wp_ajax_add_meta() does not allow empty values

WordPress Trac noreply at wordpress.org
Fri Mar 16 17:22:35 UTC 2018


#43559: wp_ajax_add_meta() does not allow empty values
--------------------------------+------------------------------
 Reporter:  charlestonsw        |       Owner:
     Type:  enhancement         |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Options, Meta APIs  |     Version:  trunk
 Severity:  normal              |  Resolution:
 Keywords:  reporter-feedback   |     Focuses:  rest-api
--------------------------------+------------------------------

Comment (by charlestonsw):

 Sorry - late night coding.

 Same thing happens for values... copied the wrong code block.


 {{{
                 if ( '' == trim($value) )
                         wp_die( __( 'Please provide a custom field value.'
 ) );
 }}}


 To reproduce:

 Create a custom post type (probably not necessary based on the code from
 WP Core).
 Add Custom Field.
 Enter a key, "test".
 Leave value empty.
 Save.

 You'll get the error above in the notification box.

 So you have no way to add a custom field with a blank value.

 I have a JS listener that does a standard WP REST call to fetch the post
 with full meta.     I use this to remotely configure plugins, so if a
 setting for a text field, call it "Search Box Title" should be set to
 BLANK I cannot do this.     I am now sending   and in the listener I
 then have to do if $json_data[ 'search_box_title' ] === ' '
 $json_data['search_box_title']='';

 Not I cannot set my "custom_html' setting to  

 Granted that is unlikely to happen in my particular instance but this is a
 notable shortcoming in the custom fields/post meta.

 I'd much rather use core REST functionality and send back a standard
 response and consume the meta fields with a reactive app than have to use
 custom settings and document for my clients "well, if you really want to
 set that value to blank enter   as the value in the field".     Only
 code geeks will even know why I used that when really I wanted them to be
 able to turn the search box title OFF completely setting it from the
 default 'Enter Your Search Parameters' to '' and skipping the header
 rendering entirely.

 Same premise as above, swap the word 'key' with 'value'.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/43559#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list