Vai al contenuto Vai alla barra laterale

Waiting for author

Topic Tags: Compatibility

Overview of the issue

When using Dokan with WPML configured in different domains per language mode, the language switcher may generate invalid URLs containing an extra domain prefix. For example, switching to French might result in a URL like “https://domain.com/fr/https://domain.fr/” instead of the correct “https://domain.fr”.

Workaround

Please, make sure of having a full site backup of your site before proceeding.

  • Open the …/wp-content/plugins/dokan-wpml/dokan-wpml.php file.
  • Look for line 1871.
  • Replace:
    			public function filter_language_switcher_url( $url, $lang ) {
        $lang_code = $lang['code'] ?? '';
        if ( empty( $url ) || empty( $lang_code ) ) {
            return $url;
        }
    
        // Get home URL without WPML modifications.
        $this->disable_url_translation();
        $home_url = home_url();
        $this->enable_url_translation();
    
        $default_language_code     = wpml_get_default_language();
        $language_negotiation_type = (int) apply_filters( 'wpml_setting', 1, 'language_negotiation_type' );
        $is_parameter_based        = ( WPML_LANGUAGE_NEGOTIATION_TYPE_PARAMETER === $language_negotiation_type );
    
        if ( ! $is_parameter_based && $default_language_code !== $lang_code ) {
            $base_url = trailingslashit( $home_url ) . $lang_code;
        } else {
            $base_url = $home_url;
        }
    
            
  • With:
    			public function filter_language_switcher_url( $url, $lang ) {
        $lang_code = $lang['code'] ?? '';
        if ( empty( $url ) || empty( $lang_code ) ) {
            return $url;
        }
    
        $language_negotiation_type = (int) apply_filters( 'wpml_setting', 1, 'language_negotiation_type' );
    
        if ( WPML_LANGUAGE_NEGOTIATION_TYPE_DOMAIN === $language_negotiation_type ) {
            return $url;
        }
    
        $this->disable_url_translation();
        $home_url = home_url();
        $this->enable_url_translation();
    
        $default_language_code  = wpml_get_default_language();
        $is_parameter_based     = ( WPML_LANGUAGE_NEGOTIATION_TYPE_PARAMETER === $language_negotiation_type );
    
        if ( ! $is_parameter_based && $default_language_code !== $lang_code ) {
            $base_url = trailingslashit( $home_url ) . $lang_code;
        } else {
            $base_url = $home_url;
        }
    
            
  • Save the file and clear your site cache

Lascia una risposta

Per favore rimani in tema e sii rispettoso verso gli altri. Se hai bisogno di aiuto con problemi non relativi a questo post, usa il nostro Forum di Supporto per iniziare una chat o inviare un ticket.

Puoi usare questi tag:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>