Skip to content

Instantly share code, notes, and snippets.

@MaximeCulea
Last active June 22, 2024 19:20
Show Gist options
  • Save MaximeCulea/812a436a91542230de0d967b6b08dea4 to your computer and use it in GitHub Desktop.
Save MaximeCulea/812a436a91542230de0d967b6b08dea4 to your computer and use it in GitHub Desktop.
Unregister the post type "Post"
<?php
/**
* Unregister the post type "Post" or more
*
* @see unregister_post_type()
*
* @author Maxime CULEA
*/
add_action( 'init', function () {
global $wp_post_types;
$unregister = [
'post',
];
foreach ( $unregister as $post_type ) {
if ( ! post_type_exists( $post_type ) ) {
continue;
}
$post_type_object = get_post_type_object( $post_type );
$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 ] );
do_action( 'unregistered_post_type', $post_type );
// Avoid notices
$wp_post_types[ $post_type ] = new stdClass();
$wp_post_types[ $post_type ]->show_in_menu = false;
$wp_post_types[ $post_type ]->publicly_queryable = false;
$wp_post_types[ $post_type ]->_builtin = false;
$wp_post_types[ $post_type ]->name = false;
$wp_post_types[ $post_type ]->new_item = false;
$wp_post_types[ $post_type ]->cap = get_post_type_capabilities( (object) array_merge( (array) $post_type_object, [ 'capabilities' => [] ] ) );
$wp_post_types[ $post_type ]->labels = (object) WP_Post_Type::get_default_labels();
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment