Filter uncanny-toolkit-pro

uncanny_toolkit_restricted_content_filter

Filters the content that is restricted by Uncanny Toolkit, allowing modifications before it's displayed to the user.

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

Description

Fires before restricted content is displayed. Allows developers to conditionally bypass or modify the restricted content message shown to users who lack access. Developers can return `false` to display the original content or modify the message itself.


Usage

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

Parameters

$content (mixed)
This parameter indicates whether the content restriction should be applied.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the uncanny_toolkit_restricted_content_filter hook.
 *
 * This example will prevent the restricted content message from being displayed
 * if the current user is an administrator.
 *
 * @param bool  $is_restricted  The current restriction status.
 * @param mixed $content        The content being filtered.
 * @return bool                 Whether the content should be restricted.
 */
add_filter( 'uncanny_toolkit_restricted_content_filter', function( $is_restricted, $content ) {

	// If the current user is an administrator, bypass the restriction.
	if ( current_user_can( 'manage_options' ) ) {
		return false; // Do not restrict content for administrators.
	}

	// Otherwise, let the default restriction logic handle it.
	return $is_restricted;

}, 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/restrict-page-access.php:325

public static function restricted_content_filter( $content ) {

		$is_restricted = apply_filters( 'uncanny_toolkit_restricted_content_filter', true, $content );
		
		if( true !== $is_restricted ) {
			return $content;
		}
		
		$message = self::get_settings_value( 'uncanny-restrict-page-access-message', __CLASS__ );
		if ( empty( $message ) ) {
			$message = self::get_message();
		}

		return do_shortcode( nl2br( $message ) );

	}

Scroll to Top