Filter tin-canny-learndash-reporting

uo_tincanny_reporting_access_check

Filters the access check for Tincanny reporting, allowing customization of who can view reports.

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

Description

This filter hook, `uo_tincanny_reporting_access_check`, controls access to the frontend Tincanny reports. By default, it returns `false`, preventing access. Developers can filter this to return `true` to grant access, or implement custom logic to manage user permissions for viewing reports, for example, by checking specific user roles or capabilities.


Usage

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

Return Value

The filtered value.


Examples

// Prevent users without a specific role from accessing reporting data.
add_filter(
	'uo_tincanny_reporting_access_check',
	function( $has_access ) {
		// If the default check already determined no access, preserve that.
		if ( false === $has_access ) {
			return $has_access;
		}

		// Check if the current user has the 'administrator' role.
		// This is a common scenario where administrators might have broader access.
		$current_user = wp_get_current_user();
		if ( in_array( 'administrator', (array) $current_user->roles ) ) {
			// If the user is an administrator, grant them access.
			return true;
		}

		// For all other users, return false, meaning they don't have access
		// beyond the default checks.
		return false;
	},
	10,
	1
);

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/shortcode-tincanny/shortcode-tincanny.php:1157
src/shortcode-tincanny/shortcode-tincanny.php:1163
src/shortcode-tincanny/shortcode-tincanny.php:1166

public static function frontend_reports_access_check() {

		if ( ! is_user_logged_in() ) {
			echo esc_html__( 'You must be logged in to view this report.', 'uncanny-learndash-reporting' );

			return apply_filters( 'uo_tincanny_reporting_access_check', false );
		}

		if ( ! current_user_can( apply_filters( 'uo_tincanny_reporting_capability', 'tincanny_reporting' ) ) ) {
			echo esc_html__( 'You do not have access to this report', 'uncanny-learndash-reporting' );

			return apply_filters( 'uo_tincanny_reporting_access_check', false );
		}

		return apply_filters( 'uo_tincanny_reporting_access_check', true );
	}


Scroll to Top