# Add filter to model/post for force\_delete

**URL:** <https://community.hivepress.io/t/add-filter-to-model-post-for-force-delete/2110>\
**Category:** HivePress\
**Tags:** code\
**Created:** [September 29, 2022, 11:30pm UTC](https://community.hivepress.io/t/add-filter-to-model-post-for-force-delete/2110 "2022-09-29T23:30:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saidayvazov](https://community.hivepress.io/user_avatar/community.hivepress.io/saidayvazov/32/1029_2.png) [@saidayvazov](https://community.hivepress.io/u/saidayvazov)\
**Post date:** [September 29, 2022, 11:30pm UTC](https://community.hivepress.io/t/add-filter-to-model-post-for-force-delete/2110/1 "2022-09-29T23:30:06Z")

</div>

Игорь привет!)  
В общем ситуация такая, в модели post, есть финальный класс delete.  
У него статично стоит для force\_delete = true, это не очень удобно, если нужно контролировать какие записи удалять жестко, а какие мягко.  
Проблема с которой я столкнулся:  
Мне нужно сохранять некоторые файлы, которые условно люди дают нам на проверку как магазин(условно сертификаты и т.д.).  
Есть глобальная переменная у wp - MEDIA\_TRASH, которую если активировать, она добавляет возможность корзины для медиафайлов, но от того что в модели post стоит жесткая force\_delete и с ней никак не проманипулировать, тут получается проблема что он в любом случае удаляет файл.  
Можно ли добавить какой-нибудь фильтр на значение force\_delete?

* * *

Hi Igor!  
In general, such a situation, in post models, there is a final class to delete.  
It has a static value for force\_delete = true, this is not very convenient if you need to control which entries are hard to delete and which are soft.  
The problem I faced:  
I need to read some files that conditionally people give us for verification as a store (conditionally certificates, etc.).  
There is a global variable in wp - MEDIA\_TRASH, which, if activated, creates the possibility of a basket for media files, but the fact that the post model has a hard force\_delete and cannot be manipulated in any way, there is a problem that it processes the file anyway.  
Is it possible to add some filter by force\_delete value?

---

<div class="post-metadata">

**Author:** ![saidayvazov](https://community.hivepress.io/user_avatar/community.hivepress.io/saidayvazov/32/1029_2.png) [@saidayvazov](https://community.hivepress.io/u/saidayvazov)\
**Post date:** [September 29, 2022, 11:40pm UTC](https://community.hivepress.io/t/add-filter-to-model-post-for-force-delete/2110/2 "2022-09-29T23:40:40Z")

</div>

может быть так? / maybe so?

```auto
		$force = apply_filters( 'hivepress/v1/models/' . static::_get_meta( 'name' ) . '/force_delete', true, $id );
		return $id && wp_delete_post( absint( $id ), $force );

```

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [September 30, 2022, 4:52pm UTC](https://community.hivepress.io/t/add-filter-to-model-post-for-force-delete/2110/4 "2022-09-30T16:52:16Z")

</div>

Sorry, currently there’s no way to override this but we’ll try to resolve this issue in the next update (maybe by checking the post type, and adding extra options for attachments). You can also check the `trash()` method, it works for regular posts but I’m not sure if it works for attachments.

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [October 30, 2022, 4:52pm UTC](https://community.hivepress.io/t/add-filter-to-model-post-for-force-delete/2110/5 "2022-10-30T16:52:37Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
