Index: www/wp-includes/class-wp-post-type.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- www/wp-includes/class-wp-post-type.php	(revision d8cd020a37f8d18df3fa6540b5dd75ad93aee24e)
+++ www/wp-includes/class-wp-post-type.php	(date 1584114029066)
@@ -360,6 +360,14 @@
 	 *                                Default empty array.
 	 */
 	public function __construct( $post_type, $args = array() ) {
+		// Sanitize post type name
+		$post_type = sanitize_key( $post_type );
+
+		if ( empty( $post_type ) || strlen( $post_type ) > 20 ) {
+			_doing_it_wrong( __METHOD__, __( '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.' ) );
+		}
+
 		$this->name = $post_type;
 
 		$this->set_props( $args );
@@ -728,4 +736,66 @@
 
 		return $this->rest_controller;
 	}
+
+	public function unregister() {
+		global $wp_post_types;
+
+		// Do not allow unregistering internal post types.
+		if ( $this->_builtin ) {
+			return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) );
+		}
+
+		if ( $removed = post_type_exists( $this->name ) ) {
+			$this->remove_supports();
+			$this->remove_rewrite_rules();
+			$this->unregister_meta_boxes();
+			$this->remove_hooks();
+			$this->unregister_taxonomies();
+			unset( $wp_post_types[ $this->name ] );
+		}
+
+		/**
+		 * Fires after a post type was unregistered.
+		 *
+		 * @since 4.5.0
+		 *
+		 * @param string $post_type Post type key.
+		 * @param bool $removed True if the post type 'existed' and was removed, false otherwise
+		 */
+		do_action( 'unregistered_post_type', $this->name, $removed );
+
+		return true;
+
+	}
+
+	public function register() {
+		global $wp_post_types;
+
+		if ( ! is_array( $wp_post_types ) ) {
+			$wp_post_types = array();
+		}
+
+		$this->add_supports();
+		$this->add_rewrite_rules();
+		$this->register_meta_boxes();
+
+		$wp_post_types[ $this->name ] = $this;
+
+		$this->add_hooks();
+		$this->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', $this->name, $this );
+
+		return $this;
+	}
+
 }
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 1584114190325)
@@ -1403,42 +1403,8 @@
  * @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 $post_type_object->register();
 }
 
 /**
@@ -1460,31 +1426,7 @@
 		return new WP_Error( 'invalid_post_type', __( 'Invalid post type.' ) );
 	}
 
-	$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 get_post_type_object( $post_type )->unregister();
 }
 
 /**
