Allow non-admin to Add xAPI Content

If you want to decide whom to allow adding xAPI Content.  You can add the following code to your theme's functions.php file.

And then, use a plugin like User Role Editor, to assign related custom capabilities.  

 


// GrassBlade xAPI
add_filter("gb_xapi_content_post_args", "custom_gb_xapi_content_post_args");
function custom_gb_xapi_content_post_args($cpt_args)
{
$cpt_args['publicly_queryable'] = false;
$cpt_args['show_in_nav_menus'] = false;
$cpt_args['show_in_menu'] = false;
$cpt_args['capability_type'] = 'xapi';
$cpt_args['capabilities'] = array(
'edit_post' => 'edit_xapi',
'read_post' => 'read_xapi',
'delete_post' => 'delete_xapi',
'edit_posts' => 'edit_xapis',
'edit_others_posts' => 'edit_others_xapis',
'publish_posts' => 'publish_xapis',
'read_private_posts' => 'read_private_xapis',
);
return $cpt_args;
}

add_filter("learndash_submenu", "custom_grassblade_learndash_admin_tabs");
function custom_grassblade_learndash_admin_tabs($admin_tabs)
{
if (current_user_can('edit_xapis')) {
$admin_tabs['grassblade']["name"] = __('xAPI Content', "grassblade");
} else {
unset($admin_tabs['grassblade']);
}
return $admin_tabs;
}

 

Have more questions? Submit a request

5 Comments

  • 0
    Avatar
    Mmorrison

    Hi Pankaj,

    There seems to be an issue with this code. When adding, it removes the xAPI Content menu item from Administrators even though they have the edit_xapi capability.

    Similarly adding the edit_xapi capability to a custom role, the xAPI Content menu doesn't show for that user.

    So it seems the code is thinking that the capability is not present and unsetting the admin_tab or isn't able to assign the admin_tab

    Cheers,

    Mark

  • 1
    Avatar
    purva bathe

    I was having same problem but resolved...

    Using above code it's just create "xAPI Content" in submenu but has no access. I also tried user role plugins to achieve access but did not work.

    so at last i have gone through the code of plugin "instructor-role" which i have used to create new instructor role and found solution to access "xAPI Content".

    It is in root file "instructor.php" around line no. 55 where it says,

    // array of all custom post types of LD posts.

    i have added there 'gb_xapi_content' and it works for me for the non-admin instructor role.

    Edited by purva bathe
  • 0
    Avatar
    Pankaj Agrawal

    Hi Purva,

    I am not aware of instructor.php file in either LearnDash or GrassBlade xAPI Companion . Can you let me know where exactly it is? 

    Pankaj

     

  • 1
    Avatar
    purva bathe

    Hello Sir,

    That instructor.php file is in "instructor-role" (https://wisdmlabs.com/instructor-role-extension-for-learndash/) which is add-on plugin for learnDash.

    And I want instructor should access "xAPI Content".

  • 0
    Avatar
    Israr Ahmed

    Hi Pankaj

    This is a clean solution for managing xAPI content access in LearnDash. One thing to keep in mind is that custom capability types like this do not automatically inherit admin access, so administrators can lose menu visibility as Mark pointed out. Mapping the capabilities explicitly to the admin role after adding this code resolves that. User Role Editor makes that step straightforward. Also 

    https://wooninjas.com/learndash/ has add-on plugins for LearnDash

    Edited by Israr Ahmed
Please sign in to leave a comment.
Powered by Zendesk