( $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 */ 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 */ 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 */ 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 * * @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 * * @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 */ 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 */ 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 */ public function remove_hooks() { remove_action( 'future_' . $this->name, '_future_post_hook', 5 ); } /** * Gets the REST API controller for this post type. * * Will only instantiate the controller class once per request. * * @since 5.3.0 * * @return WP_REST_Controller|null The controller instance, or null if the post type * is set not to show in rest. */ public function get_rest_controller() { if ( ! $this->show_in_rest ) { return null; } $class = $this->rest_controller_class ? $this->rest_controller_class : WP_REST_Posts_Controller::class; if ( ! class_exists( $class ) ) { return null; } if ( ! is_subclass_of( $class, WP_REST_Controller::class ) ) { return null; } if ( ! $this->rest_controller ) { $this->rest_controller = new $class( $this->name ); } if ( ! ( $this->rest_controller instanceof $class ) ) { return null; } return $this->rest_controller; } }