Filter tin-canny-learndash-reporting

tincanny_can_get_data

Filters whether the current user can access Tincanny data, based on the 'manage_options' capability.

add_filter( 'tincanny_can_get_data', $callback, 10, 1 );

Description

Allows developers to filter the capability required to access Tincanny data. This hook is ideal for customizing access control beyond the default 'manage_options' capability, ensuring only authorized users can retrieve Tincanny report data.


Usage

add_filter( 'tincanny_can_get_data', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Conditionally allows access to specific reporting data based on user capabilities.
 *
 * This filter allows administrators to further restrict access to sensitive reporting
 * data. By default, it checks for the 'manage_options' capability, which is standard
 * for WordPress administrators. This example demonstrates how a plugin might
 * leverage this filter to grant access to a custom role or a more specific capability
 * if needed.
 *
 * @param string $capability The capability required to access the data. Defaults to 'manage_options'.
 * @return string The updated capability string if modified, otherwise the original.
 */
add_filter( 'tincanny_can_get_data', 'my_custom_tincanny_data_access', 10, 1 );

function my_custom_tincanny_data_access( $capability ) {
    // Check if the current user has the 'edit_posts' capability AND is also a subscriber (for demonstration).
    // In a real scenario, you might check for a specific custom role or a more granular capability.
    if ( current_user_can( 'edit_posts' ) && current_user_can( 'subscriber' ) ) {
        // If the conditions are met, allow access. We return the original capability,
        // but this could be changed to a more specific capability if needed.
        return $capability;
    }

    // If the custom conditions are not met, return the default capability or an empty string
    // to deny access implicitly if the user doesn't meet the default 'manage_options'.
    // Returning 'manage_options' ensures the default check still applies.
    return 'manage_options';
}

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/templates/admin-header.php:17
src/reporting/learndash/frontend-reports/quiz-module-reports.php:61
src/reporting/learndash/courses-users-report/rest-routes.php:231

* Variables:
 * $tab_active   The ID of the active tab
 */

$tabs = [];

$manage_content_cap = apply_filters( 'tc_manage_content_cap', 'manage_options' );
$capability         = apply_filters( 'tincanny_can_get_data', 'manage_options' );


// Restrict endpoint to only users who have the manage_options capability.
if ( current_user_can( $capability ) ) {
	$tabs = [
		(object) [
			'id'   => 'uncanny-learnDash-reporting',


Scroll to Top