Closed HowdyMcGee closed 2 years ago
After looking into this a bit, one possible way that the plugin could include this is by adding the following to the wp.media.view.UploaderWindow
instantiated object params in the acf-dropzone.js
file:
params: {
_acfuploader: this.field.get("key"),
_post_id: this.closest( "form" ).getElementById( "_acf_post_id" )
},
Regardless of whether it's frontend or admin, Advanced Custom Fields adds the _acf_post_id
hidden input under their acf-form-data
section. Then, this could be checked and used in the upload_dir
filter hook to change the uploaded file paths. To verify that this seems to work, I've error logged the $_REQUEST
as seen below:
add_filter( 'upload_dir', function( $uploads ) {
error_log( print_r( $_REQUEST, true ) );
return $uploads;
} );
Hi Alex,
I made some slight changes in the update, so that the value of _acf_post_id
is now present in the $_REQUEST
array.
If _acf_post_id
is strictly numeric $_REQUEST['post_id']
will be there too.
Hello & thank you for putting together this plugin!
I'm trying to manage uploads by assigning them specific upload folders based on their post type. I'm doing so using the
upload_dir
filter hook and using the $_REQUEST array. To complicate this further, I'm using the ACF functionacf_form()
to do this on the frontend. Generally, WordPress will pass in apost_id
in the $_REQUEST as well as the action, filename, etc. I was wondering if:1) There was a JS action hook ( like acf has? ) so I could manually add in the Post ID to pass to the request. I see that you're already passing in
_acfuploader
as the field key as as param which is cool so I would need to extend that.2) A mechanism built into the plugin that would also pass the Post ID along with the
_acfuploader
param to DropJS.If I'm overlooking something on the WP side or in the ACF Drozone plugin that could help please let me know! Thanks again and I hope this finds you well!