Filter tin-canny-learndash-reporting

tc_manage_content_cap

Filters the capability required to manage content, allowing modification of the permission needed.

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

Description

This filter allows developers to modify the capability required to manage content within the Uncanny Toolkit. By default, it's set to 'manage_options'. Developers can change this to a custom capability or even return false to restrict access based on different user roles or conditions. This hook fires before the admin header is rendered, enabling dynamic capability checks.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Filters the capability required to manage Uncanny Automator content.
 *
 * This example shows how to restrict access to Uncanny Automator's manage
 * content section to users with a custom capability called 'manage_automator_content'
 * instead of the default 'manage_options'.
 *
 * @param string $capability The current capability required.
 *
 * @return string The modified capability.
 */
add_filter( 'tc_manage_content_cap', 'my_custom_automator_manage_content_cap', 10, 1 );

function my_custom_automator_manage_content_cap( $capability ) {
	// Check if the current user has the default 'manage_options' capability.
	// This is a good practice to ensure that if the filter isn't applied
	// or the custom role doesn't exist, access is still controlled by the default.
	if ( current_user_can( 'manage_options' ) ) {
		// If the user has 'manage_options', try to give them a more specific capability.
		// Replace 'manage_automator_content' with your actual custom capability.
		// Ensure this capability is assigned to the roles you want to grant access to.
		if ( current_user_can( 'manage_automator_content' ) ) {
			return 'manage_automator_content';
		}
	}

	// If the user doesn't have 'manage_options' or the custom capability,
	// return the original default capability to ensure the `current_user_can()` check fails correctly.
	// This ensures that if they don't meet the criteria, they won't have access.
	return $capability;
}

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:16
src/uncanny-articulate-and-captivate/classes/Admin/ManageContent.php:58

/**
 * 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) [


Scroll to Top