Filter uncanny-learndash-groups

ulgm_group_management_page_link

Filters the ID of the group management page before it's displayed on the admin menu.

add_filter( 'ulgm_group_management_page_link', $callback, 10, 2 );

Description

Filters the URL or ID of the group management page. Allows developers to dynamically change which page is designated as the group management page, or to modify the generated permalink. Useful for custom integrations or redirecting users to a different page.


Usage

add_filter( 'ulgm_group_management_page_link', 'your_function_name', 10, 2 );

Parameters

$group_management_page_id (mixed)
This parameter is intended to hold the ID of the group management page.
$group_management_page_id (mixed)
This parameter contains the ID of the group management page, which is retrieved from the WordPress options.

Return Value

The filtered value.


Examples

/**
 * Example: Modify the group management page URL to prepend a custom subdomain.
 *
 * This filter allows you to alter the generated URL for the group management page.
 * For instance, you might want to route it through a specific subdomain for
 * organizational purposes.
 */
add_filter( 'ulgm_group_management_page_link', function( $group_management_page_url, $group_management_page_id ) {
    // Check if the group management page URL is not empty and if it's a valid page ID.
    if ( ! empty( $group_management_page_url ) && is_numeric( $group_management_page_id ) ) {
        // Example: Prepend a hypothetical "members" subdomain to the URL.
        // In a real-world scenario, you would need server-side configuration
        // to handle this subdomain correctly.
        $subdomain_prefix = 'members.';
        $modified_url = str_replace( home_url(), home_url( '', 'https' ) . $subdomain_prefix, $group_management_page_url );

        // You could also perform other modifications, like adding query parameters,
        // based on conditions or other data.

        return $modified_url;
    }

    // If modifications aren't possible or desired, return the original URL.
    return $group_management_page_url;
}, 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/handlers/class-group-management-pages.php:159

public function get_group_management_page_id( $url = false ) {
		SharedFunctions::$group_management_page_id = get_option( 'ulgm_group_management_page', '' );

		// Return URL
		if ( $url && ! empty( SharedFunctions::$group_management_page_id ) ) {
			return apply_filters( 'ulgm_group_management_page_link', get_permalink( (int) SharedFunctions::$group_management_page_id ), (int) SharedFunctions::$group_management_page_id );
		}

		// Return ID
		return SharedFunctions::$group_management_page_id;
	}

Scroll to Top