uo_tincanny_reporting_capability
Filters the capability required for Tincanny reporting, allowing customization of user permissions for this feature.
add_filter( 'uo_tincanny_reporting_capability', $callback, 10, 1 );
Description
This filter controls user capability required to access Uncanny Tin Can reporting. Modify the 'tincanny_reporting' parameter to change the required capability, allowing for granular permission management for report viewing.
Usage
add_filter( 'uo_tincanny_reporting_capability', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Filters the capability required to access Uncanny Tin Can reporting.
*
* This function checks if the current user has the 'administrator' role.
* If not, it adds a new capability 'uo_custom_reporting_access' to the list
* of required capabilities. This allows for more granular control over
* who can access the reporting features.
*
* @param string $capability The default capability required for reporting.
* @return string The modified capability or capabilities.
*/
add_filter( 'uo_tincanny_reporting_capability', function( $capability ) {
// Check if the current user is an administrator.
if ( current_user_can( 'administrator' ) ) {
return $capability; // Administrators always have access.
}
// If not an administrator, we might want to allow access based on a custom role
// or a different capability. For this example, let's assume we have a custom
// capability 'uo_custom_reporting_access' that grants access.
// In a real-world scenario, you might check against specific custom roles
// or other conditions.
// We are essentially adding an OR condition. If they have the original capability
// OR this new one, they get access.
// For simplicity, we'll just return the new capability if they are NOT an admin.
// A more complex scenario might involve returning an array of capabilities:
// return ['tincanny_reporting', 'uo_custom_reporting_access'];
// For this realistic example, let's assume we're adding a new capability
// that *also* grants access, and the system will check for either.
// If you were checking for *only* this new capability if not an admin,
// you might do:
// return 'uo_custom_reporting_access';
// To illustrate a common use case: allowing a specific custom role
// like 'tutor' to also access reporting.
// In a real plugin, you'd likely have a setting to define these roles.
$allowed_custom_roles = array( 'tutor', 'editor' ); // Example custom roles
$user = wp_get_current_user();
$can_access_via_custom_role = false;
foreach ( $user->roles as $role ) {
if ( in_array( $role, $allowed_custom_roles ) ) {
$can_access_via_custom_role = true;
break;
}
}
if ( $can_access_via_custom_role ) {
// Return the original capability as is, assuming the check within
// the plugin will be OR'd with other capabilities.
// OR, if the system expects a single capability and you want to enforce
// that specific custom roles get a *different* capability check,
// you might return a unique one.
// For this example, we'll assume the system checks for the original
// capability OR any other returned by this filter.
return $capability;
}
// If none of the above conditions are met, they don't have reporting access.
// Returning a non-existent capability or an empty string would effectively deny access.
// For demonstration, let's return a distinct capability that might be checked elsewhere.
return 'uo_restricted_reporting_view'; // A placeholder for users without access via default or custom roles.
}, 10, 1 ); // Priority 10, 1 accepted argument.
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/init.php:25
src/uncanny-tincan/classes/Database/Admin.php:148
src/uncanny-tincan/classes/Database/Admin.php:313
src/uncanny-tincan/classes/Database/Admin.php:385
src/uncanny-tincan/classes/Database/Admin.php:560
src/uncanny-tincan/classes/Database/Admin.php:584
src/uncanny-tincan/classes/Database/Admin.php:608
src/uncanny-tincan/classes/Database/Admin.php:655
src/uncanny-tincan/classes/Database/Admin.php:707
src/uncanny-tincan/classes/Database/Admin.php:758
src/uncanny-tincan/classes/Database/Admin.php:807
src/uncanny-tincan/classes/Database/Admin.php:850
src/uncanny-tincan/classes/Database/Admin.php:910
src/uncanny-tincan/classes/Database/Admin.php:943
src/uncanny-tincan/classes/Database/Admin.php:1345
src/shortcode-tincanny/shortcode-tincanny.php:1160
src/reporting-admin-menu.php:54
src/reporting-admin-menu.php:138
src/reporting-admin-menu.php:160
src/reporting-admin-menu.php:182
src/reporting-admin-menu.php:207
src/reporting/learndash/courses-users-report/misc-functions.php:52
function uncanny_learndash_reporting_plugin_activate() {
// Set which roles will need access to reporting
$set_role_for_reporting = array( 'group_leader', 'administrator' );
// Loop through all roles that need the reporting capability added
foreach ( $set_role_for_reporting as $role ) {
// Get the role class instance
$group_leader_role = get_role( $role );
if ( ! $group_leader_role ) {
continue;
}
// Add the reporting capability to the role
$group_leader_role->add_cap( apply_filters( 'uo_tincanny_reporting_capability', 'tincanny_reporting' ) );
}
update_option( 'uncanny_learndash_reporting_plugin_do_activation_redirect', 'yes' );
}