Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I disable adding of new posts of a particular custom post type?

Found this code in Log Deprecated Notices plugin:

    $screen = get_current_screen();
    if ( self::pt == $screen->id && ( $screen->action == 'add' || $_GET['action'] == 'edit' ) )
        wp_die( __( 'Invalid post type.', 'log-deprecated' ) );
    if ( self::pt != $screen->post_type )
        return;
share|improve this question

2 Answers 2

up vote 1 down vote accepted
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!" );
}

Note that you'll also need to hide the UI elements, such as in the menu, and the "Add New" button in the h2 tag on the edit screen.

share|improve this answer
    
Thanks, would you hide those just via CSS? –  drtanz Jul 12 '12 at 15:28
1  
You might be better off removing the menu item by hooking onto admin_menu and searching for/unsetting the item in the global $submenu. As for the other items, check out the source & see if there's any suitable hooks/filters, otherwise fallback to CSS/JS. –  TheDeadMedic Jul 12 '12 at 15:43
    
Also how can I remove the Edit and Quick edit links –  drtanz Jul 12 '12 at 15:49
    
I don't have a menu item as I am adding the cpt to the menu via add_submenu_page –  drtanz Jul 12 '12 at 15:50
remove_submenu_page( 
    'edit.php?post_type=product',
    'post-new.php?post_type=product' 
);
share|improve this answer
4  
Please explain why that could solve the problem. –  toscho Mar 16 '13 at 22:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.