Phân quyền nếu là tác giả chỉ cho đăng 1 bài viết và có quyển chỉnh sửa rời menu chỉnh (ok)

<?php  
  $n = 1;
  $user_ID = get_current_user_id();
  $count_posts = count(get_posts(array('author'=>$user_ID)));
  if ($count_posts >= $n && isset(get_userdata($user_ID)->roles[0]) && get_userdata($user_ID)->roles[0]==='author'){
  function remove_menu_items() {
    remove_submenu_page( 'edit.php', 'post-new.php' );
  }
  add_action( 'admin_menu', 'remove_menu_items' );
  function disable_create_newpost() {
    global $wp_post_types;
    $wp_post_types['post']->cap->create_posts = 'do_not_allow';
    //$wp_post_types['page']->cap->create_posts = 'do_not_allow';
    //$wp_post_types['my-post-type']->cap->create_posts = 'do_not_allow';
  }
  add_action('init','disable_create_newpost');
  }
?>

Last updated