• Resolved joneiseman

    (@joneiseman)


    PHP Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in …/public_html/wp-content/plugins/bbp-style-pack/includes/functions_bugs.php:675

    On line 675 of bbp-style-pack/includes/funcions_bugs.php it has the following line:

    <li><?php echo implode( "</li>\n<li>", esc_html($errors) ); ?></li>

    The variable $errors is an array and esc_html expects a string. I think this should be changed to to this:

    <li><?php echo esc_html( implode( "</li>\n<li>", $errors ) ); ?></li>
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Robin W

    (@robin-w)

    thanks, yes that looks better, I’ll test and release a new version soon

    Thread Starter joneiseman

    (@joneiseman)

    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.
    Plugin Author Robin W

    (@robin-w)

    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

    Plugin Author Robin W

    (@robin-w)

    should be fixed in 6.2.1 just released, please confirm

    Thread Starter joneiseman

    (@joneiseman)

    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;
    }
    Thread Starter joneiseman

    (@joneiseman)

    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>';
    }
    Plugin Author Robin W

    (@robin-w)

    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

    Plugin Author Robin W

    (@robin-w)

    fixed in 6.2.3 just released

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘PHP Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) …’ is closed to new replies.