$postarr['post_status'
] = 'auto-draft';
// Auto-drafts are allowed to have empty post_names, so it has to be explicitly set.
if ( empty( $postarr['post_name'
] ) ) { $postarr['post_name'
] =
sanitize_title( $postarr['post_title'
] );
} if ( !
isset( $postarr['meta_input'
] ) ) { $postarr['meta_input'
] = array
();
} $postarr['meta_input'
]['_customize_draft_post_name'
] =
$postarr['post_name'
];
$postarr['meta_input'
]['_customize_changeset_uuid'
] =
$this->manager->
changeset_uuid();
unset( $postarr['post_name'
] );
add_filter( 'wp_insert_post_empty_content', '__return_false', 1000
);
$r =
wp_insert_post( wp_slash( $postarr ), true
);
remove_filter( 'wp_insert_post_empty_content', '__return_false', 1000
);
if ( is_wp_error( $r ) ) { return $r;
} else { return get_post( $r );
} }