Registered Vendor without a listing still able to send messages

I have been having help from a web developer as currently if a vendor just registers and does not add a listing, they are able to send messages to other vendors, without other vendors to be able to see the profile of this vendor.

So he applied this php code and with this if a vendor who has registered and contacts other vendor or replies to a listing he is restricted from sending message and gets a message that he needs a listing to send a message. This is how it should work. With the code below it works but next day it reverts back to default, and vendor with no listing are then able to send messages.

Any thoughts why this is reverting. We have gone a long way in getting the site up and running but now it seems to have come a big problem like this. You help will be very much appreciated at this sticky point please. Will be verso grateful. The code is


add_filter(
	'hivepress/v1/forms/message_send/errors',
	function($errors, $form){
		$values = $form->get_values();
		
		if(!$values){
			return $errors;
		}
		
		$user_id = hivepress()->helper->get_array_value($values, 'recipient');
		
		if(!$user_id){
			return $errors;
		}
		
		$vendor_id = \HivePress\Models\Vendor::query()->filter(['user' => $user_id])->get_first_id();
		
		if(!$vendor_id){
			return $errors;
		}
		
		$listing_count = \HivePress\Models\Listing::query()->filter(['vendor' => $vendor_id])->get_count();
		
		if($listing_count > 0){
			return $errors;
		}
		
		$errors[] = 'Unable to send message to vendor with no listings.';
		return $errors;
	},
	1000,
	2
);

Hi,

I also recommend filtering listings by status=>publish here:

$listing_count = \HivePress\Models\Listing::query()->filter(['vendor' => $vendor_id])->get_count();

Because currently it probably also counts hidden draft listings, so the code probably doesn’t work if the user just clicks Add Listing button and returns to any other page without proceeding, because the listing draft is created during the listing attempt.

Hope this helps

Thank you so much
Any chance if you can help me with one final thing?

How can I limit the size of upload photo when vendor loads their or listings image. I have restricted the number if images to only one.
My web developer is still struggling with this having implemented some changes

Thank you;)

Hi,

For listing images, please use this PHP snippet: Change the maximum number of images per listing #hivepress #listings · GitHub

Regarding the size limit, please check this tutorial: How to Increase the Maximum File Upload Size in WordPress

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.