Skip to content

Fix: Filter allowed blocks through AllowedBlockLists::filter_valid_blocks()#23

Merged
rilwis merged 1 commit into
masterfrom
fix/allowed-blocks-validation
Jul 4, 2026
Merged

Fix: Filter allowed blocks through AllowedBlockLists::filter_valid_blocks()#23
rilwis merged 1 commit into
masterfrom
fix/allowed-blocks-validation

Conversation

@doanducanh

Copy link
Copy Markdown

Bug được report trong ticket: https://helpdesk.elightup.com/conversation/13686?folder_id=35

Lỗi xảy ra

  • PHP Fatal error: Allowed memory size exhausted (256MB).

Nguyên nhân

  • Meta Box Builder (trong Meta Box AIO mà khách đang sử dụng) lưu danh sách allowed blocks vào option mbb_allowed_block_lists.
  • Option này đã phình lên rất lớn (lên tới vài chục MB), khiến quá trình xử lý bị vượt quá giới hạn bộ nhớ PHP.

Đoạn code gây ra vấn đề

  • vendor/wpmetabox/mbb-parser/src/Unparsers/Field.php
  • Hàm: unparse_field_block_editor()

Giải thích
Khách trước đây đã cài một plugin tên gothe (hiện đã deactivate), plugin này đăng ký hai block:

  • consenta/conditional-content
  • consenta/consent-status

Hai block này vẫn còn được lưu trong database.

Trong mỗi lần chạy:

  • $list chỉ chứa danh sách các block hiện đang được đăng ký.
  • $blocks lại vẫn chứa cả consenta/conditional-contentconsenta/consent-status.

Do $list$blocks luôn khác nhau, Meta Box Builder luôn tạo một danh sách mới và ghi lại vào option mbb_allowed_block_lists, khiến option này liên tục phình to theo thời gian.

Giải pháp
Lọc bỏ các block không còn được đăng ký trước khi so sánh:

$blocks = \MBB\Helpers\AllowedBlockLists::filter_valid_blocks( (array) $this->allowed_blocks );

Việc này sẽ loại bỏ các block không hợp lệ, giúp $blocks chỉ chứa các block đang được đăng ký và ngăn option mbb_allowed_block_lists tiếp tục tăng kích thước không cần thiết.

…ocks()

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
@opencode-agent

opencode-agent Bot commented Jul 4, 2026

Copy link
Copy Markdown

The PR makes a single-line change in src/Unparsers/Field.php:253 — wrapping $this->allowed_blocks with \MBB\Helpers\AllowedBlockLists::filter_valid_blocks() before comparison.

No issues found with this change. The fix is correct and minimal:

  • It addresses the root cause described in the bug report — stale block names in $blocks that never match any stored list cause unbounded growth of the mbb_allowed_block_lists option
  • The pre-existing class_exists guard on line 244 provides a safe fallback if the external class is unavailable
  • The existing empty() check on line 248 already handles the case where $this->allowed_blocks is undefined/null/empty
  • The (array) cast ensures type safety regardless of the property's current value

The only concern is a pre-existing one (not introduced by this PR): the strict array comparison $list['blocks'] === $blocks on line 257 is order-sensitive. If filter_valid_blocks() returns blocks in an order different from how they were originally stored in the database, existing lists will never match, and a new list will be created each time — which would recreate the same memory exhaustion bug. However, this depends entirely on the implementation of filter_valid_blocks() in the external meta-box-builder package, which is outside the scope of this PR.

New%20session%20-%202026-07-04T09%3A10%3A01.029Z
opencode session  |  github run

@rilwis
rilwis merged commit e0663ef into master Jul 4, 2026
1 check passed
@rilwis
rilwis deleted the fix/allowed-blocks-validation branch July 4, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants