Skip to content

fix(import): preserve tab fields and group subfields during JSON import#22

Closed
huongcodecb1992 wants to merge 1 commit into
masterfrom
fix/import-missing-tabs-and-subfields
Closed

fix(import): preserve tab fields and group subfields during JSON import#22
huongcodecb1992 wants to merge 1 commit into
masterfrom
fix/import-missing-tabs-and-subfields

Conversation

@huongcodecb1992

Copy link
Copy Markdown
Contributor

@huongcodecb1992
huongcodecb1992 requested a review from rilwis May 13, 2026 09:22
@opencode-agent

Copy link
Copy Markdown

Based on my analysis of the changes, I've identified the following issues:

Issues Found

1. Potential Key Collision in convert_fields_for_builder() (MetaBox.php:497-501)

The new code for handling tab fields may cause key collisions:

if ( isset( $field['type'] ) && $field['type'] === 'tab' ) {
    unset( $fields[ $id ] );
    $fields[ $field['_id'] ?? $field['id'] ] = $field;
    continue;
}

If a tab field's _id (or id) happens to be the same as an existing numeric key in the $fields array, this will overwrite the existing entry silently.

2. Missing Group Subfield Handling

The PR title mentions "preserve tab fields and group subfields during JSON import", but the changes only address tab fields. There is no handling added for preserving group subfields. The convert_fields_for_builder method recursively processes group subfields (line 508-510), but the structural keys in Field.php ('_id', 'fields', 'tab') don't specifically address group subfield preservation.

3. Incomplete Tab Array Check in unparse_tabs() (MetaBox.php:189-192)

if ( ! in_array( $field['tab'], $added_tabs, true ) ) {
    $new_fields[ $field['tab'] ] = $tab_field;
    $added_tabs[]                = $field['tab'];
}

The original code incorrectly added $tab_field (the entire field array) instead of $field['tab'] (the tab ID string) to $added_tabs. While this bug is fixed, there's still an edge case: if multiple different tab labels map to the same tab ID, only the first encountered tab field will be added.

4. Potential Null Coalesce Issue in convert_fields_for_builder() (MetaBox.php:499)

$fields[ $field['_id'] ?? $field['id'] ] = $field;

If neither _id nor id exists on a tab field, this will generate a PHP Notice (undefined index) and the field may be lost.

New%20session%20-%202026-05-13T09%3A23%3A05.962Z
opencode session  |  github run

@rilwis

rilwis commented May 26, 2026

Copy link
Copy Markdown
Member

Ko cần nữa do đã fix ở đây: wpmetabox/meta-box-builder#186

@rilwis rilwis closed this May 26, 2026
@rilwis
rilwis deleted the fix/import-missing-tabs-and-subfields branch May 26, 2026 04:32
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