Home Support Extensions Messages Allow only Contributor to Message

Allow only Contributor to Message

  • Author
    Posts
  • unitehearts

    Hi
    I would like to restrict messaging to only those who have posted their own Listing – can you give some code snippet for this.
    Thank you very much

    ihor developer

    You can try adding this one:

    add_filter(
    	'hivepress/v1/models/message/errors',
    	function( $errors, $message ) {
    		if ( ! $message->get_id() && empty( $errors ) && ! current_user_can( 'edit_posts' ) ) {
    			$errors[] = 'error text here';
    		}
    
    		return $errors;
    	},
    	10,
    	2
    );

    But it doesn’t hide the message buttons, only checks the submitted messages.

    unitehearts

    this is nice. is it possible that this error can be made to popup before one types and submits the Message

    ihor developer

    Sorry, but customizations are not part of the HivePress support, although I’m always glad to help if there’s a simple fix. If you’re familiar with PHP please try customizing the message button.

    unitehearts

    this snippet does not seem to work now. it asks for login – and the login modal pops up.
    please help

    ihor developer

    It worked this way since the initial version – if the current user is not logged in there will be a login modal on click (it also works this way for Favorites and other actions that require login). Once the user is logged in the snippet suggested above should work fine.

    unitehearts

    Thanks Ihor this code is working.
    Can you guide on a small tweak. Suppose someone posts an Ad and then later deletes it or hides it, they are still a Contributor and can send messages.

    How to alter the code to ensure that unless a person has a live ad, they cannot send a message.

    ihor developer

    Sorry, this requires further customizations (to update the user role if the last of the user’s listings is deleted or hidden).

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.