Profile Image Optional for Users and Required for Vendors

Hi Team,

We would like to make the Profile Image mandatory for anyone who wants to become a vendor, and optional for all users.

We used the code you suggested in one of the threads:

 add_filter(
	'hivepress/v1/forms/user_update/errors',
	function( $errors, $form ) {
		$user = $form->get_model();

		if ( $user && ! $user->get_image__id() ) {
			$errors[] = 'Please upload the profile image.';
		}

		return $errors;
	},
	100,
	2
);

add_filter(
	'hivepress/v1/forms/user_update',
	function( $form ) {
		$form['fields']['image']['statuses']['optional'] = null;

		return $form;
	},
	1000
);

Unfortunately, this makes Profile Image mandatory for both Vendors and Users.

If I unset the Profile Image as suggested here: Hide profile image in vendor register form

When the User heads to the Settings page, and tries to update their profile, it says Profile Image is needed even though the Profile Image field is hidden.

Please do help us solving this problem.

Thanks,
Team Purohit Connect

1 Like

Please try this PHP code snippet. It makes the profile image required for vendors and optional for users

add_filter(
	'hivepress/v1/forms/user_update/errors',
	function( $errors, $form ) {
		$is_vendor = user_can(get_current_user_id(), 'edit_posts');
		
		if(!$is_vendor){
			return $errors;
		}
		
		$user = $form->get_model();

		if ( $user && ! $user->get_image__id() ) {
			$errors[] = 'Please upload the profile image.';
		}

		return $errors;
	},
	100,
	2
);

add_filter(
	'hivepress/v1/forms/user_update',
	function( $form ) {
		$is_vendor = user_can(get_current_user_id(), 'edit_posts');
		
		if(!$is_vendor){
			return $form;
		}
		
		$form['fields']['image']['statuses']['optional'] = null;

		return $form;
	},
	1000
);

I tried using this snippet, but it didn’t work. When a user creates an account and decides to list a service, it doesn’t make it mandatory for them to upload a profile image. same with registering as a vendor. it doesn’t make it mandatory

Hi,

This is a snippet for user and vendor profiles.

There is also a snippet to require uploading at least one image for listings: Require uploading at least one image for listings #hivepress #listings · GitHub

Hope it helps.

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