Index: www/wp-includes/post.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- www/wp-includes/post.php	(revision d8cd020a37f8d18df3fa6540b5dd75ad93aee24e)
+++ www/wp-includes/post.php	(date 1584216267149)
@@ -1403,42 +1403,10 @@
  * @return WP_Post_Type|WP_Error The registered post type object, or an error object.
  */
 function register_post_type( $post_type, $args = array() ) {
-	global $wp_post_types;
-
-	if ( ! is_array( $wp_post_types ) ) {
-		$wp_post_types = array();
-	}
-
-	// Sanitize post type name
-	$post_type = sanitize_key( $post_type );
-
-	if ( empty( $post_type ) || strlen( $post_type ) > 20 ) {
-		_doing_it_wrong( __FUNCTION__, __( 'Post type names must be between 1 and 20 characters in length.' ), '4.2.0' );
-		return new WP_Error( 'post_type_length_invalid', __( 'Post type names must be between 1 and 20 characters in length.' ) );
-	}
-
 	$post_type_object = new WP_Post_Type( $post_type, $args );
-	$post_type_object->add_supports();
-	$post_type_object->add_rewrite_rules();
-	$post_type_object->register_meta_boxes();
-
-	$wp_post_types[ $post_type ] = $post_type_object;
-
-	$post_type_object->add_hooks();
-	$post_type_object->register_taxonomies();
-
-	/**
-	 * Fires after a post type is registered.
-	 *
-	 * @since 3.3.0
-	 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
-	 *
-	 * @param string       $post_type        Post type.
-	 * @param WP_Post_Type $post_type_object Arguments used to register the post type.
-	 */
-	do_action( 'registered_post_type', $post_type, $post_type_object );
-
-	return $post_type_object;
+	return is_null($post_type_object->last_error)
+		? $post_type_object->register()
+		: $post_type_object->last_error;
 }
 
 /**
@@ -1462,29 +1430,9 @@
 
 	$post_type_object = get_post_type_object( $post_type );
 
-	// Do not allow unregistering internal post types.
-	if ( $post_type_object->_builtin ) {
-		return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) );
-	}
-
-	$post_type_object->remove_supports();
-	$post_type_object->remove_rewrite_rules();
-	$post_type_object->unregister_meta_boxes();
-	$post_type_object->remove_hooks();
-	$post_type_object->unregister_taxonomies();
-
-	unset( $wp_post_types[ $post_type ] );
-
-	/**
-	 * Fires after a post type was unregistered.
-	 *
-	 * @since 4.5.0
-	 *
-	 * @param string $post_type Post type key.
-	 */
-	do_action( 'unregistered_post_type', $post_type );
-
-	return true;
+	return ! $post_type_object->unregister()
+		? $post_type_object->last_error
+		: true;
 }
 
 /**
