Filter uncanny-learndash-groups

ulgm_allow_assets_for_custom_uo_groups

Filters whether to allow assets for custom user organization groups, firing when assets are being loaded.

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

Description

Allows developers to conditionally enable frontend assets for Uncanny LearnDash Groups custom user-defined groups. By default, assets are only enqueued if the `uo_groups` shortcode or block is present. Returning `true` from this filter will force asset enqueuing, overriding the default check. Useful for custom integrations or specific page layouts.


Usage

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

Parameters

$post (mixed)
This parameter is the default value for whether to allow assets for custom user role groups, and can be filtered by other plugins.

Return Value

The filtered value.


Examples

/**
 * Conditionally allows Uncanny Groups assets to be enqueued even if the
 * main 'uo_groups' shortcode or block is not present on the page.
 *
 * This filter is useful if you're programmatically displaying Uncanny Groups
 * content elsewhere on your site or need assets for custom integrations
 * that don't directly use the provided shortcode or block.
 *
 * @param bool  $allow_assets Whether to allow assets to be enqueued. Default is false.
 * @param WP_Post|null $post The current post object.
 *
 * @return bool True to allow assets, false otherwise.
 */
add_filter( 'ulgm_allow_assets_for_custom_uo_groups', function( $allow_assets, $post ) {

    // Check if we're in the admin area and not on a frontend post object.
    if ( is_admin() || ! is_a( $post, 'WP_Post' ) ) {
        return $allow_assets; // Don't interfere with admin or non-post contexts.
    }

    // Example: Allow assets if a specific custom meta field is present on the post.
    // This assumes you have a custom field named 'custom_groups_integration'
    // that you set to 'true' on posts where you want Uncanny Groups assets
    // to load without the default shortcode/block.
    $custom_integration_enabled = get_post_meta( $post->ID, 'custom_groups_integration', true );

    if ( 'true' === $custom_integration_enabled ) {
        return true; // Allow assets because the custom meta field is set.
    }

    // Example: Allow assets if the current post type is a specific custom post type.
    // Replace 'my_custom_content_type' with the actual slug of your CPT.
    // $allowed_post_types = array( 'my_custom_content_type', 'another_type' );
    // if ( in_array( $post->post_type, $allowed_post_types ) ) {
    //     return true;
    // }

    // If none of the custom conditions are met, return the original value (likely false).
    return $allow_assets;

}, 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/group-management/group-management-interface.php:182

public function uo_group_management_scripts() {

		global $post;
		$add_thru_custom_code = apply_filters( 'ulgm_allow_assets_for_custom_uo_groups', false, $post );
		// Only add scripts if shortcode is present on page
		if ( Utilities::has_shortcode( $post, 'uo_groups' ) || Utilities::has_block( $post, 'uncanny-learndash-groups/uo-groups' ) || true === $add_thru_custom_code ) {
			self::enqueue_frontend_assets();
		}

		if ( Utilities::has_shortcode( $post, 'uo_groups_button' ) ) {
			self::enqueue_button_frontend_assets();
		}
	}

Scroll to Top