BuddyDev

Search

limit gallery link on members profiles

  • Participant
    Level: Initiated
    Posts: 14
    Patti Muldoon on #10121

    Hi, I have a buddypress site running s2member pro plugin and the mediapress plugin. Currently all members (one free and one paid) have the ability to add a gallery to the site, but I want to limit it to only the paid members. I have restricted access to the page where the gallery shows to those members, but am unsure how to stop the free members from creating a gallery, as it shows on every profile, regardless of membership level. Does anyone have any ideas?

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #10126

    Hi Patti,
    Simple solution will be to filter on ‘mpp_is_enabled’ to completely remove it from user profile.

    I will post an example below with capability, please feel free to update for s2members pro.

    
    
    /**
     * Example: Disable MediaPress gallery for subscriber, contributor, author
     *
     * @param bool   $is_active is MediaPress active.
     * @param string $component component name(members, groups,sitewide etc).
     * @param int    $component_id context items id(user id, group id etc).
     *
     * @return bool
     */
    function mpp_custom_disable_for_users( $is_active, $component, $component_id ) {
    	// only for members component.
    	if ( 'members' !== $component ) {
    		return $is_active;
    	}
    	// only editor or above should have gallery.
    	if ( ! user_can( $component_id, 'publish_pages' ) ) {
    		return false;
    	}
    	return $is_active;
    }
    add_filter( 'mpp_is_enabled', 'mpp_custom_disable_for_users', 10, 3 );
    
    

    regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 14
    Patti Muldoon on #10134

    Thank you Brajesh. How do I incorporate this into the site? I’m not a programmer, so am not sure if this is css, php or js?

  • Participant
    Level: Initiated
    Posts: 14
    Patti Muldoon on #10142

    Hi, I really need an answer to this question if possible. I am hoping to launch the website this week, and this is holding up the launch. Anyone that can help, much appreciated.

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #10152

    Hi Patti,
    It is php code.

    If you don’t understand the code, I will suggest hiring someone or avoiding this use case. This is a very small thing(you need to specify the membership levels and conditions and the developer can update the above code for you and put it on the site).

    I am sorry that we don’t have a ready made solution for this case, we will try to have something as addon in future.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 14
    Patti Muldoon on #10154

    Thank you Brajesh. I appreciate your patience with me.

    I added this php code to my child functions.php but it still doesn’t limit the gallery to the membership level. I will try to figure out where I went wrong and fix this issue. I didn’t add the filter code at the bottom, so is that necessary?

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #10155

    Hi Patti,
    Can you please list the membership level names and which of them should be allowed to have gallery?

    I will try to post a complete solution.

    The above code limits based on capability(In this example, subscriber, author and contributors won’t have gallery).

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 14
    Patti Muldoon on #10156

    Yes, thanks. Membership label is soulmate and the level is s2member_level1

  • Participant
    Level: Initiated
    Posts: 14
    Patti Muldoon on #10158

    For the ones that I don’t want to have access to the gallery on their profile, the membership label is friend and the level is s2member_level0

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #10159

    Hi Patti,

    Please remove the old code and add this code at the bottom of the file.

    
    
    /**
     * Example: Disable MediaPress gallery for S2 members level 0
     *
     * @param bool   $is_active is MediaPress active.
     * @param string $component component name(members, groups,sitewide etc).
     * @param int    $component_id context items id(user id, group id etc).
     *
     * @return bool
     */
    function mpp_custom_disable_for_users( $is_active, $component, $component_id ) {
    	// only for members component.
    	if ( 'members' !== $component ) {
    		return $is_active;
    	}
    	// do not allow zero level to have the gallery.
    	if ( function_exists('current_user_is' ) && current_user_is( $component_id, 's2member_level0' ) ) {
    		return false;
    	}
    	return $is_active;
    }
    add_filter( 'mpp_is_enabled', 'mpp_custom_disable_for_users', 10, 3 );
    
    

    Does it solve the problem?

    Thank you
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved