最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

save post - wp_insert_post_data filter not working correctly after upgrade to Wordpress 5

matteradmin9PV0评论

I have the following code in a project.

function vb_post_modified_date_update($data, $postarr) {  
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )   
      return;  

    if (!empty($postarr['vb_modified_date_switch'])) {  
        $data['post_modified'] = $postarr['post_modified'];  
        $data['post_modified_gmt'] = $postarr['post_modified_gmt'];  
    }  

    return $data;  
}  

add_filter( 'wp_insert_post_data', 'vb_post_modified_date_update', '99', 2 ); 

What this used to do (it worked before upgrading to Wordpress 5), is to keep the old value on post_modified and post_modified_gmt fields when saving the post and a checkbox (vb_modified_date_switch) is checked in the post editor.

According documentation of wp_insert_post_data, $data should have the post data and $postarr should have the unmodified post data. However, debuging, I found that both variables have the same post data (modified data), so now I cant get the original post_modified and post_modified_gmt.

Is there any other way I can change the post data before is saved?

Thanks

Post a comment

comment list (0)

  1. No comments so far