How to Restrict Messaging to Connected Users


Home Forums Front End PM PRO How to Restrict Messaging to Connected Users

This topic is: Not Resolved
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #46004
    cam.wall
    Participant

    I am trying to restrict messaging so you can only message someone if you are connected to them. I use Member Press to manage users and a WordPress post type called Connection to store connection info. Am having trouble using php to block messages when users are not connected. Please help with code suggestions. Thanks!

    #46006
    Shamim Hasan
    Keymaster

    You can add 2 approaches
    Suppose current user id is 2 (you can get that using get_current_user_id()) and connected users of this user in 2,3 and 4 (get that from your member plugin or using query)

    Approach 1. You show only connected users in auto suggestion and in directory.

    add_filter( 'fep_filter_rest_users_args', function( $args, $for, $q, $x ) {
    	$args['meta_query'] = [
                'include' => [2,3,4], //Get ids from member plugin
            ];
    	return $args;
    }, 10, 4 );
    

    Approach 2. restrict user from sending message to only connected users

    add_filter( 'fep_current_user_can', function( $can, $cap, $id ){
        if ( 'send_new_message_to' != $cap || ! $can ) {
    	return $can;
        }
        //Get ids from member plugin
        if( in_array($id, [2,3,4] ) ){
            return true;
        }
        return false;
    }, 10, 3);
    
Viewing 2 posts - 1 through 2 (of 2 total)

You need to purchase ‘Front End PM PRO’ to create topic in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.