_wp_delete_customize_changeset_dependent_auto_drafts

The timeline below displays how wordpress function _wp_delete_customize_changeset_dependent_auto_drafts has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Deletes 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 $stub_post_id) {
        if (empty($stub_post_id)) {
            continue;
        }
        if ('auto-draft' === get_post_status($stub_post_id)) {
            wp_delete_post($stub_post_id, true);
        } elseif ('draft' === get_post_status($stub_post_id)) {
            wp_trash_post($stub_post_id);
            delete_post_meta($stub_post_id, '_customize_changeset_uuid');
        }
    }
    add_action('delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts');
}

WordPress Version: 4.9

/**
 * 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 $stub_post_id) {
        if (empty($stub_post_id)) {
            continue;
        }
        if ('auto-draft' === get_post_status($stub_post_id)) {
            wp_delete_post($stub_post_id, true);
        } elseif ('draft' === get_post_status($stub_post_id)) {
            wp_trash_post($stub_post_id);
            delete_post_meta($stub_post_id, '_customize_changeset_uuid');
        }
    }
    add_action('delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts');
}

WordPress Version: 4.8

/**
 * 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');
}