BuddyDev

Search

How to set media amount limits

  • Participant
    Level: Initiated
    Posts: 3
    Derek on #49305

    Hi there,

    I’ve taking a look through the docs, support and elsewhere for ideas, but I can’t seem to work out this one. I’m creating an interactive directory with buddypress and want to allow users to upload items to showcase their work, however I don’t want to limit so much by file size, rather, by the number of uploads (eg. each user can have a max of 5 images).

    Is it possible to limit the amount of uploads a user can have in their profile? Then if they want new ones, they would just delete some of the current ones and can replace with new ones if they wish.

    And would it be possible to get a suggestion of where/how to code for this?

    Many thanks, and I appreciate your plugins!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #49306

    Hello Derek,

    Welcome to the BuddyDev Forums. Yes, it can be possible with some lines of code

    
    add_filter( 'mpp_user_can_upload', function ( $can_do, $component, $component_id, $gallery ) {
    
    	// If not logged in return.
    	if ( ! is_user_logged_in() ) {
    		return $can_do;
    	}
    
    	$limit_count      = 4;
    	$user_media_count = mpp_get_user_media_count( bp_loggedin_user_id() );
    
    	if ( $user_media_count && $user_media_count >= $limit_count ) {
    		$can_do = false;
    	}
    
    	return $can_do;
    }, 10, 4 );
    
    

    You can further alter this code by based on component, status or media type. Look mpp_get_object_count supported args.

    You can place this code in your ‘bp-custom.php’ file. Please give it a try.

    To know what is ‘bp-custom.php’ file look here
    https://buddydev.com/docs/buddypress-guides/what-is-bp-custom-php/

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 3
    Derek on #49307

    This is incredible, thanks for the help! I’ll give it a go and look into the args as well.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #49309

    Hello Derek,

    You’re welcome! Don’t hesitate to reach out if you have any further questions or need additional assistance. Good luck with your project!

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved