Skip to content

Commit

Permalink
Editor: Move auto-draft status change to the server. (#16814)
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras authored and gziolo committed Aug 29, 2019
1 parent c811938 commit 3e835ad
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,32 @@ 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 unset any auto-draft assigned post title. The status
* of an auto-draft should be read from its `post_status` and not inferred via its
* title. A post with an explicit title should be created with draft status, not
* with auto-draft status. It will also 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 subject to auto-draft purge.
*
* @see https://core.trac.wordpress.org/ticket/43316#comment:88
* @see https://core.trac.wordpress.org/ticket/43316#comment:89
*
* @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_filter_wp_insert_post_data( $data, $postarr ) {
if ( 'auto-draft' === $postarr['post_status'] ) {
if ( ! empty( $postarr['ID'] ) ) {
$data['post_status'] = 'draft';
} else {
$data['post_title'] = '';
}
}
return $data;
}
add_filter( 'wp_insert_post_data', 'gutenberg_filter_wp_insert_post_data', 10, 2 );

0 comments on commit 3e835ad

Please sign in to comment.