Files
heretek-control-core/tests/ElementCacheFlushTest.php
T
Mian Shahzad RazaandClaude Opus 4.8 a63ed73c93 fix(#111): invalidate Elementor 4.2 element cache on data writes
MCP-created pages rendered empty on Elementor 4.2.x: create-page writes empty
[] data, an intermediate render caches an empty _elementor_element_cache, and
the plugin's raw update_post_meta() write path never invalidated it (Elementor
only clears it in Document::save(), which the CLI/proxy fallback bypasses). On a
persistent object cache (WP Engine) the stale empty entry survives every content
write, so the page serves the cached empty render forever.

Add EMCP_Tools_Data::init() — an added/updated_post_meta hook that clears
_elementor_element_cache whenever _elementor_data changes, from ANY write path —
plus an explicit clear in the save fallback. Also fixes delayed visibility of
edits to existing pages. Root-caused + fix live-verified on Elementor 4.2.2.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-08-11 22:06:26 +05:00

32 lines
1.2 KiB
PHP

<?php
/**
* Public unit test for EMCP_Tools_Data::flush_element_cache_on_data_write() —
* the issue #111 fix that invalidates Elementor 4.2's rendered-element cache
* whenever `_elementor_data` is written (so MCP-created pages never serve a
* stale/empty cached render). Behaviour is fully live-verified on a real
* Elementor 4.2.2 site; this pins the key-matching logic.
*
* @package EMCP_Tools
*/
require_once dirname( __DIR__ ) . '/includes/class-elementor-data.php';
class ElementCacheFlushTest extends \PHPUnit\Framework\TestCase {
protected function setUp(): void {
emcp_test_reset();
$GLOBALS['emcp_test']['deleted_meta'] = array();
}
public function test_clears_element_cache_when_elementor_data_written() {
EMCP_Tools_Data::flush_element_cache_on_data_write( 5, 42, '_elementor_data' );
$this->assertContains( array( 42, '_elementor_element_cache' ), $GLOBALS['emcp_test']['deleted_meta'] );
}
public function test_ignores_other_meta_keys() {
EMCP_Tools_Data::flush_element_cache_on_data_write( 5, 42, '_edit_lock' );
EMCP_Tools_Data::flush_element_cache_on_data_write( 5, 42, '_elementor_css' );
$this->assertSame( array(), $GLOBALS['emcp_test']['deleted_meta'] );
}
}