Filter uncanny-toolkit-pro

uo_show_groups_login_form

Filters whether to display the groups login form, controlling its visibility on the frontend.

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

Description

Filters whether to display the LearnDash groups login form. Return `false` to hide the form, useful for redirecting logged-in users or integrating custom login logic. The `$context` parameter provides information about where the form is being displayed.


Usage

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

Parameters

$context (mixed)
This parameter determines whether the groups login form should be displayed.

Return Value

The filtered value.


Examples

/**
 * Filter example for 'uo_show_groups_login_form' to conditionally hide the login form
 * based on a custom user meta key.
 *
 * This example demonstrates how to use the filter to prevent the groups login form
 * from displaying if a specific user meta key indicates they should not see it.
 *
 * @param mixed $show_form The default value, usually true.
 * @param mixed $context   The context provided by the original function.
 * @return mixed           Returns false to hide the form, or the original $show_form value to show it.
 */
function my_custom_hide_groups_login_form( $show_form, $context ) {
    // Check if the current user is logged in.
    if ( is_user_logged_in() ) {
        $current_user_id = get_current_user_id();

        // Retrieve a custom meta key for the user. Let's assume 'disable_group_login'
        // If this meta key is set to 'yes', we'll hide the form.
        $disable_login = get_user_meta( $current_user_id, 'disable_group_login', true );

        if ( 'yes' === $disable_login ) {
            // Return false to prevent the filter from returning true, thus hiding the form.
            return false;
        }
    }

    // If the conditions are not met, return the original value to allow the form to display.
    return $show_form;
}
add_filter( 'uo_show_groups_login_form', 'my_custom_hide_groups_login_form', 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/learn-dash-group-sign-up.php:733

public static function groups_login_form( $context = '' ) {
		if( true !== apply_filters( 'uo_show_groups_login_form', true, $context ) ) {
			return;
		}

		if ( is_user_logged_in() ) {
			ob_start();
			esc_html_e( 'You're already signed in! We hope you're enjoying our courses.', 'uncanny-pro-toolkit' );
			$page_link = self::get_page_link_settings( 'uo_groups_page_link' );
			$page_text = self::get_page_link_settings( 'uo_groups_page_link_text' );
			if ( self::is_url( $page_link ) ) {
				printf( '<br /><a href="%s">%s</a>', esc_url( $page_link ), esc_html( $page_text ) );
			}

			return ob_get_clean();
		} else {
			ob_start();
			$form_template = self::get_template( 'groups-login-form.php', dirname( dirname( __FILE__ ) ) . '/src' );
			$form_template = apply_filters( 'uo_group_login_form_template', $form_template );
			include $form_template;

			return ob_get_clean();
		}
	}


Scroll to Top