public function array_to_p( $array, $class = '', $seperator = '', $show_seperator = false )
This method takes an indexed array and builds a paragraph, with each array item being seperated by line breaks. This can be ideal for formatting certain types of content, such as an street adress, and works well for outputting repeatable text inputs created on the backend with CMB2.
Only Pass Trusted Input
Please be aware that $array is first passed through the maybe_unserialize() function (to support passing serialized post meta to the method). The contents of each array index are passed through esc_html(), and then the format_tags() method (allowing for basic content formatting without supporting raw HTML)
(mixed) (required) An indexed array or serialized indexed array to convert into an unordered list.
(string) (optional) A CSS class for the paragraph. Defaults to empty.
(string) (optional) A visually-hidden seperator to include before each line break. While not required, providing a seperator is greatly encouraged, as it will allow for better indexing of the output by search engines and work better with screen readers.
(bool) (optional) Whether or not the seperator should be visible. If false, a span with the visually-hidden css class will be wrapped around the seperator.
(string) If that passed value for $array is a valid array and is not empty, this method returns a string containing the merged values of an indexed array, seperated by a custom string (if provided) and a line break (
<br>), all wrapped in
<p>...</p>. If the provided value for $array is not an array, or is empty, the method returns an empty string.
The following code...
Would add the following HTML (formatted for legibility here, returned as single line in practice)...
- The $seperator argument was added in v1.1.2
- Format tag support was added in v1.1.2