WPML
ステータス
解決済み
報告対象
WPML Multilingual CMS 3.2.7
解決されたバージョン
3.3.2

問題の概要

WPEngineのキャッシュ実装やその他のカスタム実装を使用している場合、次のような致命的なエラーが発生する場合があります。

PHP Fatal error: Call to undefined method WP_Object_Cache::__get() in /nas/wp/www/cluster-40022/spms/wp-content/plugins/wpml-string-translation/inc/package-translation/inc/wpml-package-translation-helper.class.php on line 384

これは、WPMLがグループごとにキャッシュをフラッシュしようとすることが原因です。

WordPressが提供する標準のキャッシュを使用している場合、`WP_Object_Cache::__get()`マジックメソッドを使用するため、この問題は発生しません。

ただし、このメソッドは`cache`プロパティを読み取るために使用されますが、このプロパティは実際にはプライベートです。

このクラスのカスタム実装ではマジックメソッドが利用できない場合があるため、致命的なエラーが発生します。

回避策

一時的な回避策として、次の手順を実行します(下部の注意をお読みください)。


  • `wp-content/plugins/wpml-string-translation/inc/package-translation/inc/wpml-package-translation-helper.class.php`ファイルを開きます。

  • 369行目付近の`flush_cache`メソッドを探します。次のコードが表示されます。
    final private function flush_cache() {
    	/** @var WP_Object_Cache $wp_object_cache */
    	global $wp_object_cache;
    	$cache = $wp_object_cache->__get( 'cache' );
    	if ( isset( $cache[ $this->cache_group ] ) ) {
    		foreach ( $cache[ $this->cache_group ] as $cache_key => $data ) {
    			wp_cache_delete( $cache_key, $this->cache_group );
    		}
    	}
    }

  • これらの行を以下に置き換えます。
    final private function flush_cache() {
    	/** @var WP_Object_Cache $wp_object_cache */
    	global $wp_object_cache;
    	$has_cache_property = method_exists( $wp_object_cache, '__get' );
    	if ( ! $has_cache_property && property_exists( $wp_object_cache, 'cache' ) ) {
    		$reflector          = new ReflectionClass( get_class( $wp_object_cache ) );
    		$cache_property     = $reflector->getProperty( 'cache' );
    		$has_cache_property = $cache_property->isPublic();
    	}
    	if ( $has_cache_property ) {
    		$cache = $wp_object_cache->cache;
    		if ( isset( $cache[ $this->cache_group ] ) ) {
    			foreach ( $cache[ $this->cache_group ] as $cache_key => $data ) {
    				wp_cache_delete( $cache_key, $this->cache_group );
    			}
    		}
    	} else {
    		wp_cache_flush();
    	}
    }
注意: この機能は、キャッシュ全体ではなくキャッシュの一部をクリアするために必須です。この回避策を使用するとフラッシュがグローバルに行われるため、パフォーマンスに影響する可能性があります。ただし、この特定のコードは、文字列パッケージ(LayoutsやGravity Formsなど)を削除または更新する場合にのみ実行されます。

すべての既知の問題 →