跳到内容 跳到侧边栏

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

发表回复

保持话题相关并尊重他人。如果您需要与此帖子无关的问题帮助,请使用我们的支持论坛开始聊天或提交工单。

您可以使用这些标签:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>