0

I'm trying to set a limit to course creation using the roles of S2Member. For example for the level one, the user can create only 2 courses and 2 units. I added this code but it works only from the back-end. In the front-end creation (using wplms theme) the user can still create new courses and units. I'm not expert in coding, just trying to find my way out to this functionality. Any suggestions please?

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 >= 2 ) && (current_user_is("s2member_level1")) ) { 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 >= 2 ) && (current_user_is("s2member_level1")) ) { wp_die( "Do not create too much units." ); }
 }
 return;
}
icedwater
  • 4,701
  • 3
  • 35
  • 50
Amine Richer
  • 23
  • 1
  • 6

0 Answers0