Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Unparsers/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,13 @@ private function unparse_custom_settings(): self {

$all_keys = \MBB\Helpers\FieldKeys::all();

$structural_keys = [ '_id', 'fields', 'tab' ];

// Move any unrecognized key into custom_settings format.
$custom_settings = $this->settings['custom_settings'] ?? [];

foreach ( $this->original_keys as $key ) {
if ( in_array( $key, $all_keys, true ) || ! isset( $this->settings[ $key ] ) ) {
if ( in_array( $key, $all_keys, true ) || in_array( $key, $structural_keys, true ) || ! isset( $this->settings[ $key ] ) ) {
continue;
}

Expand Down
19 changes: 11 additions & 8 deletions src/Unparsers/MetaBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public function unparse() {
$this->unparse_post_fields();
$this->unparse_modified();
$this->unparse_settings();
$this->unparse_fields();
$this->unparse_custom_table();
$this->unparse_tabs();
$this->unparse_fields();
$this->unparse_validation();
$this->unparse_geo_location();
$this->unparse_columns();
Expand Down Expand Up @@ -151,12 +151,10 @@ private function unparse_tabs(): self {
];
$this->settings['settings']['custom_settings'] = $custom_settings;

// Rebuild fields with tab fields first
$added_tabs = [];
$original_fields = $this->settings['fields'] ?? [];
$original_fields = $this->settings['meta_box']['fields'] ?? [];
$new_fields = [];

// Add fields under this tab
foreach ( $original_fields as $id => $field ) {
if ( ! isset( $field['tab'] ) ) {
$new_fields[ $id ] = $field;
Expand Down Expand Up @@ -188,16 +186,15 @@ private function unparse_tabs(): self {
'icon_url' => $icon_type === 'url' ? $icon : '',
];

// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
if ( ! in_array( $field['tab'], $added_tabs ) ) {
if ( ! in_array( $field['tab'], $added_tabs, true ) ) {
$new_fields[ $field['tab'] ] = $tab_field;
$added_tabs[] = $tab_field;
$added_tabs[] = $field['tab'];
}

$new_fields[ $id ] = $field;
}

$this->settings['fields'] = $new_fields;
$this->settings['meta_box']['fields'] = $new_fields;
return $this;
}

Expand Down Expand Up @@ -497,6 +494,12 @@ public function unparse_fields(): self {

public function convert_fields_for_builder( $fields = [] ): array {
foreach ( $fields as $id => $field ) {
if ( isset( $field['type'] ) && $field['type'] === 'tab' ) {
unset( $fields[ $id ] );
$fields[ $field['_id'] ?? $field['id'] ] = $field;
continue;
}

$unparser = new Field( $field );
$unparser->unparse();

Expand Down
Loading