[wp-trac] [WordPress Trac] #54020: Add a filter to allow updating post without changing the modified dates

WordPress Trac noreply at wordpress.org
Mon Aug 30 09:04:19 UTC 2021


#54020: Add a filter to allow updating post without changing the modified dates
-------------------------------------------------+-------------------------
 Reporter:  pbearne                              |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Posts, Post Types                    |     Version:  trunk
 Severity:  normal                               |  Resolution:
 Keywords:  has-unit-tests has-dev-note dev-     |     Focuses:
  feedback has-patch                             |
-------------------------------------------------+-------------------------

Comment (by kasparsd):

 > What kind of problem? The post was modified, even if it was by a batch
 job, so shouldn't it reflect that?

 There are many instances when `wp_update_post()` needs to be called
 without the intention of updating the actual post content:

 - changing the `comment_status` and `ping_status`,
 - changing the post slug,
 - changing the menu order,
 - changing the post parent.

 I feel like that's enough use-cases to provide a simple way to disable any
 changes to the `post_modified` and `post_modified_gmt` dates. For legacy
 reasons, it should default to the current behaviour but it would be nice
 to have a parameter flag or a filter to disable the date change behaviour.

 We already have the `edit_date` flag
 [https://core.trac.wordpress.org/browser/tags/5.8/src/wp-
 includes/post.php#L4537 to clear the date data for drafts], for example.

 Could we add a filter before the `if ( $update || '0000-00-00 00:00:00'
 === $post_date ) {` conditional that generates a date-specific update flag
 `$update_post_modified_date` based on a filter value?

 How about something like this:

 {{{#!php
 <?php
 $update_post_modified_date = apply_filters(
     'wp_insert_post_update_post_modified_date',
     ( $update || '0000-00-00 00:00:00' === $post_date ), // Default to the
 current logic.
     $postarr
 );

 if ( $update_post_modified_date ) {
     // ...
 }}}

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


More information about the wp-trac mailing list