_wp_delete_customize_changeset_dependent_auto_drafts

函数
_wp_delete_customize_changeset_dependent_auto_drafts ( $post_id )
Access
Private
参数
  • (int) $post_id Post ID for the customize_changeset.
    Required:
定义位置
相关方法
_wp_keep_alive_customize_changeset_dependent_auto_drafts_wp_customize_changeset_filter_insert_post_datawp_delete_auto_drafts_wp_customize_publish_changeset_wp_delete_orphaned_draft_menu_items
引入
4.8.0
弃用
-

_wp_delete_customize_changeset_dependent_auto_drafts: 这个函数用来删除在WordPress定制器中创建变化集时创建的自动草稿: 当用户开始在定制器中进行修改时,会自动创建一个修改集的草稿版本: 当这些草稿不再需要时,这个函数就会删除它们。

删除与提供的更改集相关的自动起草的文章。

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

常见问题

FAQs
查看更多 >