BuddyDev

Search

[Resolved] How do that users can upload only 2 photos and create only one galerry?

  • Participant
    Level: Enlightened
    Posts: 62
    MargaritaS on #10856

    Hi,

    How can I do that users can upload only 2 photos and create only one gallery?

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #10888

    Hi Margrita,
    Please put this in your bp-custom.php

    
    
    /**
     * Filter on the gallery creation permission.
     *
     * @param bool   $can can create.
     * @param string $component component name.
     * @param string $component_id component id.
     *
     * @return bool
     */
    function mpp_custom_limit_gallery_creation( $can, $component, $component_id ) {
    	// non logged in user's don't have permissions and admin's don't have restrictions.
    	if ( ! is_user_logged_in() || is_super_admin() ) {
    		return $can;
    	}
    
    	$user_id = get_current_user_id();
    
    	// How many galleries?
    	$allowed_gallery_count = 1; // 0 = no restriction.
    
    	if ( ! $allowed_gallery_count ) {
    		// No restrictions when someone sets it to zero zero.
    		return $can;
    	}
    	// only limit if crossed the limit.
    	if ( mpp_get_user_gallery_count( $user_id ) >= $allowed_gallery_count ) {
    		$can = false;
    	}
    
    	return $can;
    }
    add_filter( 'mpp_user_can_create_gallery', 'mpp_custom_limit_gallery_creation', 10, 3 );
    
    /**
     * Filter on the media upload permission.
     *
     * @param bool        $can can create.
     * @param string      $component component name.
     * @param string      $component_id component id.
     * @param MPP_Gallery $gallery gallery object.
     *
     * @return bool
     */
    function mpp_custom_limit_media_upload( $can, $component, $component_id, $gallery ) {
    
    	// non logged in user's don't have permissions and admin's don't have restrictions.
    	if ( ! is_user_logged_in() || is_super_admin() ) {
    		return $can;
    	}
    
    	$user_id = get_current_user_id();
    	// How Many media is allowed?
    	$allowed_media_count = 2; // 0 = no limit.
    
    	if ( ! $allowed_media_count ) {
    		// No restrictions when zero.
    		return $can;
    	}
    	// only limit if crossed the limit.
    	if ( mpp_get_user_media_count( $user_id ) >= $allowed_media_count ) {
    		$can = false;
    	}
    
    	return $can;
    }
    add_filter( 'mpp_user_can_upload', 'mpp_custom_limit_media_upload', 10, 4 );
    
    

    That will do it. It will only work for MediaPress 1.2.0 or above.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 62
    MargaritaS on #10895

    Thank you very much Brajesh,

    In what directory there is the file bp-custom.php?

  • Participant
    Level: Enlightened
    Posts: 62
    MargaritaS on #10903

    Please Brajesh, can you explain me about the file bp-custom.php?

    In what directory there is this file? Or I need to cerate itwhit dreamwevaer, a phpfile with only the code that you give me? Then where I must to put this file by ftp?

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #10923

    Hi Margrita,
    I am sorry I did not explain it earlier.

    bp-custom.php should be in your wp-content/plugins directory.

    For more details, Please see
    https://buddydev.com/docs/guides/guides/buddypress-guides/what-is-bp-custom-php/

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 62
    MargaritaS on #10939

    Thank you very much Brajesh.

    I have created the file bp-custom.php with dreamweaver, I wrote in this file only the code that you gave me. I put it in wp-conten/plugins by FTP and in the forntend appear this message error in the top of the web site, well, is the code of the file that appear:

    “/** * Filter on the gallery creation permission. * * @param bool $can can create. * @param string $component component name. * @param string $component_id component id. * * @return bool */ function mpp_custom_limit_gallery_creation( $can, $component, $component_id ) { // non logged in user’s don’t have permissions and admin’s don’t have restrictions. if ( ! is_user_logged_in() || is_super_admin() ) { return $can; } $user_id = get_current_user_id(); // How many galleries? $allowed_gallery_count = 1; // 0 = no restriction. if ( ! $allowed_gallery_count ) { // No restrictions when someone sets it to zero zero. return $can; } // only limit if crossed the limit. if ( mpp_get_user_gallery_count( $user_id ) >= $allowed_gallery_count ) { $can = false; } return $can; } add_filter( ‘mpp_user_can_create_gallery’, ‘mpp_custom_limit_gallery_creation’, 10, 3 ); /** * Filter on the media upload permission. * * @param bool $can can create. * @param string $component component name. * @param string $component_id component id. * @param MPP_Gallery $gallery gallery object. * * @return bool */ function mpp_custom_limit_media_upload( $can, $component, $component_id, $gallery ) { // non logged in user’s don’t have permissions and admin’s don’t have restrictions. if ( ! is_user_logged_in() || is_super_admin() ) { return $can; } $user_id = get_current_user_id(); // How Many media is allowed? $allowed_media_count = 2; // 0 = no limit. if ( ! $allowed_media_count ) { // No restrictions when zero. return $can; } // only limit if crossed the limit. if ( mpp_get_user_media_count( $user_id ) >= $allowed_media_count ) { $can = false; } return $can; } add_filter( ‘mpp_user_can_upload’, ‘mpp_custom_limit_media_upload’, 10, 4 );”

    What have I to do?

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #10947

    Sorry about that. You did not use the php starting tag.

    I should have assisted you earlier with it.

    Please copy the code from this page
    https://gist.github.com/sbrajesh/928d36128afe48cd6cdf29a47a232abb

    and paste into that file. It contains the opening tag and should work.

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 62
    MargaritaS on #10957

    Thank you, thank you very very much Barjesh. Now it works perfect.

    You are a very good person and a great professional, I admire you a lot.

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #10966

    Hi Margrita,
    Thank you for the kind words. I am glad I was able to help 🙂

    Regards
    Brajesh

The topic ‘ [Resolved] How do that users can upload only 2 photos and create only one galerry?’ is closed to new replies.

This topic is: resolved