admin管理员组

文章数量:1292172

I created 4 custom post types.

Each author can write 1 post in each custom post type.

When an author wrote 1 post in a custom post type, I would like to remove "Add new.. (CPT)" for the custom post type concerned in admin menu.

For the moment, the limitation of 1 post works fine but I can't delete "Add new...(CPT)" in the admin menu.

Can I have some help please ?

$post_types_name = array('subject-imposed', 'subject-free', 'dissertation', 'curriculum-vitae');

foreach ($post_types_name as $post_type_name) {
    $count_post = count_user_posts(get_current_user_id(), $post_type_name, true);

    $max_posts = 1; //the number of max published posts

    if ($count_post >= $max_posts) {
        add_action( 'admin_menu', function() use ( $post_type_name ) {
                remove_submenu_page( 'edit.php?post_type='.$post_type_name, 'post-new.php?post_type='.$post_type_name );
            }
        );
    }
}

UPDATE :

Based on this hook

function remove_submenu() {
    remove_submenu_page( 'edit.php?post_type=posttype', 'post-new.php?post_type=posttype' );
}

add_action( 'admin_menu', 'remove_submenu', 999 );

本文标签: Limit to one post for each custom post type