Add filter to model/post for force_delete

Игорь привет!)
В общем ситуация такая, в модели 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?

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

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

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.

1 Like

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