0

I have created 'news' custom post-type with CPTUI. And add 'news_manager' user role with these capabilities

edit_post
edit_posts
publish_posts
edit_others_posts
edit_published_posts

Then basically blocking access to some page with remove_menu_page by admin_menu action

remove_menu_page( 'index.php' );
remove_menu_page( 'edit.php?post_type=blog' );

Then making the role redirect to 'edit.php?post_type=news'

function loginRedirect( $redirect_to, $request, $user ){
  if ( current_user_can( 'news_manager' ) ) {
    return "/wp-admin/edit.php?post_type=news";
  }
  return $redirect_to;
}
add_filter("login_redirect", "loginRedirect", 50, 3);

But when I created a news_manager user and login with that. URL redirect is correct. But getting blocked, wordpress saying these

You do not have sufficient permissions to access this admin page.

Reason: The current user has the "edit_posts" capability that is required to access the "News → All News" menu item.

These only blocked on edit.php page. If access specific post it's pass. '/wp-admin/post.php?post=22&action=edit' for example

It's said the user have capability to view but blocking access. Why? and How to fix these.

Versions

  • Wordpress 4.9.4
  • Custom Post Type UI 1.5.6

1 Answers1

0

Please try the code below in your function.php file of Current Theme

function add_blog_role_caps() {

   $roles = array('news_manager');

   foreach($roles as $the_role) {

      $role = get_role($the_role);
      $role->add_cap( 'read_news');
      $role->add_cap( 'edit_news' );
      $role->add_cap( 'edit_others_news' );
      $role->add_cap( 'edit_published_news' );
      $role->add_cap( 'publish_news' );
      $role->add_cap( 'delete_others_news' );
      $role->add_cap( 'delete_private_news' );
      $role->add_cap( 'delete_published_news' );

   }
}
add_action('admin_init', 'add_blog_role_caps', 5 );
Yogesh Garg
  • 299
  • 3
  • 10