From e322f2ebf10ab8ef478908fdf3babe6b67b68974 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 8 May 2020 14:03:46 -0300 Subject: [PATCH] use `delete_metadata_by_mid` to delte post_metadata and fix `get_value_as_html` fo compound multiple --- .../class-tainacan-item-metadata.php | 2 +- .../compound/class-tainacan-compound.php | 44 +++++-------------- 2 files changed, 11 insertions(+), 35 deletions(-) diff --git a/src/classes/repositories/class-tainacan-item-metadata.php b/src/classes/repositories/class-tainacan-item-metadata.php index 38a5964dc..d6b04ffde 100644 --- a/src/classes/repositories/class-tainacan-item-metadata.php +++ b/src/classes/repositories/class-tainacan-item-metadata.php @@ -71,7 +71,7 @@ class Item_Metadata extends Repository { } else { if ( $unique ) { if( empty( $item_metadata->get_value() ) ) { - delete_post_meta( $item_metadata->get_item()->get_id(), $item_metadata->get_metadatum()->get_id() ); + delete_metadata_by_mid( 'post', $item_metadata->get_meta_id() ); } elseif ( is_int( $item_metadata->get_meta_id() ) ) { update_metadata_by_mid( 'post', $item_metadata->get_meta_id(), wp_slash( $item_metadata->get_value() ) ); } else { diff --git a/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php b/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php index 2597665bb..534af6bf0 100644 --- a/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php +++ b/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php @@ -175,54 +175,30 @@ class Compound extends Metadata_Type { return $return; if ( $item_metadata->is_multiple() ) { - - if ( sizeof($value) > 0 ) { - - $return .= '
'; - $count = 0; - - foreach ( $value as $compound_element ) { - $count++; - - if ( sizeof($compound_element) > 0 ) { - - $return .= '
'; - - foreach ( $compound_element as $meta ) { - if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) { - $return .= '\n"; - $return .= '

' . $meta->get_value_as_html() . '

' . "\n\n"; - } + $elements = []; + foreach ( $value as $compound_element ) { + if ( !empty($compound_element) ) { + $metadata_value = ''; + foreach ( $compound_element as $meta ) { + if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) { + $metadata_value .= '

' . $meta->get_value_as_html() . "

\n"; } - - if ($count < sizeof($compound_element)) { - $return .= '
' . "\n" . $separator . "\n"; - } else { - $return .= '
'; - } - } + } + $elements[] = '
' . $metadata_value . "
\n" ; } - - $return .= '' . "\n\n"; } - + $return .= '
' . implode($separator, $elements) . '
'; } else { $return .= '
'; - foreach ( $value as $meta ) { - if ( $meta->get_value_as_html() != '' ) { - $return .= '
'; - if ( $meta instanceof Item_Metadata_Entity ) { $return .= '\n"; $return .= '

' . $meta->get_value_as_html() . '

'; } - $return .= '
' . "\n\n"; } - } $return .= '
' . "\n\n"; }