Filter uncanny-toolkit-pro

toolkit_learndash_user_import_capability

Filters the capability required for importing LearnDash users, allowing customization of import permissions.

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

Description

Filter the capability required to access the LearnDash CSV user import feature. Developers can modify this filter to restrict or allow access based on specific user roles or custom capabilities, overriding the default 'list_users' requirement.


Usage

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

Parameters

$capability (mixed)
This filter allows you to modify the capability required to import LearnDash users from a CSV file.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the capability required to access the LearnDash User Import tool.
 * This example grants access to users with the 'manage_options' capability instead of the default.
 */
add_filter( 'toolkit_learndash_user_import_capability', 'my_custom_learndash_user_import_capability', 10, 1 );

function my_custom_learndash_user_import_capability( $capability ) {
	// By default, the capability might be 'list_users' or something similar.
	// We are changing it here to 'manage_options' which is typically reserved for administrators.
	// You can set it to any valid WordPress capability.
	$custom_capability = 'manage_options';

	// Return the modified capability.
	return $custom_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/classes/import-learndash-users-from-csv.php:248
src/classes/import-learndash-users-from-csv.php:259
src/classes/import-learndash-users-from-csv.php:374
src/classes/import-learndash-users-from-csv.php:727
src/classes/import-learndash-users-from-csv.php:875
src/classes/import-learndash-users-from-csv.php:1656
src/classes/import-learndash-users-from-csv.php:1689

public static function admin_menu() {
		if ( current_user_can( 'list_users' ) ) {
			add_users_page(
				self::$module_name,
				self::$module_name,
				apply_filters( 'toolkit_learndash_user_import_capability', self::$capability ),
				self::$module_key,
				array(
					__CLASS__,
					'cb_admin_menu',
				)
			);
		} else {
			add_dashboard_page(
				self::$module_name,
				self::$module_name,
				apply_filters( 'toolkit_learndash_user_import_capability', self::$capability ),
				self::$module_key,
				array(
					__CLASS__,
					'cb_admin_menu',
				)
			);
		}
	}


Scroll to Top