• Resolved Soul

    (@soulkitchen)


    Hi
    I like your plugin.
    Wondering if it is possible to aktivate PM only for KEymaster that he she can sending to the Participant / Spectator an vice versa.

    The Participant / Spectator should be able to send PM to the Keymaster only.

    The idea is that the Participant / Spectator can ask private questions to the keymaster via messaging.

    Is this possible?

    thanks for the answer and sorry for my english.

    Cheers

    https://wordpress.org/plugins/bbp-messages/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Contributor Ismail

    (@elhardoum)

    Hello Soul,

    Thank you.

    So I took some time to understand it, you want to only allow messages between keymaster <=> participant|spectator

    Can you add this snippet of code to the bottom of your child theme’s functions file? :

    function wp_8273966_can_pm( $user_id ) {
    
    	if( ! is_user_logged_in() )
    		return false;
    
    	$current_user = wp_get_current_user();
    
    	// current user is keymaster, see if the contact is spectator|participant
    	if ( in_array('bbp_keymaster', $current_user->roles) ) {
    		return in_array('bbp_spectator', get_userdata($user_id)->roles) || in_array('bbp_participant', get_userdata($user_a)->roles);
    	}
    
    	// current user is not keymaster, see if current user is spectator|participant, and then check if contact is keymaster
    	elseif ( in_array('bbp_spectator', get_userdata($user_id)->roles) || in_array('bbp_participant', get_userdata($user_a)->roles) ) {
    		return in_array('bbp_keymaster', get_userdata($user_id)->roles);
    	}
    
    	// current user is not keymaster|spectator|participant. there's nothing to do here;
    	return false;
    
    }
    
    add_action('bbpm_before_conversation_content', function($recipient) {
    
    	// bbP Messages plugin is not there
    	if( ! function_exists('bbpm_messages_base') )
    		return;
    
    	// can not contact
    	if( ! wp_8273966_can_pm($recipient) ) {
    		wp_redirect( bbpm_messages_base( '?done=err-sending&restriction=1' ) );
    		exit;
    	}
    
    	return;
    
    });
    
    add_filter('bbpm_notice_error_sending', function($notice) {
    
    	// Append a new error message to let the user know they can not contact the selected recipient
    	if( isset( $_GET['restriction'] ) ) {
    		$notice = 'Sorry, you can not contact this user';
    	}
    
    	return $notice;
    
    });

    It should redirect users and show an error message when they can not contact others based on your messaging rule..

    Let me know if that’s what you wanted, or we could disable the message input area instead of redirecting?

    Your English is great.

    Regards,
    Samuel

    Thread Starter Soul

    (@soulkitchen)

    Hi Samuel

    That works perfect.
    participant|spectator<=> participant|spectator cannot messaging eachother. This is what i need.

    But,

    keymaster <=> participant|spectator cannot messaging either. πŸ™‚

    This should be enabled so the participant|spectator can contact the Keymaster.

    may the WP user role should also be in the function.

    By the way. Theme is twenty sixteen.

    Thanks
    Best regards

    I think the Disabling messaging to the participant|spectator <=> participant|spectator would be better choice.

    Thanks

    Plugin Contributor Ismail

    (@elhardoum)

    Hello Sould,

    My apologies, I forgot to update some part of the code..

    Please use this instead

    function wp_8273966_can_pm( $user_id ) {
    
    	if( ! is_user_logged_in() )
    		return false;
    
    	$current_user = wp_get_current_user();
    
    	// current user is keymaster, see if the contact is spectator|participant
    	if ( in_array('bbp_keymaster', $current_user->roles) ) {
    		return in_array('bbp_spectator', get_userdata($user_id)->roles) || in_array('bbp_participant', get_userdata($user_id)->roles);
    	}
    
    	// current user is not keymaster, see if current user is spectator|participant, and then check if contact is keymaster
    	elseif ( in_array('bbp_spectator', $current_user->roles) || in_array('bbp_participant', $current_user->roles) ) {
    		return in_array('bbp_keymaster', get_userdata($user_id)->roles);
    	}
    
    	// current user is not keymaster|spectator|participant. there's nothing to do here;
    	return false;
    
    }
    
    add_action('bbpm_before_conversation_content', function($recipient) {
    
    	// bbP Messages plugin is not there
    	if( ! function_exists('bbpm_messages_base') )
    		return;
    
    	// can not contact
    	if( ! wp_8273966_can_pm($recipient) ) {
    		wp_redirect( bbpm_messages_base( '?done=err-sending&restriction=1' ) );
    		exit;
    	}
    
    	return;
    
    });
    
    add_filter('bbpm_notice_error_sending', function($notice) {
    
    	// Append a new error message to let the user know they can not contact the selected recipient
    	if( isset( $_GET['restriction'] ) ) {
    		$notice = 'Sorry, you can not contact this user';
    	}
    
    	return $notice;
    
    });

    It should do it.

    Regards

    Thread Starter Soul

    (@soulkitchen)

    Perfect. πŸ™‚

    Do you know how to change the name of the link : send admin name a message to send my choosen nickname a message ?

    Because the showing name is the admin name. This would be a problem if someone tries to hack the site. because the admin user name is shown instead of the site nickname.

    for example:
    Admin name to login in admin area is : soul
    Screen name is : LouisArmstrong

    so the text should not : Send soul a message
    it should : Send LouisArmstrong a message

    any clue?

    Best regards.
    Soul

    Plugin Contributor Ismail

    (@elhardoum)

    Well, thought user_nicename would be a perfect user info to show, but, there you go:

    function wp_8273966_pm_link( $user_id ) {
    
    	if( ! get_userdata( $user_id ) || $user_id == wp_get_current_user()->ID || ! function_exists('bbpm_messages_base') )
    		return;
    
    	ob_start();
    	?>
    		<p><a href="<?php echo bbpm_messages_base( get_userdata( $user_id )->user_nicename . '/', wp_get_current_user()->ID ); ?>">Send <?php echo get_userdata( $user_id )->display_name; ?> a message</a></p>
    	<?php
    
    	return ob_get_clean();
    
    }
    
    add_filter('bbpm_bbp_template_after_user_profile', function() {
    
    	return wp_8273966_pm_link( bbp_get_displayed_user_id() );
    
    });
    
    add_action('bbpm_bbp_theme_after_reply_author_details', function() {
    
    	return wp_8273966_pm_link( bbp_get_reply_author_id() );
    
    });

    It will show the user display name (can be 2 portions or more, if you want to show the first portion only then let me know)..

    Did it work for you?

    Regards,
    Samuel

    Thread Starter Soul

    (@soulkitchen)

    Perfect.
    Perfect
    Perfect.

    Works like a charm. πŸ™‚

    thanks a lot.

    How do i contact you via mail. I have some other question’s belong php.

    Thread Starter Soul

    (@soulkitchen)

    By the way. You should update your pro version. πŸ™‚

    Plugin Contributor Ismail

    (@elhardoum)

    Hi Louis,

    Thank you, I am glad that fixed everything.

    Yes, the PRO version needs a minor upgrade to solve a 404 error, but I am taking few days to maintain some of the plugins I have here..

    You can send me an email at samelh.com/contact/ or open an account at http://support.samelh.com and you can use the private messaging tool from there.

    Thank you!

    Thread Starter Soul

    (@soulkitchen)

    Hi Samuel

    Sorry to disturb you. I was conntacting you via your website. Did you receive may message?

    Best Regards

    Plugin Contributor Ismail

    (@elhardoum)

    Hi Soul,

    No worries, thanks for alerting me. Yes I just reached to it and I am sending you a reply.

    Thank you.

    Hey Samuel,

    I use the code as described above to restrict users sending messages to other users.

    Now everything works fine, except one thing, now keymasters can’t send messages to other keymasters. So only messages between ‘normal’ users and keymasters an vice versa is possible.

    Do you have an idea how to change that?

    Thanks for your help!

    Greetings Pascal

    Plugin Contributor Ismail

    (@elhardoum)

    Hello Pascal,

    Please open a new support topic for this, and mention where you got the working code (by linking to this post). Bumping others’ threads is a bad idea.

    Try this code for the wp_8273966_can_pm function:

    function wp_8273966_can_pm( $user_id ) {
    
    	if( ! is_user_logged_in() )
    		return false;
    
    	$current_user = wp_get_current_user();
    
    	// current user is keymaster, see if the contact is spectator|participant
    	if ( in_array('bbp_keymaster', $current_user->roles) ) {
    		return in_array('bbp_spectator', get_userdata($user_id)->roles) || in_array('bbp_participant', get_userdata($user_id)->roles) || in_array('bbp_keymaster', get_userdata($user_id)->roles);
    	}
    
    	// current user is not keymaster, see if current user is spectator|participant, and then check if contact is keymaster
    	elseif ( in_array('bbp_spectator', $current_user->roles) || in_array('bbp_participant', $current_user->roles) ) {
    		return in_array('bbp_keymaster', get_userdata($user_id)->roles);
    	}
    
    	// current user is not keymaster|spectator|participant. there's nothing to do here;
    	return false;
    
    }

    Thank you!
    Samuel

    Hey Samuel,

    I know bumping into an old support thread is normally not a good idea, but I thought so you would directly know what I mean

    And it works, thank you!
    Looks like this

    || in_array(‘bbp_keymaster’, get_userdata($user_id)->roles);

    was the part I was looking for.

    Thank you Samuel πŸ™‚
    And PS, nice plugin :p

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘PM only between Keymaster and Participant/Spectator bbpress’ is closed to new replies.