[wp-trac] [WordPress Trac] #59610: Post modified date cannot be updated through WP-CLI

WordPress Trac noreply at wordpress.org
Fri Oct 13 19:50:32 UTC 2023


#59610: Post modified date cannot be updated through WP-CLI
-----------------------------------+------------------------------
 Reporter:  shreyasikhar26         |       Owner:  (none)
     Type:  defect (bug)           |      Status:  new
 Priority:  normal                 |   Milestone:  Awaiting Review
Component:  Posts, Post Types      |     Version:  6.3.3
 Severity:  normal                 |  Resolution:
 Keywords:  has-patch 2nd-opinion  |     Focuses:
-----------------------------------+------------------------------

Comment (by brianhenryie):

 As I recall, it never worked that way.

 There's a similar patch in #41227, closed in favour of #36595.

 The behaviour of `wp_update_post()` (which is used by `wp post update`) is
 to always update the modified date to `current_time()` (inside
 `wp_insert_post()`).

 The question then: should `wp_post_update()` always change post modified
 to the current time, or should it respect the `post_modified` values
 passed?

 I expect this ticket will be closed in favor of the one mentioned.

 But to discuss in the context of WP CLI...

 What I have done in plugins in the past is:

 {{{#!php
 <?php
 /**
  * Don't change the last modified time.
  *
  * @see https://wordpress.stackexchange.com/questions/237878/how-to-
 prevent-wordpress-from-updating-the-modified-time
  *
  * @param array $new_post A WP_Post array.
  * @param array $old A WP_Post array.
  * @return array
  */
 $stop_modified_date_update = function ( $new_post, $old ) {
         $new_post['post_modified']     = $old['post_modified'];
         $new_post['post_modified_gmt'] = $old['post_modified_gmt'];
         return $new_post;
 };
 add_filter( 'wp_insert_post_data', $stop_modified_date_update, 10, 2 );

 }}}


 For WP CLI, it makes sense to either implement a function similar to that
 which does make the `--post_modified=` parameter take effect, or to warn
 users that it will do nothing.

 Overall, I favour the core `wp_update_post()` function respecting the
 `post_modified` value, which should mean no changes needed in WP CLI.

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


More information about the wp-trac mailing list