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.
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.
Share Improve this question asked Jun 12, 2019 at 16:27 VinzzVinzz 12 bronze badges 4 |1 Answer
Reset to default 0I found a way to add html above the post type table which is generated by WP.
add_filter( 'views_edit-my_cpt', "custom_list_table");
function custom_list_table( $views ) {
/* Print form */ ?>
<form method="post" action="//your.url/?action=action">
<? wp_nonce_field( 'action-form', 'action_nonce' ); ?>
<label for="field1"><? _e('your label') ?></label><br />
<input id="field1" type="text" name="field1"><input type="submit" name="submit" id="submitbtn" class="button button-primary" value="<? _e('Go')?> ">
</form><?
return $views;
}
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 ) – Tom J Nowell ♦ Commented Jun 12, 2019 at 16:46