Working with wordpress 4.2.2, when I use this code in the function.php child theme to change the attachment download directory according to each message type:
function wpse_16722_type_upload_dir( $args ) {
$id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : '' );
if( $id ) {
$newdir = '/' . get_post_type( $id );
$args['path'] = str_replace( $args['subdir'], '', $args['path'] );
$args['url'] = str_replace( $args['subdir'], '', $args['url'] );
$args['subdir'] = $newdir;
$args['path'] .= $newdir;
$args['url'] .= $newdir;
return $args;
}
}
add_filter( 'upload_dir', 'wpse_16722_type_upload_dir' );
I get a blank page! there are no empty lines in the .php function, and the problem only occurs after adding this code. I really need to organize my download folder, but without a blank page. is there any solution?
source
share