wp_insert_post_data filter not working correctly after upgrade to Wordpress 5

by Vallel   Last Updated December 12, 2018 19:08 PM

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



Related Questions



Stripping URLs & Email from post submissions

Updated May 22, 2017 08:08 AM

Wordpress 4.9.8 doesn't save if content has style="

Updated October 29, 2018 16:08 PM

Can't save changes after migration/domain change

Updated April 16, 2019 14:08 PM

save_post affect creation and deletion

Updated October 11, 2017 14:08 PM