Title: Custom Image Field
Last modified: August 31, 2016

---

# Custom Image Field

 *  Resolved [noobiestrikesagain](https://wordpress.org/support/users/noobiestrikesagain/)
 * (@noobiestrikesagain)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/custom-image-field/)
 * Hey,
 * Great plugin! Thanks for this awesome plugin.
 * I want to know couple of things regarding image field.
 * First of all, I want to change the upload directory to “MY_UPLOAD_DIR/registration/
   year/month/day/USERNAME_OF_USER.jpg” or whatever format image is in. I want to
   save the name of image by the username and in this directory.
 * Secondly, I wish to edit code and implement `accept="image/*"` for image fields.
 * I’m looking forward for your reply.
 * Thanks in advance!
 * [https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/](https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/)

Viewing 12 replies - 1 through 12 (of 12 total)

 *  Plugin Author [donmik](https://wordpress.org/support/users/atallos/)
 * (@atallos)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/custom-image-field/#post-7275512)
 * Hi,
 * I believe right now you cannot change the upload dir without changing my plugin.
   Maybe using ‘upload_dir’ filter you can do it, but it will be easier if I provide
   a new filter specific for my plugin. I will do it on next release, hope to ship
   it this monday.
 * About your second question, you can do it using “bp_xprofile_field_edit_html_elements”:
 *     ```
       add_filter( 'bp_xprofile_field_edit_html_elements', 'accept_only_images', 10, 2 );
       function my_custom_html_elements($r, $field_class) {
           if ($field_class === 'Bxcft_Field_Type_Image') {
               $r['accept'] = 'image/*';
           }
           return $r;
       }
       ```
   
 *  Thread Starter [noobiestrikesagain](https://wordpress.org/support/users/noobiestrikesagain/)
 * (@noobiestrikesagain)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/custom-image-field/#post-7275533)
 * Hey,
 * Thanks for the reply.
 * I’ll try the solution to your second question and will wait for the new filter.
 * I’m keeping this topic open till the time. Will mark resolve after the update!
 * Thanks a lot!
 *  Thread Starter [noobiestrikesagain](https://wordpress.org/support/users/noobiestrikesagain/)
 * (@noobiestrikesagain)
 * [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275575)
 * Hey,
 * I tried the filter by inserting the code to theme’s functions.php
 * I’m getting an error. Please assist me with the problem.
 * Thanks in advance.
 *  Plugin Author [donmik](https://wordpress.org/support/users/atallos/)
 * (@atallos)
 * [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275622)
 * What error are you getting?
 *  Thread Starter [noobiestrikesagain](https://wordpress.org/support/users/noobiestrikesagain/)
 * (@noobiestrikesagain)
 * [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275626)
 * [Here’s the screenshot](http://imgur.com/5hgMB4Z)
 *  Plugin Author [donmik](https://wordpress.org/support/users/atallos/)
 * (@atallos)
 * [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275627)
 * Ok, I’m dumb…xD. I changed the name of the function and forget to change the 
   name inside the add_filter call… Sorry.
 *     ```
       add_filter( 'bp_xprofile_field_edit_html_elements', 'accept_only_images', 10, 2 );
       function accept_only_images($r, $field_class) {
           if ($field_class === 'Bxcft_Field_Type_Image') {
               $r['accept'] = 'image/*';
           }
           return $r;
       }
       ```
   
 *  Thread Starter [noobiestrikesagain](https://wordpress.org/support/users/noobiestrikesagain/)
 * (@noobiestrikesagain)
 * [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275632)
 * Lol. No problem XD
    and Thanks. It’s working now! (Y)
 * I’m waiting for the update so that I can mark this topic as resolved.
 * Thanks once again.
 *  Thread Starter [noobiestrikesagain](https://wordpress.org/support/users/noobiestrikesagain/)
 * (@noobiestrikesagain)
 * [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275652)
 * Hey,
 * Thank you for the update and the new filter.
 * Please assist me with the code. How can I use ‘bxcft_upload_dir’?
 *  Plugin Author [donmik](https://wordpress.org/support/users/atallos/)
 * (@atallos)
 * [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275661)
 * The default upload dir is: “wp-content/uploads/profiles/USERID/”
 *     ```
       add_filter( 'bxcft_upload_dir', 'my_upload_dir', 10, 2);
       function my_upload_dir($path, $user_id) {
           return str_replace('profiles/', 'custom_dir/', $path);
       }
       ```
   
 * This code will replace the “profiles” folder with a folder named “custom_dir”.
 *  Thread Starter [noobiestrikesagain](https://wordpress.org/support/users/noobiestrikesagain/)
 * (@noobiestrikesagain)
 * [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275663)
 * Hey.
 * Thanks. It’s working!
 * I tried couple of modification to the code so that I can have this: “MY_UPLOAD_DIR/
   registration/year/month/day/USERNAME/”
 *     ```
       add_filter( 'bxcft_upload_dir', 'my_upload_dir', 10, 2);
       function my_upload_dir($path, $year, $month, $day, $display_name) {
           return str_replace('profiles/', 'registration/', $path);
       }
       ```
   
 * And umm, it’s not working. Any solution?
 * Sorry for so many questions.. but I can’t get it.
 * Thanks
 *  Plugin Author [donmik](https://wordpress.org/support/users/atallos/)
 * (@atallos)
 * [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275664)
 * You cannot change the parameters of the filter. The following code should work.
 *     ```
       add_filter( 'bxcft_upload_dir', 'my_upload_dir', 10, 2);
       function my_upload_dir($path, $user_id) {
           return '/registration/' . date('Y/m/d') . '/' . bp_core_get_user_displayname($user_id);
       }
       ```
   
 * This will save your files inside:
    “wp-content/uploads/registration/2016/04/30/
   USERNAME/”
 *  Thread Starter [noobiestrikesagain](https://wordpress.org/support/users/noobiestrikesagain/)
 * (@noobiestrikesagain)
 * [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275665)
 * Hey!
 * Thank you soooo much..
    It’s working. Finally! 😀

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Custom Image Field’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/buddypress-xprofile-custom-fields-
   type.svg)
 * [Buddypress Xprofile Custom Fields Type](https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/)
 * [Active Topics](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/reviews/)

 * 12 replies
 * 2 participants
 * Last reply from: [noobiestrikesagain](https://wordpress.org/support/users/noobiestrikesagain/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/custom-image-field/#post-7275665)
 * Status: resolved