diff --git src/wp-includes/customize/class-wp-customize-custom-css-setting.php src/wp-includes/customize/class-wp-customize-custom-css-setting.php
index eadd47c..f0c11b7 100644
--- src/wp-includes/customize/class-wp-customize-custom-css-setting.php
+++ src/wp-includes/customize/class-wp-customize-custom-css-setting.php
@@ -287,27 +287,13 @@ final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting {
 		$args = apply_filters( 'customize_update_custom_css_post_content_args', $args, $css, $setting );
 		$args = wp_array_slice_assoc( $args, array( 'post_content', 'post_content_filtered' ) );
 
-		$args = array_merge(
-			$args,
-			array(
-				'post_title' => $this->stylesheet,
-				'post_name' => sanitize_title( $this->stylesheet ),
-				'post_type' => 'custom_css',
-				'post_status' => 'publish',
-			)
-		);
+		$args['stylesheet'] = $this->stylesheet;
+		$r = wp_update_custom_css_post( $args );
 
-		// Update post if it already exists, otherwise create a new one.
-		$post = wp_get_custom_css_post( $this->stylesheet );
-		if ( $post ) {
-			$args['ID'] = $post->ID;
-			$post_id = wp_update_post( wp_slash( $args ) );
-		} else {
-			$post_id = wp_insert_post( wp_slash( $args ) );
-		}
-		if ( ! $post_id ) {
+		if ( $r instanceof WP_Error ) {
 			return false;
 		}
+		$post_id = $r->ID;
 
 		// Cache post ID in theme mod for performance to avoid additional DB query.
 		if ( $this->manager->get_stylesheet() === $this->stylesheet ) {
diff --git src/wp-includes/theme.php src/wp-includes/theme.php
index eea50a5..69c5665 100644
--- src/wp-includes/theme.php
+++ src/wp-includes/theme.php
@@ -1708,6 +1708,55 @@ function wp_get_custom_css( $stylesheet = '' ) {
 }
 
 /**
+ * Update the `custom_css` post for a given theme.
+ *
+ * @since 4.7.0
+ * @access public
+ *
+ * @param array $args {
+ *     @type string $post_content          CSS.
+ *     @type string $post_content_filtered Pre-processed CSS. Normally empty string. Optional.
+ *     @type string $stylesheet            Stylesheet (child theme) to update.
+ * }
+ * @return WP_Post|WP_Error Post on success, error on failure.
+ */
+function wp_update_custom_css_post( $args ) {
+	$args = array_merge(
+		array(
+			'post_content' => '',
+			'post_content_filtered' => '',
+			'stylesheet' => get_stylesheet(),
+		),
+		$args
+	);
+
+	$args = array_merge(
+		$args,
+		array(
+			'post_title' => $args['stylesheet'],
+			'post_name' => sanitize_title( $args['stylesheet'] ),
+			'post_type' => 'custom_css',
+			'post_status' => 'publish',
+		)
+	);
+
+	// Update post if it already exists, otherwise create a new one.
+	$post = wp_get_custom_css_post( $args['stylesheet'] );
+	if ( $post ) {
+		$args['ID'] = $post->ID;
+		$r = wp_update_post( wp_slash( $args ), true );
+	} else {
+		$r = wp_insert_post( wp_slash( $args ), true );
+	}
+
+	if ( $r instanceof WP_Error ) {
+		return $r;
+	} else {
+		return get_post( $r );
+	}
+}
+
+/**
  * Add callback for custom TinyMCE editor stylesheets.
  *
  * The parameter $stylesheet is the name of the stylesheet, relative to
