Skip to content

Commit ca4b9a3

Browse files
committed
Fix meta array storage and output
1 parent cdfd964 commit ca4b9a3

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

classes/class-connector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ public function delayed_log_commit() {
214214

215215
/**
216216
* Compare two values and return changed keys if they are arrays
217+
* x
217218
*
218219
* @param mixed $old_value Value before change.
219220
* @param mixed $new_value Value after change.

classes/class-db-driver-wpdb.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,17 @@ public function insert_record( $data ) {
7979
$record_id = $wpdb->insert_id;
8080

8181
// Insert record meta.
82-
foreach ( (array) $meta as $key => $vals ) {
83-
foreach ( (array) $vals as $val ) {
82+
foreach ( (array) $meta as $key => $val ) {
83+
if ( is_array( $val ) ) {
84+
$vals = $val;
85+
foreach ( $vals as $k => $val ) {
86+
if ( is_scalar( $val ) && '' !== $val ) {
87+
$this->insert_meta( $record_id, $key . '[' . $k . ']', substr( $val, 0, 200 ) );
88+
}
89+
}
90+
} else {
8491
if ( is_scalar( $val ) && '' !== $val ) {
85-
$this->insert_meta( $record_id, $key, $val );
92+
$this->insert_meta( $record_id, $key, substr( $val, 0, 200 ) );
8693
}
8794
}
8895
}

classes/class-list-table.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,20 @@ public function column_default( $item, $column_name ) {
334334
);
335335
}
336336
if ( $record->meta ) {
337-
$out .= '<details><summary>' . esc_html__( 'Metadata', 'stream' ) . '</summary><pre>' . esc_html( print_r( $record->meta, true ) ) . '</pre></details>';
337+
$meta = array();
338+
foreach ( $record->meta as $key => $value ) {
339+
if ( false === strpos( $key, '[' ) ) {
340+
$meta[ $key ] = $value;
341+
} else {
342+
$main_key = substr( $key, 0, strpos( $key, '[' ) );
343+
$sub_key = substr( $key, strpos( $key, '[' ) + 1, - 1 );
344+
345+
$meta[ $main_key ][ $sub_key ] = $value;
346+
}
347+
}
348+
$out .= '<details><summary>' . esc_html__( 'Metadata', 'stream' ) . '</summary><pre>';
349+
$out .= esc_html( print_r( $meta, true ) );
350+
$out .= '</pre></details>';
338351
}
339352
$out .= $this->get_action_links( $record );
340353
break;

0 commit comments

Comments
 (0)