Index: src/wp-admin/edit.php
===================================================================
--- src/wp-admin/edit.php	(revision 37886)
+++ src/wp-admin/edit.php	(working copy)
@@ -23,8 +23,8 @@
 }
 
 /**
- * @global string $post_type
- * @global object $post_type_object
+ * @global string       $post_type
+ * @global WP_Post_Type $post_type_object
  */
 global $post_type, $post_type_object;
 
Index: src/wp-admin/includes/class-wp-posts-list-table.php
===================================================================
--- src/wp-admin/includes/class-wp-posts-list-table.php	(revision 37886)
+++ src/wp-admin/includes/class-wp-posts-list-table.php	(working copy)
@@ -72,8 +72,8 @@
 	 *
 	 * @see WP_List_Table::__construct() for more information on default arguments.
 	 *
-	 * @global object $post_type_object
-	 * @global wpdb   $wpdb
+	 * @global WP_Post_Type $post_type_object
+	 * @global wpdb         $wpdb
 	 *
 	 * @param array $args An associative array of arguments.
 	 */
Index: src/wp-admin/includes/nav-menu.php
===================================================================
--- src/wp-admin/includes/nav-menu.php	(revision 37886)
+++ src/wp-admin/includes/nav-menu.php	(working copy)
@@ -522,9 +522,9 @@
 				 *
 				 * @see WP_Query::query()
 				 *
-				 * @param array  $posts     The posts for the current post type.
-				 * @param array  $args      An array of WP_Query arguments.
-				 * @param object $post_type The current post type object for this menu item meta box.
+				 * @param array        $posts     The posts for the current post type.
+				 * @param array        $args      An array of WP_Query arguments.
+				 * @param WP_Post_Type $post_type The current post type object for this menu item meta box.
 				 */
 				$posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type );
 				$checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
Index: src/wp-includes/class-wp-post-type.php
===================================================================
--- src/wp-includes/class-wp-post-type.php	(revision 0)
+++ src/wp-includes/class-wp-post-type.php	(working copy)
@@ -0,0 +1,685 @@
+<?php
+/**
+ * Post API: WP_Post_Type class
+ *
+ * @package WordPress
+ * @subpackage Post
+ * @since 4.6.0
+ */
+
+/**
+ * Core class used for interacting with post types.
+ *
+ * @since 4.6.0
+ */
+final class WP_Post_Type {
+	/**
+	 * Post type key.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var string $name
+	 */
+	public $name;
+
+	/**
+	 * Name of the post type shown in the menu. Usually plural.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var string $label
+	 */
+	public $label;
+
+	/**
+	 * An array of labels for this post type.
+	 *
+	 * If not set, post labels are inherited for non-hierarchical types
+	 * and page labels for hierarchical ones.
+	 *
+	 * @see get_post_type_labels()
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var array $labels
+	 */
+	public $labels;
+
+	/**
+	 * A short descriptive summary of what the post type is.
+	 *
+	 * Default empty.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var string $description
+	 */
+	public $description = '';
+
+	/**
+	 * Whether a post type is intended for use publicly either via the admin interface or by front-end users.
+	 *
+	 * While the default settings of $exclude_from_search, $publicly_queryable, $show_ui, and $show_in_nav_menus
+	 * are inherited from public, each does not rely on this relationship and controls a very specific intention.
+	 *
+	 * Default false.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $public
+	 */
+	public $public = false;
+
+	/**
+	 * Whether the post type is hierarchical (e.g. page).
+	 *
+	 * Default false.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $hierarchical
+	 */
+	public $hierarchical = false;
+
+	/**
+	 * Whether to exclude posts with this post type from front end search
+	 * results.
+	 *
+	 * Default is the opposite value of $public.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $exclude_from_search
+	 */
+	public $exclude_from_search = null;
+
+	/**
+	 * Whether queries can be performed on the front end for the post type as part of `parse_request()`.
+	 *
+	 * Endpoints would include:
+	 * - `?post_type={post_type_key}`
+	 * - `?{post_type_key}={single_post_slug}`
+	 * - `?{post_type_query_var}={single_post_slug}`
+	 *
+	 * Default is the value of $public.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $publicly_queryable
+	 */
+	public $publicly_queryable = null;
+
+	/**
+	 * Whether to generate and allow a UI for managing this post type in the admin.
+	 *
+	 * Default is the value of $public.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $show_ui
+	 */
+	public $show_ui = null;
+
+	/**
+	 * Where to show the post type in the admin menu.
+	 *
+	 * To work, $show_ui must be true. If true, the post type is shown in its own top level menu. If false, no menu is
+	 * shown. If a string of an existing top level menu (eg. 'tools.php' or 'edit.php?post_type=page'), the post type
+	 * will be placed as a sub-menu of that.
+	 *
+	 * Default is the value of $show_ui.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $show_in_menu
+	 */
+	public $show_in_menu = null;
+
+	/**
+	 * Makes this post type available for selection in navigation menus.
+	 *
+	 * Default is the value $public.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $show_in_nav_menus
+	 */
+	public $show_in_nav_menus = null;
+
+	/**
+	 * Makes this post type available via the admin bar.
+	 *
+	 * Default is the value of $show_in_menu.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $show_in_admin_bar
+	 */
+	public $show_in_admin_bar = null;
+
+	/**
+	 * The position in the menu order the post type should appear.
+	 *
+	 * To work, $show_in_menu must be true. Default null (at the bottom).
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var int $menu_position
+	 */
+	public $menu_position = null;
+
+	/**
+	 * The URL to the icon to be used for this menu.
+	 *
+	 * Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme.
+	 * This should begin with 'data:image/svg+xml;base64,'. Pass the name of a Dashicons helper class
+	 * to use a font icon, e.g. 'dashicons-chart-pie'. Pass 'none' to leave div.wp-menu-image empty
+	 * so an icon can be added via CSS.
+	 *
+	 * Defaults to use the posts icon.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var string $menu_icon
+	 */
+	public $menu_icon = null;
+
+	/**
+	 * The string to use to build the read, edit, and delete capabilities.
+	 *
+	 * May be passed as an array to allow for alternative plurals when using
+	 * this argument as a base to construct the capabilities, e.g.
+	 * array( 'story', 'stories' ). Default 'post'.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var string $capability_type
+	 */
+	public $capability_type = 'post';
+
+	/**
+	 * Whether to use the internal default meta capability handling.
+	 *
+	 * Default false.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $map_meta_cap
+	 */
+	public $map_meta_cap = false;
+
+	/**
+	 * Provide a callback function that sets up the meta boxes for the edit form.
+	 *
+	 * Do `remove_meta_box()` and `add_meta_box()` calls in the callback. Default null.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var string $register_meta_box_cb
+	 */
+	public $register_meta_box_cb = null;
+
+	/**
+	 * An array of taxonomy identifiers that will be registered for the post type.
+	 *
+	 * Taxonomies can be registered later with `register_taxonomy()` or `register_taxonomy_for_object_type()`.
+	 *
+	 * Default empty array.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var array $taxonomies
+	 */
+	public $taxonomies = array();
+
+	/**
+	 * Whether there should be post type archives, or if a string, the archive slug to use.
+	 *
+	 * Will generate the proper rewrite rules if $rewrite is enabled. Default false.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool|string $has_archive
+	 */
+	public $has_archive = false;
+
+	/**
+	 * Sets the query_var key for this post type.
+	 *
+	 * Defaults to $post_type key. If false, a post type cannot be loaded at `?{query_var}={post_slug}`.
+	 * If specified as a string, the query `?{query_var_string}={post_slug}` will be valid.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var string|bool $query_var
+	 */
+	public $query_var;
+
+	/**
+	 * Whether to allow this post type to be exported.
+	 *
+	 * Default true.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $can_export
+	 */
+	public $can_export = true;
+
+	/**
+	 * Whether to delete posts of this type when deleting a user.
+	 *
+	 * If true, posts of this type belonging to the user will be moved to trash when then user is deleted.
+	 * If false, posts of this type belonging to the user will *not* be trashed or deleted.
+	 * If not set (the default), posts are trashed if post_type_supports( 'author' ).
+	 * Otherwise posts are not trashed or deleted. Default null.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $delete_with_user
+	 */
+	public $delete_with_user = null;
+
+	/**
+	 * Whether this post type is a native or "built-in" post_type.
+	 *
+	 * Default false.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var bool $_builtin
+	 */
+	public $_builtin = false;
+
+	/**
+	 * URL segment to use for edit link of this post type.
+	 *
+	 * Default 'post.php?post=%d'.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var string $_edit_link
+	 */
+	public $_edit_link = 'post.php?post=%d';
+
+
+	/**
+	 * Post type capabilities.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var array $cap
+	 */
+	public $cap;
+
+	/**
+	 * Triggers the handling of rewrites for this post type.
+	 *
+	 * Defaults to true, using $post_type as slug.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var array|false $rewrite
+	 */
+	public $rewrite;
+
+	/**
+	 * The features supported by the post type.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 * @var array|bool $supports
+	 */
+	public $supports;
+
+	/**
+	 * Constructor.
+	 *
+	 * Will populate object properties from the provided arguments and assign other
+	 * default properties based on that information.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 *
+	 * @see register_post_type()
+	 *
+	 * @param string       $post_type Post type key.
+	 * @param array|string $args      Optional. Array or string of arguments for registering a post type.
+	 *                                Default empty array.
+	 */
+	public function __construct( $post_type, $args = array() ) {
+		$this->name = $post_type;
+
+		$this->set_props( $args );
+	}
+
+	/**
+	 * Sets post type properties.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 *
+	 * @param array|string $args Array or string of arguments for registering a post type.
+	 */
+	public function set_props( $args ) {
+		$args = wp_parse_args( $args );
+
+		/**
+		 * Filter the arguments for registering a post type.
+		 *
+		 * @since 4.4.0
+		 *
+		 * @param array  $args      Array of arguments for registering a post type.
+		 * @param string $post_type Post type key.
+		 */
+		$args = apply_filters( 'register_post_type_args', $args, $this->name );
+
+		$has_edit_link = ! empty( $args['_edit_link'] );
+
+		// Args prefixed with an underscore are reserved for internal use.
+		$defaults = array(
+			'labels'               => array(),
+			'description'          => '',
+			'public'               => false,
+			'hierarchical'         => false,
+			'exclude_from_search'  => null,
+			'publicly_queryable'   => null,
+			'show_ui'              => null,
+			'show_in_menu'         => null,
+			'show_in_nav_menus'    => null,
+			'show_in_admin_bar'    => null,
+			'menu_position'        => null,
+			'menu_icon'            => null,
+			'capability_type'      => 'post',
+			'capabilities'         => array(),
+			'map_meta_cap'         => null,
+			'supports'             => array(),
+			'register_meta_box_cb' => null,
+			'taxonomies'           => array(),
+			'has_archive'          => false,
+			'rewrite'              => true,
+			'query_var'            => true,
+			'can_export'           => true,
+			'delete_with_user'     => null,
+			'_builtin'             => false,
+			'_edit_link'           => 'post.php?post=%d',
+		);
+
+		$args = array_merge( $defaults, $args );
+
+		$args['name'] = $this->name;
+
+		// If not set, default to the setting for public.
+		if ( null === $args['publicly_queryable'] ) {
+			$args['publicly_queryable'] = $args['public'];
+		}
+
+		// If not set, default to the setting for public.
+		if ( null === $args['show_ui'] ) {
+			$args['show_ui'] = $args['public'];
+		}
+
+		// If not set, default to the setting for show_ui.
+		if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) {
+			$args['show_in_menu'] = $args['show_ui'];
+		}
+
+		// If not set, default to the whether the full UI is shown.
+		if ( null === $args['show_in_admin_bar'] ) {
+			$args['show_in_admin_bar'] = (bool) $args['show_in_menu'];
+		}
+
+		// If not set, default to the setting for public.
+		if ( null === $args['show_in_nav_menus'] ) {
+			$args['show_in_nav_menus'] = $args['public'];
+		}
+
+		// If not set, default to true if not public, false if public.
+		if ( null === $args['exclude_from_search'] ) {
+			$args['exclude_from_search'] = ! $args['public'];
+		}
+
+		// Back compat with quirky handling in version 3.0. #14122.
+		if ( empty( $args['capabilities'] ) && null === $args['map_meta_cap'] && in_array( $args['capability_type'], array( 'post', 'page' ) ) ) {
+			$args['map_meta_cap'] = true;
+		}
+
+		// If not set, default to false.
+		if ( null === $args['map_meta_cap'] ) {
+			$args['map_meta_cap'] = false;
+		}
+
+		// If there's no specified edit link and no UI, remove the edit link.
+		if ( ! $args['show_ui'] && ! $has_edit_link ) {
+			$args['_edit_link'] = '';
+		}
+
+		$this->cap = get_post_type_capabilities( (object) $args );
+		unset( $args['capabilities'] );
+
+		if ( is_array( $args['capability_type'] ) ) {
+			$args['capability_type'] = $args['capability_type'][0];
+		}
+
+		if ( false !== $args['query_var'] ) {
+			if ( true === $args['query_var'] ) {
+				$args['query_var'] = $this->name;
+			} else {
+				$args['query_var'] = sanitize_title_with_dashes( $args['query_var'] );
+			}
+		}
+
+		if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {
+			if ( ! is_array( $args['rewrite'] ) ) {
+				$args['rewrite'] = array();
+			}
+			if ( empty( $args['rewrite']['slug'] ) ) {
+				$args['rewrite']['slug'] = $this->name;
+			}
+			if ( ! isset( $args['rewrite']['with_front'] ) ) {
+				$args['rewrite']['with_front'] = true;
+			}
+			if ( ! isset( $args['rewrite']['pages'] ) ) {
+				$args['rewrite']['pages'] = true;
+			}
+			if ( ! isset( $args['rewrite']['feeds'] ) || ! $args['has_archive'] ) {
+				$args['rewrite']['feeds'] = (bool) $args['has_archive'];
+			}
+			if ( ! isset( $args['rewrite']['ep_mask'] ) ) {
+				if ( isset( $args['permalink_epmask'] ) ) {
+					$args['rewrite']['ep_mask'] = $args['permalink_epmask'];
+				} else {
+					$args['rewrite']['ep_mask'] = EP_PERMALINK;
+				}
+			}
+		}
+
+		foreach ( $args as $property_name => $property_value ) {
+			$this->$property_name = $property_value;
+		}
+
+		$this->labels = get_post_type_labels( $this );
+		$this->label  = $this->labels->name;
+	}
+
+	/**
+	 * Sets the features support for the post type.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 */
+	public function add_supports() {
+		if ( ! empty( $this->supports ) ) {
+			add_post_type_support( $this->name, $this->supports );
+			unset( $this->supports );
+		} elseif ( false !== $this->supports ) {
+			// Add default features.
+			add_post_type_support( $this->name, array( 'title', 'editor' ) );
+		}
+	}
+
+	/**
+	 * Adds the necessary rewrite rules for the post type.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 *
+	 * @global WP_Rewrite $wp_rewrite WordPress Rewrite Component.
+	 * @global WP         $wp         Current WordPress environment instance.
+	 */
+	public function add_rewrite_rules() {
+		global $wp_rewrite, $wp;
+
+		if ( false !== $this->query_var && $wp && is_post_type_viewable( $this ) ) {
+			$wp->add_query_var( $this->query_var );
+		}
+
+		if ( false !== $this->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {
+			if ( $this->hierarchical ) {
+				add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" );
+			} else {
+				add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" );
+			}
+
+			if ( $this->has_archive ) {
+				$archive_slug = true === $this->has_archive ? $this->rewrite['slug'] : $this->has_archive;
+				if ( $this->rewrite['with_front'] ) {
+					$archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug;
+				} else {
+					$archive_slug = $wp_rewrite->root . $archive_slug;
+				}
+
+				add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$this->name", 'top' );
+				if ( $this->rewrite['feeds'] && $wp_rewrite->feeds ) {
+					$feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
+					add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' );
+					add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' );
+				}
+				if ( $this->rewrite['pages'] ) {
+					add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$this->name" . '&paged=$matches[1]', 'top' );
+				}
+			}
+
+			$permastruct_args         = $this->rewrite;
+			$permastruct_args['feed'] = $permastruct_args['feeds'];
+			add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $permastruct_args );
+		}
+	}
+
+	/**
+	 * Registers the post type meta box if a custom callback was specified.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 */
+	public function register_meta_boxes() {
+		if ( $this->register_meta_box_cb ) {
+			add_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10, 1 );
+		}
+	}
+
+	/**
+	 * Adds the future post hook action for the post type.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 */
+	public function add_hooks() {
+		add_action( 'future_' . $this->name, '_future_post_hook', 5, 2 );
+	}
+
+	/**
+	 * Registers the taxonomies for the post type.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 */
+	public function register_taxonomies() {
+		foreach ( $this->taxonomies as $taxonomy ) {
+			register_taxonomy_for_object_type( $taxonomy, $this->name );
+		}
+	}
+
+	/**
+	 * Removes the features support for the post type.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 *
+	 * @global array $_wp_post_type_features Post type features.
+	 */
+	public function remove_supports() {
+		global $_wp_post_type_features;
+
+		unset( $_wp_post_type_features[ $this->name ] );
+	}
+
+	/**
+	 * Removes any rewrite rules, permastructs, and rules for the post type.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 *
+	 * @global WP_Rewrite $wp_rewrite          WordPress rewrite component.
+	 * @global WP         $wp                  Current WordPress environment instance.
+	 * @global array      $post_type_meta_caps Used to remove meta capabilities.
+	 */
+	public function remove_rewrite_rules() {
+		global $wp, $wp_rewrite, $post_type_meta_caps;
+
+		// Remove query var.
+		if ( false !== $this->query_var ) {
+			$wp->remove_query_var( $this->query_var );
+		}
+
+		// Remove any rewrite rules, permastructs, and rules.
+		if ( false !== $this->rewrite ) {
+			remove_rewrite_tag( "%$this->name%" );
+			remove_permastruct( $this->name );
+			foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) {
+				if ( false !== strpos( $query, "index.php?post_type=$this->name" ) ) {
+					unset( $wp_rewrite->extra_rules_top[ $regex ] );
+				}
+			}
+		}
+
+		// Remove registered custom meta capabilities.
+		foreach ( $this->cap as $cap ) {
+			unset( $post_type_meta_caps[ $cap ] );
+		}
+	}
+
+	/**
+	 * Unregisters the post type meta box if a custom callback was specified.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 */
+	public function unregister_meta_boxes() {
+		if ( $this->register_meta_box_cb ) {
+			remove_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10 );
+		}
+	}
+
+	/**
+	 * Removes the post type from all taxonomies.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 */
+	public function unregister_taxonomies() {
+		foreach ( get_object_taxonomies( $this->name ) as $taxonomy ) {
+			unregister_taxonomy_for_object_type( $taxonomy, $this->name );
+		}
+	}
+
+	/**
+	 * Removes the future post hook action for the post type.
+	 *
+	 * @since 4.6.0
+	 * @access public
+	 */
+	public function remove_hooks() {
+		remove_action( 'future_' . $this->name, '_future_post_hook', 5 );
+	}
+}
Index: src/wp-includes/class-wp-xmlrpc-server.php
===================================================================
--- src/wp-includes/class-wp-xmlrpc-server.php	(revision 37886)
+++ src/wp-includes/class-wp-xmlrpc-server.php	(working copy)
@@ -883,8 +883,8 @@
 	 *
 	 * @access protected
 	 *
-	 * @param object $post_type Post type object.
-	 * @param array  $fields    The subset of post fields to return.
+	 * @param WP_Post_Type $post_type Post type object.
+	 * @param array        $fields    The subset of post fields to return.
 	 * @return array The prepared post type data.
 	 */
 	protected function _prepare_post_type( $post_type, $fields ) {
@@ -922,8 +922,8 @@
 		 *
 		 * @since 3.4.0
 		 *
-		 * @param array  $_post_type An array of post type data.
-		 * @param object $post_type  Post type object.
+		 * @param array        $_post_type An array of post type data.
+		 * @param WP_Post_Type $post_type  Post type object.
 		 */
 		return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type );
 	}
Index: src/wp-includes/post.php
===================================================================
--- src/wp-includes/post.php	(revision 37886)
+++ src/wp-includes/post.php	(working copy)
@@ -819,7 +819,7 @@
 }
 
 /**
- * Retrieve the post type of the current post or of a given post.
+ * Retrieves the post type of the current post or of a given post.
  *
  * @since 2.1.0
  *
@@ -834,7 +834,7 @@
 }
 
 /**
- * Retrieve a post type object by name.
+ * Retrieves a post type object by name.
  *
  * @since 3.0.0
  *
@@ -843,7 +843,7 @@
  * @see register_post_type()
  *
  * @param string $post_type The name of a registered post type.
- * @return object|null A post type object.
+ * @return WP_Post_Type|null WP_Post_Type object if it exists, null otherwise.
  */
 function get_post_type_object( $post_type ) {
 	global $wp_post_types;
@@ -899,10 +899,9 @@
  * @since 3.0.0 The `show_ui` argument is now enforced on the new post screen.
  * @since 4.4.0 The `show_ui` argument is now enforced on the post type listing
  *              screen and post editing screen.
+ * @since 4.6.0 Converted to use `WP_Post_Type`.
  *
- * @global array      $wp_post_types List of post types.
- * @global WP_Rewrite $wp_rewrite    Used for default feeds.
- * @global WP         $wp            Used to add query vars.
+ * @global array $wp_post_types List of post types.
  *
  * @param string $post_type Post type key. Must not exceed 20 characters and may
  *                          only contain lowercase alphanumeric characters, dashes,
@@ -1011,10 +1010,10 @@
  *     @type string      $_edit_link           FOR INTERNAL USE ONLY! URL segment to use for edit link of
  *                                             this post type. Default 'post.php?post=%d'.
  * }
- * @return object|WP_Error The registered post type object, or an error object.
+ * @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, $wp_rewrite, $wp;
+	global $wp_post_types;
 
 	if ( ! is_array( $wp_post_types ) ) {
 		$wp_post_types = array();
@@ -1022,191 +1021,33 @@
 
 	// Sanitize post type name
 	$post_type = sanitize_key( $post_type );
-	$args      = wp_parse_args( $args );
 
-	/**
-	 * Filters the arguments for registering a post type.
-	 *
-	 * @since 4.4.0
-	 *
-	 * @param array  $args      Array of arguments for registering a post type.
-	 * @param string $post_type Post type key.
-	 */
-	$args = apply_filters( 'register_post_type_args', $args, $post_type );
-
-	$has_edit_link = ! empty( $args['_edit_link'] );
-
-	// Args prefixed with an underscore are reserved for internal use.
-	$defaults = array(
-		'labels'               => array(),
-		'description'          => '',
-		'public'               => false,
-		'hierarchical'         => false,
-		'exclude_from_search'  => null,
-		'publicly_queryable'   => null,
-		'show_ui'              => null,
-		'show_in_menu'         => null,
-		'show_in_nav_menus'    => null,
-		'show_in_admin_bar'    => null,
-		'menu_position'        => null,
-		'menu_icon'            => null,
-		'capability_type'      => 'post',
-		'capabilities'         => array(),
-		'map_meta_cap'         => null,
-		'supports'             => array(),
-		'register_meta_box_cb' => null,
-		'taxonomies'           => array(),
-		'has_archive'          => false,
-		'rewrite'              => true,
-		'query_var'            => true,
-		'can_export'           => true,
-		'delete_with_user'     => null,
-		'_builtin'             => false,
-		'_edit_link'           => 'post.php?post=%d',
-	);
-	$args = array_merge( $defaults, $args );
-	$args = (object) $args;
-
-	$args->name = $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' );
 		return new WP_Error( 'post_type_length_invalid', __( 'Post type names must be between 1 and 20 characters in length.' ) );
 	}
 
-	// If not set, default to the setting for public.
-	if ( null === $args->publicly_queryable )
-		$args->publicly_queryable = $args->public;
+	$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();
 
-	// If not set, default to the setting for public.
-	if ( null === $args->show_ui )
-		$args->show_ui = $args->public;
+	$wp_post_types[ $post_type ] = $post_type_object;
 
-	// If not set, default to the setting for show_ui.
-	if ( null === $args->show_in_menu || ! $args->show_ui )
-		$args->show_in_menu = $args->show_ui;
+	$post_type_object->add_hooks();
+	$post_type_object->register_taxonomies();
 
-	// If not set, default to the whether the full UI is shown.
-	if ( null === $args->show_in_admin_bar )
-		$args->show_in_admin_bar = (bool) $args->show_in_menu;
-
-	// If not set, default to the setting for public.
-	if ( null === $args->show_in_nav_menus )
-		$args->show_in_nav_menus = $args->public;
-
-	// If not set, default to true if not public, false if public.
-	if ( null === $args->exclude_from_search )
-		$args->exclude_from_search = !$args->public;
-
-	// Back compat with quirky handling in version 3.0. #14122.
-	if ( empty( $args->capabilities ) && null === $args->map_meta_cap && in_array( $args->capability_type, array( 'post', 'page' ) ) )
-		$args->map_meta_cap = true;
-
-	// If not set, default to false.
-	if ( null === $args->map_meta_cap )
-		$args->map_meta_cap = false;
-
-	// If there's no specified edit link and no UI, remove the edit link.
-	if ( ! $args->show_ui && ! $has_edit_link ) {
-		$args->_edit_link = '';
-	}
-
-	$args->cap = get_post_type_capabilities( $args );
-	unset( $args->capabilities );
-
-	if ( is_array( $args->capability_type ) )
-		$args->capability_type = $args->capability_type[0];
-
-	if ( ! empty( $args->supports ) ) {
-		add_post_type_support( $post_type, $args->supports );
-		unset( $args->supports );
-	} elseif ( false !== $args->supports ) {
-		// Add default features
-		add_post_type_support( $post_type, array( 'title', 'editor' ) );
-	}
-
-	if ( false !== $args->query_var ) {
-		if ( true === $args->query_var )
-			$args->query_var = $post_type;
-		else
-			$args->query_var = sanitize_title_with_dashes( $args->query_var );
-
-		if ( $wp && is_post_type_viewable( $args ) ) {
-			$wp->add_query_var( $args->query_var );
-		}
-	}
-
-	if ( false !== $args->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {
-		if ( ! is_array( $args->rewrite ) )
-			$args->rewrite = array();
-		if ( empty( $args->rewrite['slug'] ) )
-			$args->rewrite['slug'] = $post_type;
-		if ( ! isset( $args->rewrite['with_front'] ) )
-			$args->rewrite['with_front'] = true;
-		if ( ! isset( $args->rewrite['pages'] ) )
-			$args->rewrite['pages'] = true;
-		if ( ! isset( $args->rewrite['feeds'] ) || ! $args->has_archive )
-			$args->rewrite['feeds'] = (bool) $args->has_archive;
-		if ( ! isset( $args->rewrite['ep_mask'] ) ) {
-			if ( isset( $args->permalink_epmask ) )
-				$args->rewrite['ep_mask'] = $args->permalink_epmask;
-			else
-				$args->rewrite['ep_mask'] = EP_PERMALINK;
-		}
-
-		if ( $args->hierarchical )
-			add_rewrite_tag( "%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&pagename=" );
-		else
-			add_rewrite_tag( "%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=" );
-
-		if ( $args->has_archive ) {
-			$archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive;
-			if ( $args->rewrite['with_front'] )
-				$archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug;
-			else
-				$archive_slug = $wp_rewrite->root . $archive_slug;
-
-			add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' );
-			if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) {
-				$feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
-				add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
-				add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
-			}
-			if ( $args->rewrite['pages'] )
-				add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' );
-		}
-
-		$permastruct_args = $args->rewrite;
-		$permastruct_args['feed'] = $permastruct_args['feeds'];
-		add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $permastruct_args );
-	}
-
-	// Register the post type meta box if a custom callback was specified.
-	if ( $args->register_meta_box_cb )
-		add_action( 'add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1 );
-
-	$args->labels = get_post_type_labels( $args );
-	$args->label = $args->labels->name;
-
-	$wp_post_types[ $post_type ] = $args;
-
-	add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 );
-
-	foreach ( $args->taxonomies as $taxonomy ) {
-		register_taxonomy_for_object_type( $taxonomy, $post_type );
-	}
-
 	/**
 	 * Fires after a post type is registered.
 	 *
 	 * @since 3.3.0
 	 *
-	 * @param string $post_type Post type.
-	 * @param object $args      Arguments used to register the post type.
+	 * @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, $args );
+	do_action( 'registered_post_type', $post_type, $post_type_object );
 
-	return $args;
+	return $post_type_object;
 }
 
 /**
@@ -1215,68 +1056,33 @@
  * Can not be used to unregister built-in post types.
  *
  * @since 4.5.0
+ * @since 4.6.0 Converted to use `WP_Post_Type`.
  *
- * @global WP_Rewrite $wp_rewrite             WordPress rewrite component.
- * @global WP         $wp                     Current WordPress environment instance.
- * @global array      $_wp_post_type_features Used to remove post type features.
- * @global array      $post_type_meta_caps    Used to remove meta capabilities.
- * @global array      $wp_post_types          List of post types.
+ * @global array $wp_post_types List of post types.
  *
  * @param string $post_type Post type to unregister.
  * @return bool|WP_Error True on success, WP_Error on failure or if the post type doesn't exist.
  */
 function unregister_post_type( $post_type ) {
+	global $wp_post_types;
+
 	if ( ! post_type_exists( $post_type ) ) {
 		return new WP_Error( 'invalid_post_type', __( 'Invalid post type' ) );
 	}
 
-	$post_type_args = get_post_type_object( $post_type );
+	$post_type_object = get_post_type_object( $post_type );
 
 	// Do not allow unregistering internal post types.
-	if ( $post_type_args->_builtin ) {
+	if ( $post_type_object->_builtin ) {
 		return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) );
 	}
 
-	global $wp, $wp_rewrite, $_wp_post_type_features, $post_type_meta_caps, $wp_post_types;
+	$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();
 
-	// Remove query var.
-	if ( false !== $post_type_args->query_var ) {
-		$wp->remove_query_var( $post_type_args->query_var );
-	}
-
-	// Remove any rewrite rules, permastructs, and rules.
-	if ( false !== $post_type_args->rewrite ) {
-		remove_rewrite_tag( "%$post_type%" );
-		remove_permastruct( $post_type );
-		foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) {
-			if ( false !== strpos( $query, "index.php?post_type=$post_type" ) ) {
-				unset( $wp_rewrite->extra_rules_top[ $regex ] );
-			}
-		}
-	}
-
-	// Remove registered custom meta capabilities.
-	foreach ( $post_type_args->cap as $cap ) {
-		unset( $post_type_meta_caps[ $cap ] );
-	}
-
-	// Remove all post type support.
-	unset( $_wp_post_type_features[ $post_type ] );
-
-	// Unregister the post type meta box if a custom callback was specified.
-	if ( $post_type_args->register_meta_box_cb ) {
-		remove_action( 'add_meta_boxes_' . $post_type, $post_type_args->register_meta_box_cb );
-	}
-
-	// Remove the post type from all taxonomies.
-	foreach ( get_object_taxonomies( $post_type ) as $taxonomy ) {
-		unregister_taxonomy_for_object_type( $taxonomy, $post_type );
-	}
-
-	// Remove the future post hook action.
-	remove_action( 'future_' . $post_type, '_future_post_hook', 5 );
-
-	// Remove the post type.
 	unset( $wp_post_types[ $post_type ] );
 
 	/**
@@ -1462,7 +1268,7 @@
  *
  * @access private
  *
- * @param object $post_type_object Post type object.
+ * @param object|WP_Post_Type $post_type_object Post type object.
  * @return object Object with all the labels as member variables.
  */
 function get_post_type_labels( $post_type_object ) {
@@ -1717,7 +1523,7 @@
  * @since 4.4.0
  * @since 4.5.0 Added the ability to pass a post type name in addition to object.
  *
- * @param object $post_type Post type name or object.
+ * @param string|WP_Post_Type $post_type Post type name or object.
  * @return bool Whether the post type should be considered viewable.
  */
 function is_post_type_viewable( $post_type ) {
Index: src/wp-settings.php
===================================================================
--- src/wp-settings.php	(revision 37886)
+++ src/wp-settings.php	(working copy)
@@ -158,6 +158,7 @@
 require( ABSPATH . WPINC . '/post.php' );
 require( ABSPATH . WPINC . '/class-walker-page.php' );
 require( ABSPATH . WPINC . '/class-walker-page-dropdown.php' );
+require( ABSPATH . WPINC . '/class-wp-post-type.php' );
 require( ABSPATH . WPINC . '/class-wp-post.php' );
 require( ABSPATH . WPINC . '/post-template.php' );
 require( ABSPATH . WPINC . '/revision.php' );
Index: tests/phpunit/tests/post/types.php
===================================================================
--- tests/phpunit/tests/post/types.php	(revision 37886)
+++ tests/phpunit/tests/post/types.php	(working copy)
@@ -29,7 +29,7 @@
 		register_post_type( 'foo' );
 
 		$pobj = get_post_type_object( 'foo' );
-		$this->assertInstanceOf( 'stdClass', $pobj );
+		$this->assertInstanceOf( 'WP_Post_Type', $pobj );
 		$this->assertEquals( 'foo', $pobj->name );
 
 		// Test some defaults
@@ -554,7 +554,7 @@
 	 * @since 4.5.0
 	 *
 	 * @param array $args register_post_type() arguments.
-	 * @return stdClass Post type object for `$this->post_type`.
+	 * @return WP_Post_Type Post type object for `$this->post_type`.
 	 */
 	public function register_post_type( $args = array() ) {
 		register_post_type( $this->post_type, $args );
Index: tests/phpunit/tests/post/wpPostType.php
===================================================================
--- tests/phpunit/tests/post/wpPostType.php	(revision 0)
+++ tests/phpunit/tests/post/wpPostType.php	(working copy)
@@ -0,0 +1,151 @@
+<?php
+
+/**
+ * @group post
+ */
+class Tests_WP_Post_Type extends WP_UnitTestCase {
+	public function test_instances() {
+		global $wp_post_types;
+
+		foreach ( $wp_post_types as $post_type ) {
+			$this->assertInstanceOf( 'WP_Post_Type', $post_type );
+		}
+	}
+
+	public function test_add_supports_defaults() {
+		$post_type        = rand_str();
+		$post_type_object = new WP_Post_Type( $post_type );
+
+		$post_type_object->add_supports();
+		$post_type_supports = get_all_post_type_supports( $post_type );
+
+		$post_type_object->remove_supports();
+		$post_type_supports_after = get_all_post_type_supports( $post_type );
+
+		$this->assertEqualSets( array( 'title' => true, 'editor' => true ), $post_type_supports );
+		$this->assertEqualSets( array(), $post_type_supports_after );
+	}
+
+	public function test_add_supports_custom() {
+		$post_type        = rand_str();
+		$post_type_object = new WP_Post_Type( $post_type, array(
+			'supports' => array(
+				'editor',
+				'comments',
+				'revisions',
+			),
+		) );
+
+		$post_type_object->add_supports();
+		$post_type_supports = get_all_post_type_supports( $post_type );
+
+		$post_type_object->remove_supports();
+		$post_type_supports_after = get_all_post_type_supports( $post_type );
+
+		$this->assertEqualSets( array(
+			'editor'    => true,
+			'comments'  => true,
+			'revisions' => true,
+		), $post_type_supports );
+		$this->assertEqualSets( array(), $post_type_supports_after );
+	}
+
+	public function test_does_not_add_query_var_if_not_public() {
+		$this->set_permalink_structure( '/%postname%' );
+
+		/* @var WP $wp */
+		global $wp;
+
+		$post_type        = rand_str();
+		$post_type_object = new WP_Post_Type( $post_type, array( 'rewrite' => false, 'query_var' => 'foobar' ) );
+		$post_type_object->add_rewrite_rules();
+
+		$this->assertFalse( in_array( 'foobar', $wp->public_query_vars ) );
+	}
+
+	public function test_adds_query_var_if_public() {
+		$this->set_permalink_structure( '/%postname%' );
+
+		/* @var WP $wp */
+		global $wp;
+
+		$post_type        = rand_str();
+		$post_type_object = new WP_Post_Type( $post_type, array(
+			'public'    => true,
+			'rewrite'   => false,
+			'query_var' => 'foobar',
+		) );
+
+		$post_type_object->add_rewrite_rules();
+		$in_array = in_array( 'foobar', $wp->public_query_vars );
+
+		$post_type_object->remove_rewrite_rules();
+		$in_array_after = in_array( 'foobar', $wp->public_query_vars );
+
+		$this->assertTrue( $in_array );
+		$this->assertFalse( $in_array_after );
+	}
+
+	public function test_adds_rewrite_rules() {
+		$this->set_permalink_structure( '/%postname%' );
+
+		/* @var WP_Rewrite $wp_rewrite */
+		global $wp_rewrite;
+
+		$post_type        = rand_str();
+		$post_type_object = new WP_Post_Type( $post_type, array( 'public' => true, 'rewrite' => true ) );
+
+		$post_type_object->add_rewrite_rules();
+		$rewrite_tags = $wp_rewrite->rewritecode;
+
+		$post_type_object->remove_rewrite_rules();
+		$rewrite_tags_after = $wp_rewrite->rewritecode;
+
+		$this->assertTrue( false !== array_search( "%$post_type%", $rewrite_tags ) );
+		$this->assertFalse( array_search( "%$post_type%", $rewrite_tags_after ) );
+	}
+
+	public function test_register_meta_boxes() {
+		$post_type        = rand_str();
+		$post_type_object = new WP_Post_Type( $post_type, array( 'register_meta_box_cb' => '__return_false' ) );
+
+		$post_type_object->register_meta_boxes();
+		$has_action = has_action( "add_meta_boxes_$post_type", '__return_false' );
+		$post_type_object->unregister_meta_boxes();
+		$has_action_after = has_action( "add_meta_boxes_$post_type", '__return_false' );
+
+		$this->assertSame( 10, $has_action );
+		$this->assertFalse( $has_action_after );
+	}
+
+	public function test_adds_future_post_hook() {
+		$post_type        = rand_str();
+		$post_type_object = new WP_Post_Type( $post_type );
+		$post_type_object->add_hooks();
+		$has_action = has_action( "future_$post_type", '_future_post_hook' );
+		$post_type_object->remove_hooks();
+		$has_action_after = has_action( "future_$post_type", '_future_post_hook' );
+
+		$this->assertSame( 5, $has_action );
+		$this->assertFalse( $has_action_after );
+	}
+
+	public function test_register_taxonomies() {
+		global $wp_post_types;
+
+		$post_type        = rand_str();
+		$post_type_object = new WP_Post_Type( $post_type, array( 'taxonomies' => array( 'post_tag' ) ) );
+
+		$wp_post_types[ $post_type ] = $post_type_object;
+
+		$post_type_object->register_taxonomies();
+		$taxonomies = get_object_taxonomies( $post_type );
+		$post_type_object->unregister_taxonomies();
+		$taxonomies_after = get_object_taxonomies( $post_type );
+
+		unset( $wp_post_types[ $post_type ] );
+
+		$this->assertEqualSets( array( 'post_tag' ), $taxonomies );
+		$this->assertEqualSets( array(), $taxonomies_after );
+	}
+}
