Better way of detecting empty numeric values #422.

This commit is contained in:
mateuswetah 2020-10-09 14:17:39 -03:00
parent 7ee1cfdc57
commit d12e2622d4
1 changed files with 2 additions and 5 deletions

View File

@ -70,9 +70,8 @@ class Item_Metadata extends Repository {
return $item_metadata; return $item_metadata;
} else { } else {
if ( $unique ) { if ( $unique ) {
$is_numeric = is_numeric($item_metadata->get_value());
if ( ( !$is_numeric && empty( $item_metadata->get_value()) ) || ($is_numeric && $item_metadata->get_value() == '') ) { if ( !is_numeric($item_metadata->get_value()) && empty( $item_metadata->get_value() ) ) {
if ( $item_metadata->get_metadatum()->get_parent() > 0 ) if ( $item_metadata->get_metadatum()->get_parent() > 0 )
delete_metadata_by_mid( 'post', $item_metadata->get_meta_id() ); delete_metadata_by_mid( 'post', $item_metadata->get_meta_id() );
else else
@ -103,9 +102,7 @@ class Item_Metadata extends Repository {
$values = $item_metadata->get_value(); $values = $item_metadata->get_value();
foreach ( $values as $value ) { foreach ( $values as $value ) {
$is_numeric = is_numeric($value); if ( !is_numeric($value) && empty($value) ) {
if ( (!$is_numeric && empty($value)) || ($is_numeric && $value == "") ) {
continue; continue;
} }
add_post_meta( $item_metadata->get_item()->get_id(), $item_metadata->get_metadatum()->get_id(), wp_slash( $value ) ); add_post_meta( $item_metadata->get_item()->get_id(), $item_metadata->get_metadatum()->get_id(), wp_slash( $value ) );