0

I am trying to change the upload dir of files when it is uploaded through the front end using pods.

How can i check if the upload is coming from a Advanced Content Type using pods?

template-view-page.php

$pod_name = pods_v( 0, 'url');
$pods = pods( $pod_name, $slug );
$fields = array( 'name', 'file' ); 
echo $pods->form( $fields ); 

functions.php

add_filter('upload_dir', 'change_upload_dir');
function change_upload_dir( $param ){

$pod_name = pods_v( 0, 'url');
if ($pod_name == "paperwork") {
    $mydir = '/paperwork';
}

else {
    $mydir = '/notpaperwork';
}

$param['path'] = $param['path'] . $mydir;
$param['url'] = $param['url'] . $mydir;

return $param;

}

0

The short answer here is you can't check whether the upload is coming from a Pods Advanced Content Type, especially since the media that gets uploaded has no post_id associated to it (it's not a post at that point).

The longer answer is that you can still customize this if your file upload field is using plupload itself, not the normal media library input. You will want to hook into the pods_upload_handle filter to add_filter for your special upload_dir callback. Just make sure you return null on the pods_upload_handle filter to let Pods continue handling the upload. The pods_upload_handle filter passes 5 arguments:

$custom_handler = null, $file_arg = 'Filedata', $post_id = $params->post_id, $params, $field

You would want to check if $params->pod (the pod id) is set and if so use it to check if it is your ACT pod. If it matches your ACT pod, then you can add your upload_dir filter.

Using this way, you can be sure you are adding it only for the ACT intended.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.