I am using this function to alter/validate submitted post values.
This piece of code works as intended, so that’s not the issue but it’s added to acf/pre_save and I get the feeling it might be better of in acf/save post, so I’m looking for suggestions/opinions.
Some explanation about the code.
1. It first retrieves a title (which is an obligated field, so it’s always entered) then sanitises (to be used as a post name/slug) and then updates the title field.
2. It then compares the submitted profile photo to the stored photo. If a new photo is uploaded, a meta field is added to mark the photo ‘pending’.
3. It then links the uploaded image to the ad that is created (because the upload happens on a page with a front-end form and this way I’m sure it will be connected to the new post instead of the page the form is on).
4. It then updates post_title, post_status and post_name.
5. It then creates an array for any photos already uploaded before and compares the uploaded photos to the stored ones. It then links each photo to the correct post.
6. An admin mail is sent when a new profile pic is uploaded.
7. Cache is cleaned.
8. Trigger al transitions to make sure the post status is correctly changed.
-=-
My questions
1. is this piece of code better of in acf/save ?
2. would it be better to cut this piece of code up in smaller parts ?
3. would you handle it any differently ?