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 มีให้ จะไม่เกิดปัญหานี้ เนื่องจากมีการใช้ magic method `WP_Object_Cache::__get()`

อย่างไรก็ตาม เมธอดนี้ใช้สำหรับอ่านพร็อพเพอร์ตี้ `cache` ซึ่งแท้จริงแล้วเป็น private

การใช้งานคลาสนี้แบบกำหนดเองอาจไม่มี magic method ให้ใช้งาน จึงทำให้เกิดข้อผิดพลาดร้ายแรง

วิธีแก้ปัญหาชั่วคราว

สำหรับวิธีแก้ปัญหาชั่วคราว คุณสามารถทำตามขั้นตอนเหล่านี้ (โปรดอ่านหมายเหตุด้านล่าง):


  • เปิดไฟล์ที่ `wp-content/plugins/wpml-string-translation/inc/package-translation/inc/wpml-package-translation-helper.class.php`

  • ค้นหาเมธอด `flush_cache` ประมาณบรรทัดที่ 369 คุณจะเห็นโค้ดนี้:
    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)

ปัญหาที่ทราบแล้วทั้งหมด →