thanks, yes that looks better, I’ll test and release a new version soon
I think it would be better to call esc_html when putting the error strings into the $errors array rather than calling it on the implode function otherwise I think that esc_html may incorrectly escape the <li> tags.
-
This reply was modified 1 year, 5 months ago by
joneiseman.
I’ve been working on this
The li tags seem to be ok, but yes I agree it would be better, except that the errors are generated in bbpress not my plugin, and I am not a bbpress developer, and unlikely that they will change it.
So your code is the best for the moment !!
I’ll release a new version soon !
Thanks again for your really useful input
should be fixed in 6.2.1 just released, please confirm
Well it no longer crashes but it doesn’t display the list correctly. I tested it out with this shortcode:
add_shortcode("myshortcode", 'myshortcodefunc');
function myshortcodefunc()
{
$arr = [ "str1", "str2", "str3" ];
return '<li>' . esc_html(implode("</li>\n<li>", $arr)) . '</li>';
}
This displayed as a list if I removed the esc_html. However, if I leave in the esc_html in there then it looks like this:
- str1</li> <li>str2</li> <li>str3
Changing the function to this works correctly:
function myshortcodefunc()
{
$arr = [ "str1", "str2", "str3" ];
$ret = "";
foreach ($arr as $str) {
$ret .= '<li>' . esc_html($str) . '</li>';
}
return $ret;
}
Using wp_kses_post instead of esc_html also works:
function myshortcodefunc()
{
$arr = [ "str1", "str2", "str3" ];
return '<li>' . wp_kses_post(implode("</li>\n<li>", $arr)) . '</li>';
}
Thanks, we were both getting to the same conclusion (kses_post), and thanks for your continued input
I am now planning on
<li><?php echo wp_kses_post(implode( "</li>\n<li>", $errors )); ?></li>
I’ll release this tomorrow
fixed in 6.2.3 just released