mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-04 14:47:02 +00:00
Customize: Keep alive auto-drafts created for page/post stubs when parent changeset is updated, and delete when changeset is garbage-collected.
Props utkarshpatel, westonruter. See #31089. Fixes #39715. git-svn-id: https://develop.svn.wordpress.org/trunk@40676 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -978,3 +978,31 @@ function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) {
|
||||
wp_update_nav_menu_item( $menu_id, 0, $args );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete auto-draft posts associated with the supplied changeset.
|
||||
*
|
||||
* @since 4.8.0
|
||||
* @access private
|
||||
*
|
||||
* @param int $post_id Post ID for the customize_changeset.
|
||||
*/
|
||||
function _wp_delete_customize_changeset_dependent_auto_drafts( $post_id ) {
|
||||
$post = get_post( $post_id );
|
||||
|
||||
if ( ! $post || 'customize_changeset' !== $post->post_type ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = json_decode( $post->post_content, true );
|
||||
if ( empty( $data['nav_menus_created_posts']['value'] ) ) {
|
||||
return;
|
||||
}
|
||||
remove_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
|
||||
foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
|
||||
if ( ! empty( $post_id ) && 'auto-draft' === get_post_status( $post_id ) ) {
|
||||
wp_delete_post( $post_id, true );
|
||||
}
|
||||
}
|
||||
add_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user