WPML
状态
已解决
解决于
4.4.12

问题概述

在某些情况下,小工具翻译可能无法在站点的前端显示,并且您会看到以下错误:

PHP Warning: array_merge(): Expected parameter 1 to be an array, null given in …\wp-content\plugins\sitepress-multilingual-cms\classes\widgets\class-wpml-widgets-support-frontend.php on line 61

临时解决方法

此问题将在下一个 WPML 版本中修复,但在此期间您可以使用以下临时解决方法:


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

  2. 前往 /plugins/sitepress-multilingual-cms/classes/widgets/ 文件夹。

  3. 打开 class-wpml-widgets-support-frontend.php 文件并将第 56-67 行:
        private function it_must_display( $instance ) {
            if ( isset ( $instance['content'] ) ) {
                $matches  = Str::matchAll( self::TERM_REGEX, $instance['content'] );
                $matches  = Fns::map( pipe( Lst::nth( 0 ), Json::toArray() ), $matches );
                if ( count( $matches ) > 0 ) {
                    $instance = array_merge(...$matches);
                }
            }
     
            return Lst::includes( Obj::propOr( null, 'wpml_language', $instance ), [ null, $this->current_language, 'all' ] );
        }
    }


  4. 替换为:
        private function it_must_display( $instance ) {
            return ! array_key_exists( 'wpml_language', $instance )
                   || $instance['wpml_language'] === $this->current_language
                   || 'all' === $instance['wpml_language'];
        }
    }

所有已知问题 →