- 状态
- 已解决
- 报告针对
- 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(); } }