Howto define custom UPLOAD PATH?

This topic contains 6 replies, has 3 voices, and was last updated by  Stiofan O’Connor 6 years, 9 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #396165

    Thommy Cesar
    Expired Member
    Post count: 2

    Hi,

    how can I change the upload path for geodirectory to wp-content/uploads/places?
    The normal way with filtering upload_dir, wp_handle_upload_prefilter & wp_handle_upload for custom post types didn’t work out for me.
    Does anybody have a I idea?

    #396171

    Guust
    Moderator
    Post count: 29970

    I’ll get a developer to have a look at your question after the weekend. Thanks.

    #396226

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Thommy,

    There is no specific filter for GD places, we use the wp_upload_dir() function to get the upload dir, normal WP filters should work fine if hooked right.

    Thanks,

    Stiofan

    #396701

    Thommy Cesar
    Expired Member
    Post count: 2

    Hi Stiofan,

    I’ve tried the following, but I can’t get it to work. It’s starting to frustrate me. Could you help me out with the right code, please?

    I want all geodirectory entries to be saved under uploads/places/[year]/[month]/.

    
    
    
    add_filter('upload_dir', array(&$this, 'aa_geodir_ext_custom_gd_place_upload_dir'));
    function aa_geodir_ext_custom_gd_place_upload_dir( $args ) {
           $id = $_REQUEST['post_id'];
           $parent = get_post( $id )->post_parent;
           // Check the post-type of the current post
           if( "gd_place" == get_post_type( $id ) || "gd_place" == get_post_type( $parent ) ) {
              $args['subdir'] = "/places" . '/' . date( 'Y/m' ) . $args['subdir'];
              $args['path'] = $args['basedir'] . $args['subdir'];
              $args['url']  = $args['baseurl'] . $args['subdir'];
              // $args['baseurl']  = $args['baseurl'] . "/places" . '/' . date( 'Y/m' );
           }
           return $args;
        }
    
    #396748

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Thommy,

    My first question would be why?

    Also you only wrap the filter function call in an array if you are using it inside a class

    
    
    array(&$this, 'aa_geodir_ext_custom_gd_place_upload_dir')
    'aa_geodir_ext_custom_gd_place_upload_dir'

    If you are using it inside a class when is the class called, if its too late then it might be after the filter has run.

    Stiofan

    #397067

    Thommy Cesar
    Expired Member
    Post count: 2

    Hi Stiofan,

    I use a plugin (associated to my theme) in which I make all extensions/adjustments. That’s why it’s in a class.

    Exactly with the code from above it works with other custom post types to change the upload path. How would you do it for geodirectory?

    #397221

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    We also run a check on the file location directory matches the sub_dir location, so you would also need to edit that value: example below:

    
    
    add_filter('upload_dir', 'awesome_wallpaper_dir');
    
    function awesome_wallpaper_dir( $param ){
        $mydir = '/awesome';
    
        $param['path'] = $param['path'] . $mydir;
        $param['subdir'] = $param['subdir'] . $mydir;
        return $param;
    }

    Thanks,

    Stiofan

Viewing 7 posts - 1 through 7 (of 7 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket