Hide description for normal users otherwise required

Hi there !

Is it possible to hide first name, last name, description fields for “normal” users, but make them required if the user wants to submit a listing (when he needs to complete his/her profile).

Here’s my code (based on this one)

add_filter(
	'hivepress/v1/forms/user_update',
	function( $form ) {
		if(current_user_can('edit_posts')){
			$form['fields']['first_name']['required'] = true;
			$form['fields']['last_name']['required'] = true;	
			$form['fields']['image']['statuses']['optional'] = null;			
		}else{//remove for normal users (client)
		
			unset($form['fields']['first_name']);
			unset($form['fields']['last_name']);
			unset($$form['fields']['image']);			
			unset($form['fields']['description']);			
		}

		return $form;
	},
	1000
);

What it does at the moment : hide (remove) the fields in any case (normal profile / complete your profile).

Any idea ?

Consider it solved.

I just hide it on the “normal user” screen via CSS :

/* CSS */
form.hp-form--user-update .hp-form__field--textarea{
display:none;
}

And I add some jQuery code on the second form (profile).

//jQuery to the rescue !
$('.hp-form--user-update-profile button').on('click', function(event){
	if($('textarea[name="description"]').val().length < 85){
		alert("Veuillez compléter le champ 'infos'\r\n Actuellement "+ $('textarea[name="description"]').val().length + " caractères.\r\n On essaye d'arriver à 85..."); 	
		event.preventDefault(); 
		return false; 			
	}			
}); 

1 Like