Filter uncanny-toolkit-pro

wpml_home_url

Filters the WordPress site's home URL before it's retrieved, allowing modification.

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

Description

Filters the home URL used for LearnDash group sign-up links. Developers can modify this URL to point to a custom sign-up page or implement language-specific home URLs. This hook ensures compatibility with WPML's language negotiation settings.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Modifies the home URL when using the 'wpml_home_url' filter to include language information
 * if the site is configured for subdirectory language negotiation and the language is not English.
 *
 * @param string $home_url The original home URL.
 * @return string The potentially modified home URL.
 */
add_filter( 'wpml_home_url', 'custom_wpml_home_url_filter', 10, 1 );

function custom_wpml_home_url_filter( $home_url ) {
    // Check if WPML is active and if language negotiation is set to subdirectories.
    if ( defined( 'ICL_SITEPRESS_VERSION' ) && class_exists( 'SitePress' ) ) {
        global $sitepress;
        $language_negotiation_type = $sitepress->get_setting( 'language_negotiation_type' );

        // If language negotiation is by subdirectories (type 2)
        if ( 2 === (int) $language_negotiation_type ) {
            $current_language_code = $sitepress->get_current_language();

            // If the current language is not the default language (assuming English is default for this example)
            // You might want to fetch the default language dynamically from WPML settings.
            if ( 'en' !== $current_language_code ) {
                // Append the language code as a subdirectory to the home URL.
                // Ensure there's no trailing slash on the original home_url before appending.
                $home_url = rtrim( $home_url, '/' ) . '/' . $current_language_code;
            }
        }
    }

    return $home_url;
}

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:1175
src/classes/learn-dash-group-sign-up.php:1203

public static function wpml_ulgm_admin_signup_link($ulgm_admin_signup_link, $post, $group_key){
		global $sitepress;

		$admin_signup_url = '';
		if ( 1 === (int) $sitepress->get_setting( 'language_negotiation_type' ) ) {
			$home_url = apply_filters( 'wpml_home_url', get_option( 'home' ) );
			$home_url = trim($home_url,'/');
			$url = $home_url . '/sign-up/' . $post->post_name . '/';
			$admin_signup_url = add_query_arg( array(
				'gid' => $post->ID,
			), $url )  . '&' . $group_key;;
		} else if ( 3 === (int) $sitepress->get_setting( 'language_negotiation_type' ) ) {
			$current_language = icl_get_current_language();

			$url = site_url( 'sign-up/' . $post->post_name . '/' );
			$admin_signup_url = add_query_arg( array(
				'lang' => $current_language,
				'gid' => $post->ID,
			), $url )  . '&' . $group_key;;
		}

		if( '' === $admin_signup_url ) {
			$admin_signup_url = $ulgm_admin_signup_link;
		}

		return $admin_signup_url;
	}

Scroll to Top