- Trạng thái
- Đã giải quyết
- Được báo cáo cho
- WPML Multilingual CMS 3.2.7
- Đã giải quyết trong
- 3.3.2
Tổng quan về lỗi
Khi sử dụng triển khai bộ nhớ đệm của WPEngine hoặc các triển khai tùy chỉnh khác, một lỗi nghiêm trọng như sau có thể xuất hiện:
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
Điều này là do WPML cố gắng xóa bộ nhớ đệm theo nhóm.
Khi sử dụng bộ nhớ đệm tiêu chuẩn do WordPress cung cấp, đây không phải là vấn đề vì nó sử dụng phương thức magic `WP_Object_Cache::__get()`.
Tuy nhiên, phương thức này được sử dụng để đọc thuộc tính `cache`, vốn thực chất là private.
Các triển khai tùy chỉnh của lớp này có thể không có sẵn phương thức magic, do đó gây ra lỗi nghiêm trọng.
Giải pháp tạm thời
Như một giải pháp tạm thời, bạn có thể làm theo các bước sau (vui lòng đọc phần lưu ý bên dưới):
- Mở tệp tại `wp-content/plugins/wpml-string-translation/inc/package-translation/inc/wpml-package-translation-helper.class.php`
- Tìm phương thức `flush_cache` ở khoảng dòng 369. Bạn sẽ thấy mã này:
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 ); } } } - Thay thế các dòng này bằng:
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(); } }