Filter Uncanny Redemption Codes

uc_allowed_screens

Filters the array of WordPress admin screens where Uncanny Codes features are allowed to load.

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

Description

Filters the list of backend screens where Uncanny Codes assets should be enqueued. Developers can modify this array to include or exclude specific WordPress admin pages, controlling where the plugin's scripts and styles are loaded.


Usage

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

Parameters

$current_screen (mixed)
This parameter contains an array of screen IDs where backend assets should be allowed to enqueue.

Return Value

The filtered value.


Examples

add_filter(
	'uc_allowed_screens',
	function ( $allowed_screens, $current_screen ) {
		// Allow the Uncanny Codes knowledge base and plugins pages.
		// Also allow the top-level Uncanny Codes menu page and its settings.
		$allowed_screens = array_merge(
			$allowed_screens,
			array(
				'uncanny-codes_page_uncanny-codes-kb',
				'uncanny-codes_page_uncanny-codes-plugins',
				'uncanny-codes_page_uncanny-learndash-codes-settings',
				'toplevel_page_uncanny-learndash-codes',
			)
		);

		// Optionally, if we are on a specific post type that the plugin might interact with
		// (e.g., a custom post type for courses if the plugin has deep LearnDash integration),
		// we could add it here as well. For demonstration, let's assume we don't need that.

		return $allowed_screens;
	},
	10, // Priority: Default priority
	2  // Accepted arguments: $allowed_screens and $current_screen
);

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/boot.php:659

public static function should_enqueue_backend_assets() {
		global $pagenow, $current_screen;

		$should_enqueue = false;

		$allowed_screens = apply_filters(
			'uc_allowed_screens',
			array(
				'uncanny-codes_page_uncanny-codes-kb',
				'uncanny-codes_page_uncanny-codes-plugins',
				'uncanny-codes_page_uncanny-learndash-codes-settings',
				'toplevel_page_uncanny-learndash-codes',
			),
			$current_screen
		);

		// Check if it's creating or editing a WooCommerce product
		if ( 'post' === (string) $current_screen->base && 'product' === (string) $current_screen->id ) {
			$should_enqueue = true;
		}

		// Check if it's one of the allowed pages
		if ( 'admin.php' === (string) $pagenow &&
			 ( strpos( (string) $current_screen->base, 'codes_page_uncanny' ) || in_array( $current_screen->base, $allowed_screens ) )
		) {
			$should_enqueue = true;
		}

		return apply_filters( 'ulc_codes_enqueue_backend_assets', $should_enqueue, $current_screen );
	}


Scroll to Top