WPML
状态
未解决
报告针对
Advanced Custom Fields Multilingual 2.1.3
相关插件/主题
Advanced Custom Fields (ACF)
主题标签
Compatibility

问题概述

在翻译包含带有单选按钮选项的 Advanced Custom Fields (ACF) 图库区块的页面时,这些单选选项会意外出现在高级翻译编辑器 (ATE) 中。

临时解决方法

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


  • 打开您主题的functions.php文件。

  • 添加以下代码:
    // WPML Workaround for compsupp-7404
    add_filter( 'wpml_found_strings_in_block', function( array $strings, WP_Block_Parser_Block $block ) {
    
    	$isInBlacklistedStrings = function( string $fieldName ) {
    		
    		// Add the fields to ignore here
    		$fieldsToIgnore = [];
    		$fieldsToIgnore[] = 'gallery_section_type';
    		$fieldsToIgnore[] = 'gallery_section_variant';
    
    		if ( in_array($fieldName, $fieldsToIgnore) ) {
    			return true;
    		}
    
    		return false;
        };
    
    	if ( $block->blockName == 'acf/gallery' ) {
    		foreach( $block->attrs['data'] as $fieldName => $string ) {
    			if ( $isInBlacklistedStrings( $fieldName ) ) {
    				unset( $block->attrs['data'][ $fieldName ] );
    			}
    		}
    	}
    
        return $strings;
    }, 9, 2 ); // Lower priority than 10.

所有已知问题 →