[wp-trac] [WordPress Trac] #53942: Non-single post meta multiple value update breaks post save through REST API

WordPress Trac noreply at wordpress.org
Tue Aug 17 15:19:34 UTC 2021


#53942: Non-single post meta multiple value update breaks post save through REST
API
----------------------------+------------------------------
 Reporter:  iknowsomething  |       Owner:  (none)
     Type:  defect (bug)    |      Status:  assigned
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  REST API        |     Version:  5.8
 Severity:  blocker         |  Resolution:
 Keywords:  needs-patch     |     Focuses:  rest-api
----------------------------+------------------------------

Comment (by iknowsomething):

 Temporary workaround could use short-circuit filter in `delete_metadata()`
 and might look like this:

 {{{#!php
 <?php
 $meta_type = 'post';
 add_filter( "delete_{$meta_type}_metadata", 'skip_delete', 10, 3);

 function skip_delete( $delete, $object_id, $meta_key ) {
     // If it's not about this meta, forward previous hook result
     if ( $meta_key != $this->meta_key ) {
         return $delete;
     }

     // Skip delete if meta doesn't exist in database
     $current_meta_value = get_metadata_raw( $meta_type = 'post',
 $object_id, wp_slash( $meta_key ) );
     if ( null === $current_meta_value ) {
         return true;
     }

     // Do not skip on all other cases
     return null;
 }
 }}}

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


More information about the wp-trac mailing list