Hi @arypneta the easiest way would be to rename it after it is created via the following action
do_action( 'stockpack_after_attachment_uploaded', $attach_id, $image );
This runs right after download, let me know if this works for you,
Thank you,
Stockpack
Okay, thanks. I was using that action to update the description and other things already, but I wasn’t sure if that was the best way to update the file name.
After testing, I can pretty easy update the post_title and post_name (slug) fields for the attachment post using that action. But, that doesn’t actually update the underlying file name/link to the actual file. It keeps the value it was uploaded with. After further testing, it appears that I can do some more manipulation with get_attached_file, update_attached_file, wp_generate_attachment_metadata, and wp_update_attachment_metadata, but I still feel like it would be much simpler to set a custom file name at the time of upload (since that is then all handled).
But, I do seem to have gotten it working now, so if you can’t add that option, it’s not a big deal. Thanks for your help!
It was indeed a surprise that I haven’t added a filter directly for the filename, I will add that with the next release.
Thank you!
Stockpack
@arypneta I have added the filter, here's an example on how to use it:
add_filter('stockpack_attachment_filename', 'add_custom_filename', 10, 2);
function add_custom_filename( $filename, $image ) {
/**
* {
* "id": 195254766,
* "provider": "adobe_stock",
* "description": "Morning tea waiting in the kitchen",
* "url": "https:\/\/as2.ftcdn.net\/v2\/jpg\/01\/95\/25\/47\/500_F_195254766_DY0j0rMq4CvRgaTHPeQHWSSiVGF502Z4.jpg",
* "download": "https:\/\/as2.ftcdn.net\/v2\/jpg\/01\/95\/25\/47\/1000_F_195254766_DY0j0rMq4CvRgaTHPeQHWSSiVGF502Z4.jpg",
* "sizes": {
* "full": {
* "height": 667,
* "width": 1000,
* "orientation": "landscape",
* "url": "https:\/\/as2.ftcdn.net\/v2\/jpg\/01\/95\/25\/47\/1000_F_195254766_DY0j0rMq4CvRgaTHPeQHWSSiVGF502Z4.jpg"
* },
* "medium": {
* "height": 333,
* "width": 500,
* "orientation": "landscape",
* "url": "https:\/\/as2.ftcdn.net\/v2\/jpg\/01\/95\/25\/47\/500_F_195254766_DY0j0rMq4CvRgaTHPeQHWSSiVGF502Z4.jpg"
* },
* "thumbnail": {
* "height": 147,
* "width": 220,
* "orientation": "landscape",
* "url": "https:\/\/as2.ftcdn.net\/jpg\/01\/95\/25\/47\/220_F_195254766_DY0j0rMq4CvRgaTHPeQHWSSiVGF502Z4.jpg"
* }
* }
*/
return 'custom_filename_'.$image->id . $filename;
}
Great, thanks! I had to change
$image->id
to
$image->data->id
to get the test snippet to work, but after that it was fine.