Dashboard Sidebar for Custom Role

This tip is to make custom role in wplms and then register a custom sidebar for that user role only.

Please follow these steps:

  1. Paste this code in the wplms-customizer.php file present in the wplms customizer plugin OR in the function.php file of your child theme.
add_action('init','parent_sidebar');
function parent_sidebar(){
  $papa_capability=array( 'read');
    add_role( 'parent', __('parent','vibe'), $parent_capability );

  register_sidebar( array(
    'name' => 'Parent Sidebar',
    'id' => 'parent_sidebar',
    'before_widget' => '<div id="%1$s" class="%2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h4 class="dash_widget_title">',
    'after_title' => '</h4>',
        'description'   => __('This is the dashboard sidebar for Parents','wplms-dashboard')
  ) );
}

This will register a new user role known as parent with the capability to read; and a new sidebar for that user role.

You can change the user role name and its capability according to your requirements.

2) Now paste the following code below the above code.

add_filter('wplms_student_sidebar','wplms_parent_dashboard');
function wplms_parent_dashboard($sidebar){
  if(is_user_logged_in()){
    $user = wp_get_current_user();
    if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
      if(in_array('parent',$user->roles)){
        return 'parent_sidebar';
      }
    }
  }
  return $sidebar;
}

Done.

Leave a Reply

Your email address will not be published. Required fields are marked *