Run after "wp_generate_attachment_metadata"
-
Hey all,
First time here writing, but I’ve read several threads for great help in developing sites using WordPress ?? So, I hope I can get some help as well.
The problem I have is that I’m more or less trashing the built-in image upload function of WP. It doesn’t give me the image sizes I want and such stuff, so I’ve made a function that renames the image file after I’ve uploaded it from the “large” size name (in my case “img_01_-530×351.jpg”, to “img_01_.jpg”).
That however makes a file “missing” according to the database entry which thinks there still should be a img_01_-530×351.jpg file, which now is renamed to img_01_.jpg.
I hope you understand.. ??
Anyhow, to fix that I’d like to go through the “_wp_attachment_metadata” post for the image in the database. This works perfectly when I load an image with an older post_id or meta_id. But if, as I’ve tried for a few hours now, try to run it directly after I rename the file (above) through the following call;
add_filter( 'wp_generate_attachment_metadata', 'rceRenameImage' );
It results in not finding the post “_wp_attachment_metadata” for the just uploaded image. I’ve figured this out after sitting and banging my head against my desk for the last two hours, that the actual “_wp_attachment_metadata” post in the database for the image is created AFTER “wp_generate_attachment_metadata” returns to normal function in the WP core.
So everything that happens when I call the above add_filter happens AFTER the post “_wp_attached_file” is created for the image, but BEFORE “_wp_attachment_metadata”.
This results in that the function is unable to find this post and therefore I can’t update it.
Long post, I hope you all understand what I’m trying to do here.
To sum it up, I’d like to change the “_wp_attachment_metadata” post in the database after I’ve uploaded an image.
And it doesn’t work, that’s why I’m here ??
So, I’m wondering.. is there something that is called after the function call “wp_generate_attachment_metadata” in WP that I can hook into?
The reason I’m changing most of the upload function is that I like the GUI part of the whole upload process, but the background functions doesn’t really give me what I want ??
The ideal would be that I could specify the exact 2 sizes and names for every image that is uploaded and remove the whole “choose size” idea in the upload manager. But without changing the core files that I’d like to skip, it doesn’t seem to be doable. ??
Well well, I hope you can help me out ?? Thanks in advance!
- The topic ‘Run after "wp_generate_attachment_metadata"’ is closed to new replies.