Skip to content

Commit

Permalink
Compat: Force updated post status from auto-draft to draft
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jul 29, 2019
1 parent d87bef8 commit f5748c0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,23 @@ function gutenberg_safe_style_css_column_flex_basis( $attr ) {
return $attr;
}
add_filter( 'safe_style_css', 'gutenberg_safe_style_css_column_flex_basis' );

/**
* Filters inserted post data to update an existing post's status to draft if
* currently an auto-draft. This is intended to ensure that a post which is
* explicitly updated should no longer be subjected to auto-draft purge.
*
* @param array $data An array of slashed post data.
* @param array $postarr An array of sanitized, but otherwise unmodified post
* data.
*
* @return array Filtered post data.
*/
function gutenberg_update_post_autodraft_to_draft( $data, $postarr ) {
if ( ! empty( $postarr['ID'] ) && $postarr['post_status'] === 'auto-draft' ) {
$data['post_status'] = 'draft';
}

return $data;
}
add_filter( 'wp_insert_post_data', 'gutenberg_update_post_autodraft_to_draft', 10, 2 );

0 comments on commit f5748c0

Please sign in to comment.