courses creation limit by users groups ?

Hello guys,
I really love CoursePress Pro, it's top !

I would like to know if it is possible :

I need to put a limit in courses creation for teachers.
For exemple, i have 2 groups : FREE and VIP
I want that FREE Group can create only 3 courses
and VIP Groups unlimited creation courses.

Is it possible ? If yes, how ?

Second question : By the same way, is it possible to limit the units creation
number ?
Thanks you in advance for your answers.

Sorry for my poor english...

Have a good day !!

    Jack Kitterhing

    Hi there @boll,

    Hope you're well today!

    You certainly can do this, the great thing is, that units and courses are custom post types, which allows you to more easily modify.

    The actual post types are called 'unit' and 'course', to limit the creation of those you can use a plugin such as this one https://wordpress.org/plugins/bainternet-posts-creation-limits/

    Of course if you have any problems let us know, we're here to help.

    Thanks!

    Kind Regards
    Jack.

    Vinod Dalvi

    Hi @boll,

    Thank you for your reply.

    I have tested it on my test site and found the plugin doesn't work for post types 'course' or 'unit'.

    The following code should achieve it if it is added in the functions.php file of child theme but it's not working for post types 'course' or 'unit'. May be this is because coursepress doesn't use the hook used in the following code therefore i have notified the plugin developer to knoiw which hook the coursepress plugin uses if any.

    add_action( 'admin_head-post-new.php', 'check_post_limit' );
    function check_post_limit() {
        global $userdata;
        global $post_type;
        global $wpdb;
    
    	if( $post_type === 'course' ) {
    		$item_count = $wpdb->get_var( "SELECT count(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'course' AND post_author = $userdata->ID" );
    		if( $item_count >= 1 ) { wp_die( "Do not create too much courses." ); }
    	} elseif( $post_type === 'unit' ) {
    		$shopinfo_count = $wpdb->get_var( "SELECT count(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'unit' AND post_author = $userdata->ID" );
    		if( $item_count >= 1 ) { wp_die( "Do not create too much units." ); }
    	}
    	return;
    }

    Thanks,
    Vinod Dalvi