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'];
        }
    }

すべての既知の問題 →