- Status
- Resolved
- Reported for
- WPML Multilingual CMS 3.2.7
- Resolved in
- 3.3.2
Overview of the issue
When using the caching implementation of WPEngine or other custom implementations, a fatal error as such may appear:
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
This is caused by WPML trying to flush caches by group.
When using the standard caching provided by WordPress, this is not an issue, as it uses the `WP_Object_Cache::__get()` magic method.
However, this method is used to read the `cache` property, which is actually private.
Custom implementations of this class may not have the magic method available, hence the fatal error.
Workaround
As a temporary workaround you can follow these steps (please read the bottom note):
- Open the file at `wp-content/plugins/wpml-string-translation/inc/package-translation/inc/wpml-package-translation-helper.class.php`
- Look for the method `flush_cache` around line 369. You should see this code:
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 ); } } } - Replace these lines with:
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(); } }