BuddyDev

Search

[Resolved] XProfile Custom Fields allowed file types

  • Participant
    Level: Initiated
    Posts: 16
    John on #43543

    How can I change the file types that allowed to be uploaded via the File field using your plugin? Thank you.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #43547

    Hello John,

    Thank you for posting here. Please let me know which file type do you want to allow. Currently, supported files are:

    File field: ‘doc’,’docx’ and ‘pdf’
    Image field: ‘jpg’, ‘jpeg’, ‘gif’ and ‘png’ type files

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 16
    John on #43571

    I need the ability to upload audio files.
    m4a, flac, mp3, MP4, aiff, 3gp

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #43592

    Hello John,

    Sorry for the delayed reply. Please use the following code:

    
    add_filter( 'bpxcftr_allowed_extensions', function ( $extensions ) {
    
    	if ( isset( $extensions['file'] ) ) {
    		$new_extensions = array( 'm4a', 'flac', 'mp3', 'mp4', 'aiff', '3gp' );
    
    		$extensions['file'] = array_merge( $extensions['file'], $new_extensions );
    	}
    
    	return $extensions;
    } );
    
    

    It will allow users to upload files of the mentioned extension. But File will be shown as a download link. Also, It might not support all formats.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 16
    John on #43621

    Thanks, that worked. Are there filters I can use to change the output of the field based on the filetype or other conditions?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #43627

    Hello John,

    Thank you for the acknowledgment. Please refer to the link:

    https://github.com/buddydev/bp-xprofile-custom-field-types/blob/master/src/field-types/class-field-type-file.php#L138

    This function output the field display.

    You can use the ‘bpxcftr_file_display_data’ filter to modify the field output as per your need. Please check.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 16
    John on #43650

    Thanks for pointing out the filters. That’s super helpful. Great work on this plugin.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #43654

    Hello John,

    Thank you for the acknowledgment. I am glad that I could help you.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved