根据this answer, “正确的方法”是:
register_post_type( \'custom_post_type_name\', array(
\'capability_type\' => \'post\',
\'capabilities\' => array(
\'create_posts\' => false, // Removes support for the "Add New" function ( use \'do_not_allow\' instead of false for multisite set ups )
),
\'map_meta_cap\' => true, // Set to `false`, if users are not allowed to edit/delete existing posts
));
--
<罢工>
add_action( \'load-post-new.php\', \'wpse_58290_disable_new_post\' );
function wpse_58290_disable_new_post()
{
if ( get_current_screen()->post_type == \'my_post_type\' )
wp_die( "You ain\'t allowed to do that!" );
}
请注意,您还需要隐藏UI元素,例如在菜单中,以及
h2
在编辑屏幕上标记罢工>