Deleting a pod record with an image - image remains in the WP media library

0

Hello,

I've noticed that when I delete a Pod record containing an image that image stays in the WP media library (inc. all the sizing versions of that image). It is possible to ensure the deletion of an image and all its sizes when deleting a Pod record referring to it?

asked Oct 5 '10 at 2:07

dashaluna

54

add comment
enter at least 15 characters

5 Answers

0

Got this working. Released as a Package here http://podscms.org/packages/clear-up-wp-media-library-files/

answered Oct 6 '10 at 12:12

dashaluna

54

edited Oct 6 '10 at 1:01

add comment
enter at least 15 characters
1

Pre-drop helper & wp delete attachment function should make it. I don't know exactly how the data is stored in $columns (it may be array or string), but in any way you should get array with related media IDs, loop through it and use wp_ delete_ attachment with each of them.

answered Oct 5 '10 at 5:07

Fike

208

add comment
enter at least 15 characters
1

You don't have access to $columns, you can use $params->tbl_row_id to pull in data via a new Pod() though to fit your needs.

answered Oct 5 '10 at 8:12

sc0ttkclark

2936

add comment
enter at least 15 characters
0

Hm, just looked at the codex and there isn't much info on the pre-drop helpers. Do they have the same variables as pre-save helpers? Do I access field's value using $columns['column_name']['value'] ?

Any help?

answered Oct 5 '10 at 6:36

dashaluna

54

add comment
enter at least 15 characters
0

I've been looking at it more. Still confused...

As I understand $params relates to 'wp_pod' table. When I get $params->datatype I would need to look into the 'wp_pod_types' table to retrieve the 'name' field of a Pod, so I'll have '<pods_name>'. Then I need to look into 'wp_pod_tbl_<pods_name>' and get the row/item with 'id = $params->tbl_row_id'. Then to get access to attachment I need to 'get_field('<attachment_col_name>.ID')' on the retrieved row/item.

The problem is that I don't know how to start it off and access 'wp_pod_types' and other 'wp_pod_<table_name>' required tables.

Do I need a custom SQL specifing all tables and relations myself? :S

answered Oct 6 '10 at 10:11

dashaluna

54

edited Oct 6 '10 at 10:15

add comment
enter at least 15 characters