I am making a plugin that allows admin to create custom post but I want admin to be able to create only one custom post type.
I tried this following to remove "Add New" from admin menu:
function remove_submenus() {
$count= wp_count_posts('post_type')->publish;
if( $count>=1 ){
global $submenu;
unset($submenu['edit.php?post_type=post_type'][10]);
}else{}
}
add_action('admin_menu', 'remove_submenus');
It removes "Add New" item from the menu but user (admin) is still be able to create new custom post type by using this URL (/post-new.php?post_type=post_type).
How can I prevent user to create post more than one?