I am building a WP plugin and I want to replace the admin list page (edit.php?post_type=my_cpt) for my CPT. The CPT should not have any 'add new' buttons as new content will only be imported. The existing posts should still be editable and removable. I can hide the 'add new' buttons and links by defining the capabilities of my CPT as follows:
'show_in_menu' => 'my_cpt',
'capability_type' => 'post',
'capabilities' => array(
'create_posts' => 'do_not_allow',
),
'map_meta_cap' => true
I also created a custom menu with the same slug name as the CPT. (links to admin.php?page=my_cpt_page) and the default 'all posts' link is removed from the menu.
//Main menu (this page will have a custom table for my CPT)
add_menu_page(
__( 'My CPT', 'cpt' ), // Page Title
'My Test CPT', // Menu Title
'edit_posts', // capability
'my_cpt', // menu slug
array( $this->main_page, 'render' ), // action
'dashicons-email-alt', // icon
6 // position
);
//remove menu created by wordpress
remove_submenu_page( 'my_cpt', 'edit.php?post_type=my_cpt' );
Now, when I go to an edit page of a single item (eg: post.php?post=666&action=edit) and I press the 'Move to Trash' link, Wordpress will redirect me to the hidden page located at edit.php?post_type=my_cpt.
Is there any way to redirect edit.php?post_type=my_cpt to my own custom page (admin.php?page=my_cpt_page) without altering the .htaccess file? Or, even better, is there a way to replace/override the edit.php screen for my CPT?
Thanks in advance
Vincent.
edit.php
does on your new page, as well as filter all the edit links, this isn't a trivial task ( although it is easier if you're using the block editor/gutenberg )