ข้ามไปยังเนื้อหาหลัก ข้ามไปยังแถบด้านข้าง

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>