Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix meta field saving for table-based pods #4448

Merged
Merged
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
75 changes: 39 additions & 36 deletions classes/PodsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -3545,55 +3545,58 @@ public function save_pod_item ( $params ) {
$object_data[ $object_name_field ] = $object_name;
}

if ( ( 'meta' == $pod[ 'storage' ] || 'settings' == $pod[ 'type' ] || ( 'taxonomy' == $pod[ 'type' ] && 'none' == $pod[ 'storage' ] ) ) && !in_array( $pod[ 'type' ], array( 'pod', 'table', '' ) ) ) {
if ( $allow_custom_fields && !empty( $custom_data ) )
$object_meta = array_merge( $custom_data, $object_meta );

$fields_to_send = array_flip( array_keys( $object_meta ) );

if ( ! in_array( $pod['type'], array( 'pod', 'table', '' ) ) ) {
$meta_fields = array();

if ( 'meta' === $pod['storage'] || 'settings' === $pod['type'] || ( 'taxonomy' === $pod['type'] && 'none' === $pod['storage'] ) ) {
$meta_fields = $object_meta;
}

if ( $allow_custom_fields && ! empty( $custom_data ) ) {
$meta_fields = array_merge( $custom_data, $meta_fields );
}

$fields_to_send = array_flip( array_keys( $meta_fields ) );

foreach ( $fields_to_send as $field => $field_data ) {
if ( isset( $object_fields[ $field ] ) ) {
$field_data = $object_fields[ $field ];
}
elseif ( isset( $fields[ $field ] ) ) {
} elseif ( isset( $fields[ $field ] ) ) {
$field_data = $fields[ $field ];
}
else {
} else {
unset( $fields_to_send[ $field ] );
}

$fields_to_send[ $field ] = $field_data;
}

$params->id = $this->save_wp_object( $object_type, $object_data, $meta_fields, false, true, $fields_to_send );

if ( ! empty( $params->id ) && 'settings' === $pod['type'] ) {
$params->id = $pod['id'];
}
}

$params->id = $this->save_wp_object( $object_type, $object_data, $object_meta, false, true, $fields_to_send );

if ( !empty( $params->id ) && 'settings' == $object_type )
$params->id = $pod[ 'id' ];
}
else {
if ( ! in_array( $pod[ 'type' ], array( 'pod', 'table', '' ) ) ) {
$params->id = $this->save_wp_object( $object_type, $object_data, array(), false, true );
}

if ( 'table' == $pod[ 'storage' ] ) {
// Every row should have an id set here, otherwise Pods with nothing
// but relationship fields won't get properly ID'd
if ( empty( $params->id ) )
$params->id = 0;
if ( 'table' == $pod['storage'] ) {
// Every row should have an id set here, otherwise Pods with nothing
// but relationship fields won't get properly ID'd
if ( empty( $params->id ) ) {
$params->id = 0;
}

$table_data = array( 'id' => $params->id ) + $table_data;
array_unshift( $table_formats, '%d' );
$table_data = array( 'id' => $params->id ) + $table_data;
array_unshift( $table_formats, '%d' );

if ( !empty( $table_data ) ) {
$sql = pods_data()->insert_on_duplicate( "@wp_pods_{$params->pod}", $table_data, $table_formats );
if ( ! empty( $table_data ) ) {
$sql = pods_data()->insert_on_duplicate( "@wp_pods_{$params->pod}", $table_data, $table_formats );

$id = pods_query( $sql, 'Cannot add/save table row' );
$id = pods_query( $sql, 'Cannot add/save table row' );

if ( empty( $params->id ) )
$params->id = $id;
}
}
}
if ( empty( $params->id ) ) {
$params->id = $id;
}
}
}

$params->id = (int) $params->id;

Expand Down