[wp-trac] [WordPress Trac] #39953: REST API: Add `date_floating` flag for posts

WordPress Trac noreply at wordpress.org
Sun Sep 16 19:50:11 UTC 2018


#39953: REST API: Add `date_floating` flag for posts
------------------------------------------+-----------------------
 Reporter:  jnylen0                       |       Owner:  (none)
     Type:  enhancement                   |      Status:  new
 Priority:  normal                        |   Milestone:  5.0
Component:  REST API                      |     Version:  4.7
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:  rest-api
------------------------------------------+-----------------------

Comment (by kadamwhite):

 I support @TimothyBlynJacobs' most recent proposal to assume a floating
 date when `date` and `modified_date` are the same. The edge-case where the
 date is manually set to the _exact second_ you save a draft feels like an
 acceptably minimal risk, and I'm still strongly opposed to forcing a new
 property onto a response that only accomplishes the same result as a
 simple equality check.

 In Gutenberg we do not actually pass a `date` field on save unless a date
 has been manually set, so I believe the code to handle this implementation
 would be as simple as this:

 {{{#!diff
 +function isFloatingDate( { date, modified, status } ) {
 +       if ( status === 'draft' || status === 'auto-draft' ) {
 +               return date === modified;
 +       }
 +       return false;
 +}

 -function PostScheduleLabel( { date } ) {
 +function PostScheduleLabel( props ) {
 +       const { date } = props;
 +       const floating = isFloatingDate( props );
         const settings = getSettings();
 -       return date ?
 +       return date && ! floating ?
                 dateI18n( settings.formats.datetime, date ) :
                 __( 'Immediately' );
  }
 @@ -15,5 +24,7 @@ function PostScheduleLabel( { date } ) {
  export default withSelect( ( select ) => {
         return {
                 date: select( 'core/editor' ).getEditedPostAttribute(
 'date' ),
 +               modified: select( 'core/editor' ).getEditedPostAttribute(
 'modified' ),
 +               status: select( 'core/editor' ).getEditedPostAttribute(
 'status' ),
         };
  } )( PostScheduleLabel );
 }}}

 We would indeed still need to update our item preparation code to make the
 same assumption if a date and modified value _are_ passed back to the
 server in the response, but that should also be a similar patch.

 I think this is the right way forward. Thank you @TimothyBlynJacobs and
 @earnjam for thinking through it so thoroughly!

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


More information about the wp-trac mailing list