diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index b00512513..e9be93f5a 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -210,6 +210,13 @@ class Item extends Entity { $arrayItemMetadata = $this->get_fields(); if( $arrayItemMetadata ){ foreach ( $arrayItemMetadata as $itemMetadata ) { + + // avoid core fields to re-validate + $pos = strpos($itemMetadata->get_field()->get_field_type(), 'Core'); + if( $pos !== false ){ + continue; + } + if( !$itemMetadata->validate() ){ $errors = $itemMetadata->get_errors(); $this->add_error( $itemMetadata->get_field()->get_name(), $errors ); @@ -221,4 +228,15 @@ class Item extends Entity { } return false; } + + /** + * {@inheritDoc} + * @see \Tainacan\Entities\Entity::validate() + */ + public function validate_core_fields(){ + if ( !in_array($this->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) ) + return true; + + return parent::validate(); + } } \ No newline at end of file diff --git a/src/classes/repositories/class-tainacan-fields.php b/src/classes/repositories/class-tainacan-fields.php index 72f35774b..a08dc44ed 100644 --- a/src/classes/repositories/class-tainacan-fields.php +++ b/src/classes/repositories/class-tainacan-fields.php @@ -289,8 +289,6 @@ class Fields extends Repository { * @throws \Exception */ public function fetch_by_collection(Entities\Collection $collection, $args = [], $output = null){ - $this->register_core_fields( $collection ); - $collection_id = $collection->get_id(); //get parent collections diff --git a/src/classes/repositories/class-tainacan-item-metadata.php b/src/classes/repositories/class-tainacan-item-metadata.php index 072d14e36..19455a9d2 100644 --- a/src/classes/repositories/class-tainacan-item-metadata.php +++ b/src/classes/repositories/class-tainacan-item-metadata.php @@ -64,7 +64,7 @@ class Item_Metadata extends Repository { $set_method = 'set_' . $field_type->related_mapped_prop; $value = $item_metadata->get_value(); $item->$set_method( is_array( $value ) ? $value[0] : $value ); - if ($item->validate()) { + if ($item->validate_core_fields()) { global $Tainacan_Items; $Tainacan_Items->insert($item); } else { diff --git a/src/dev-interface/class-tainacan-dev-interface.php b/src/dev-interface/class-tainacan-dev-interface.php index ead6ce542..98aac33b7 100644 --- a/src/dev-interface/class-tainacan-dev-interface.php +++ b/src/dev-interface/class-tainacan-dev-interface.php @@ -475,6 +475,12 @@ class DevInterface { foreach ($metalist as $meta) { $item_meta = new \Tainacan\Entities\Item_Metadata_Entity($entity, $meta); + + $pos = strpos($item_meta->get_field()->get_field_type(), 'Core'); + if( $pos !== false ){ + continue; + } + if (isset($_POST['tnc_metadata_' . $meta->get_id()])) { $item_meta->set_value($_POST['tnc_metadata_' . $meta->get_id()]); if ($item_meta->validate()) {