BuddyDev

Search

Disable multi upload

Tagged: , ,

  • Participant
    Level: Initiated
    Posts: 2
    Neiji sly on #2056

    Hi, i want to disable multi upload media and replace this with a simple field upload media with submit button. Tank’s

  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #2057

    Hi Neiji,
    Welcome to BuddyDev forums.
    Thank you for using MediaPress.

    To disable the multiple file selection, you can put the following line in your bp-custom.php

    
    
    add_filter( 'mpp_upload_default_settings', 'mpp_allow_single_file_selection_only');
    
    function mpp_allow_single_file_selection_only( $settings ) {
    	
    	$settings['multi_selection'] = false;
    	
    	return $settings;
    }
    
    

    That will limit the selection of one at a time but will not stop users from selecting multiple files. Now, since we don’t want users to upload more than one file at a time, we will take a little help from javascript.

    Please put this js in your theme’s js file

    
    jQuery( document ).ready( function () {
    	
    		
    	if( _mppData == undefined ) {
    		return ;
    	}
    	
    	mpp.guploader.isRestricted = check_file_limit;
    	mpp.activity_uploader.isRestricted = check_file_limit;
    
    		
    	function check_file_limit( uploader, file ) {
    		//clear any error we had earlier
    		jQuery('#message').remove();
    	
    		var size = uploader.files.length;
    		//allow selecting/uploading
    		if(  size <=1 ) {
    			return false;//no restriction
    		}
    		//remove file from queue
    		uploader.removeFile( file );
    		uploader.refresh();
    		//remove the feedback that we added
    		this.removeFileFeedback( file );
    		//notify error message
    		mpp.notify( "Only one file can be uploaded at a time", 1 );
    
    		return true; //yes, this should be restricted
    			
    	}
    
    });
    
    

    That’s all you will need to do. Please try it and let me know if that works for you or not?

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 2
    Neiji sly on #2062

    Tank you for reply, i take the fist code in bp-custom and the second in my child theme for bp-default save all but nothing work. I want to replace the multi upload form by a simple upload with submit button. Tank’s

You must be logged in to reply to this topic.

This topic is: not resolved