- Stato
- Risolto
- Segnalato per
- WPML Multilingual CMS 3.2.7
- Risolto in
- 3.3.2
Panoramica del problema
Quando utilizzi l’implementazione della cache di WPEngine o altre implementazioni personalizzate, potrebbe comparire un errore fatale come questo:
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
Ciò è causato dal tentativo di WPML di svuotare le cache per gruppo.
Quando utilizzi la cache standard fornita da WordPress, questo non è un problema, poiché utilizza il metodo magico `WP_Object_Cache::__get()`.
Tuttavia, questo metodo viene utilizzato per leggere la proprietà `cache`, che in realtà è privata.
Le implementazioni personalizzate di questa classe potrebbero non avere il metodo magico disponibile, da qui l’errore fatale.
Soluzione alternativa
Come soluzione alternativa temporanea puoi seguire questi passaggi (leggi la nota in basso):
- Apri il file in `wp-content/plugins/wpml-string-translation/inc/package-translation/inc/wpml-package-translation-helper.class.php`
- Cerca il metodo `flush_cache` intorno alla riga 369. Dovresti vedere questo codice:
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 ); } } } - Sostituisci queste righe con:
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(); } }