Skip to content

Commit

Permalink
[N/A] Reset block ID transient on new requests to prevent changing (#140
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bd-viget authored Jul 31, 2024
1 parent 5e93807 commit 62c3db0
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static function init(): void {
// Register block patterns within block folders
self::register_block_patterns();

// Reset block IDs on a new request
self::reset_block_ids();

// Add unique, persistent IDs to each ACF block.
self::create_block_id();
}
Expand Down Expand Up @@ -461,7 +464,7 @@ public static function store_block_id( string $block_id ): void {

if ( ! in_array( $block_id, self::$block_ids, true ) ) {
self::$block_ids[] = $block_id;
set_transient( self::BLOCK_IDS_TRANSIENT, self::$block_ids, 1 );
set_transient( self::BLOCK_IDS_TRANSIENT, self::$block_ids, 5 );
}
}

Expand Down Expand Up @@ -490,4 +493,20 @@ private static function load_block_ids(): void {
}
}
}

/**
* Reset the block IDs on a new request.
*
* @return void
*/
private static function reset_block_ids(): void {
add_action(
'acf/init',
function() {
if ( empty( self::$block_ids ) ) {
delete_transient( self::BLOCK_IDS_TRANSIENT );
}
}
);
}
}

0 comments on commit 62c3db0

Please sign in to comment.