Filter uncanny-toolkit-pro

uo_time_enable_logout_mode_capability

Filters whether the "logout mode" capability is enabled for a specific course.

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

Description

Filters the capability required to enable logout mode for a course. Developers can modify this to enforce custom user roles or capabilities, granting or restricting access to this feature based on specific permission levels and the course ID.


Usage

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

Parameters

$course_id (mixed)
This parameter represents the capability required to enable logout mode.

Return Value

The filtered value.


Examples

/**
 * Filters the capability required to enable the 'logout mode' for a course.
 *
 * By default, only users with the 'manage_options' capability can enable logout mode.
 * This filter allows you to modify that capability.
 *
 * @param string  $capability  The default capability required (e.g., 'manage_options').
 * @param int     $course_id   The ID of the current course.
 *
 * @return string The modified capability string.
 */
add_filter( 'uo_time_enable_logout_mode_capability', function( $capability, $course_id ) {
	// Example: Allow users with the 'edit_posts' capability to also enable logout mode.
	// You can check for specific course IDs or other conditions here.
	if ( 'manage_options' === $capability && user_can( get_current_user_id(), 'edit_posts' ) ) {
		return 'edit_posts';
	}

	// If the current user has the 'manage_options' capability, they should still be able
	// to enable it regardless of this filter's logic.
	if ( user_can( get_current_user_id(), 'manage_options' ) ) {
		return 'manage_options';
	}

	// For other users, if 'edit_posts' is not sufficient, revert to the default.
	// Or, you could implement stricter logic if needed.
	return $capability;
}, 10, 2 );

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/course-timer.php:1008
src/classes/course-timer.php:2130

if ( '' !== $feature_enable_debug_mode ) {
				$enable_debug_mode = 'true';
			}

			$enable_logout_mode         = 'false';
			$feature_enable_logout_mode = self::get_settings_value( 'enable_logout_mode', __CLASS__ );

			if ( '' !== $feature_enable_logout_mode && ! current_user_can( apply_filters('uo_time_enable_logout_mode_capability', 'manage_options', $course_id) ) ) {
				$enable_logout_mode = 'true';
			}

			// Dialog Box Style
			$dialog_box_style = plugins_url( basename( dirname( UO_FILE ) ) ) . '/src/assets/legacy/frontend/css/jquery.dialogbox.css';
			wp_enqueue_style( 'jquery-dialog-box-style', $dialog_box_style, array(), UNCANNY_TOOLKIT_PRO_VERSION );


Scroll to Top