Allow HTML in text fields

What we need in order to meet our project requirements is the ability for a property owner to post an HTML snippet and have that placed onto the listing “as is” without any changes.

I tried using the “TextArea” listing attribute, which escapes HTML characters.

I also tried this code snippet in an attempt to convert the encoded text back to plain HTML during the display format step. However, this didn’t work either, either because my code isn’t doing the right thing, or because the text is being further modified before being output to the screen.

add_filter( 
	'hivepress/v1/models/listing/attributes', 
	function ($attributes){
		if(isset($attributes)){
			$replacement = html_entity_decode('%value%');
			$attributes['myfield']['display_format'] = $replacement;
		}

		return $attributes;
	}, 
	1000
);

So the question: Is there a way we can have HTML place onto the listing page in exactly the way it is entered?

Thank you!
Andrew

So after further testing, I have discovered that the ‘hivepress/v1/models/listing/attributes’ filter only sets the format, but the value itself isn’t actually modified.

This now makes the question:

Where can I get access to the value AFTER it has been produced based on the format?

OR

How can we modify TextArea attributes to allow HTML code?

Hi,

Please note that the HTML parameter takes not only true/false but also an array of available HTML tags. The format is the same as this function in allowed_html wp_kses() – Function | Developer.WordPress.org.
It is not possible to allow full editing because it is not secured, but you can list HTML tags.

​I hope this is helpful to you.

Hi Andrii,

Thanks for the reply. I have spent some time trying to get this to work, but I may be misunderstanding your direction or am just not putting my code in the right place.

Here is a simplified example, one where I just want to allow the span tag. However, if I enter something like test, the only thing that is saved in the Text field is “test”.

Do I need to use a different filter or hook that allows specific HTML at the point in time where it is saved, rather than trying to format the output?

add_filter( 
	'hivepress/v1/models/listing/attributes', 
	function ($attributes){
		if(isset($attributes)){
			
			$attributes['myfield']['html'] = [
				'span' => []
			];	

		}

		return $attributes;
	}, 
	1000
);

Hi,

If you use this hook, you need to set the parameters as follows: $attribute[‘fieldnamehere’][‘edit_field’][‘html’]=….
Also, you can check these samples:

https://gist.github.com/search?q=user%3Ahivepress+hivepress%2Fv1%2Fmodels%2Flisting%2Fattributes&ref=searchresults

And this doc:

https://hivepress.github.io/hook-reference/hivepress_v1_models_%257Bmodel_name%257D_attributes.html

I believe this will be useful to you.

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