Pular para o conteúdo Pular para a barra lateral

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

Deixe uma resposta

Por favor mantenha-se no assunto e seja respeitoso com os outros. Se precisar de ajuda com problemas não relacionados a este post, use nosso Fórum de Suporte para iniciar um chat ou enviar um ticket.

Você pode usar estas tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>