Custom roles can’t access to wp-admin

With help of following code you can make a custom user role access the control panel. Following code works on hooks admin_init or init

add_action( 'admin_init', 'my_custom_function' );

function my_custom_function() {

  add_role( 'new_role', 'New Role' );
  
  $role = get_role( 'new_role' );
  
  $role->add_cap( 'edit_posts' );
  $role->add_cap( 'edit_pages' );
  $role->add_cap( 'edit_others_posts' );
  $role->add_cap( 'create_posts' );
  $role->add_cap( 'manage_categories' );
  $role->add_cap( 'publish_posts' );
  $role->add_cap( 'edit_themes' );
  $role->add_cap( 'install_plugins', false );
  $role->add_cap( 'update_plugin' );
  $role->add_cap( 'update_core', false );
 
  // add more capabilities as per you requirements
}