Make WordPress Core


Ignore:
Timestamp:
05/16/2017 05:36:25 AM (7 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r39638 r40676  
    979979    }
    980980}
     981
     982/**
     983 * Delete auto-draft posts associated with the supplied changeset.
     984 *
     985 * @since 4.8.0
     986 * @access private
     987 *
     988 * @param int $post_id Post ID for the customize_changeset.
     989 */
     990function _wp_delete_customize_changeset_dependent_auto_drafts( $post_id ) {
     991    $post = get_post( $post_id );
     992
     993    if ( ! $post || 'customize_changeset' !== $post->post_type ) {
     994        return;
     995    }
     996
     997    $data = json_decode( $post->post_content, true );
     998    if ( empty( $data['nav_menus_created_posts']['value'] ) ) {
     999        return;
     1000    }
     1001    remove_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
     1002    foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
     1003        if ( ! empty( $post_id ) && 'auto-draft' === get_post_status( $post_id ) ) {
     1004            wp_delete_post( $post_id, true );
     1005        }
     1006    }
     1007    add_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
     1008}
Note: See TracChangeset for help on using the changeset viewer.