WPML
状态
已解决
报告针对
WPML Multilingual for CF7 1.2.1
解决于
Contact Form 7 Multilingual 1.2.2
相关插件/主题
Contact Form 7
主题标签
Compatibility

问题概述

当使用Contact Form 7插件和do_shortcode() PHP 方法添加表单时,表单未按预期显示翻译。

临时解决方法

在继续操作之前,请确保对您的站点进行完整备份


  • 打开 …/wp-content/plugins/contact-form-7-multilingual/classes/shortcodes.php 文件。

  • 找到第 21 行。

  • 将:
    	public function translate_shortcode_form_id( $atts ) {
    		$form = null;
    
    		if ( ! empty( $atts['id'] ) ) {
    			$form = wpcf7_contact_form( (int) $atts['id'] );
    		}
    
    		if ( ! $form && ! empty( $atts['title'] ) ) {
    			$form = wpcf7_get_contact_form_by_title( trim( $atts['title'] ) );
    			unset( $atts['title'] );
    		}
    
    		if ( $form ) {
    			$atts['id'] = apply_filters( 'wpml_object_id', $form->id(), Constants::POST_TYPE, true );
    		}
    
    		return $atts;
    	}


  • 替换为:
    	public function translate_shortcode_form_id( $atts ) {
    		$form = null;
    
    		if ( ! empty( $atts['id'] ) && is_numeric($atts['id']) ) {
    			$form = wpcf7_contact_form( (int) $atts['id'] );
    		}
    
    		if ( ! $form && ! empty( $atts['title'] ) ) {
    			$form = wpcf7_get_contact_form_by_title( trim( $atts['title'] ) );
    			unset( $atts['title'] );
    		}
    		if ($form == null){
    			$form = wpcf7_get_contact_form_by_hash( $atts['id']);
    		}
    		if ( $form ) {
    			$atts['id'] = apply_filters( 'wpml_object_id', $form->id(), Constants::POST_TYPE, true );
    		}
    
    		return $atts;
    	}

所有已知问题 →