• Resolved highlyresponsivetech

    (@highlyresponsivetech)


    This is just a report on an issue related to PHP snippets and using HTML tags inside of those. The code editor is trying to be intelligent I’m sure by not allowing malformed HTML, but in PHP code, that’s illogical to require proper opening and closing HTML tags. In two examples, I’ve run into this bug where WPCode tries to add closing HTML tags to the end of a PHP snippet or just straight up deletes my closing HTML tag because there was no opening tag. In the case of strip_tags(), I was feeding it a string of allowed tags like so: strip_tags($html, ‘<p><div><ul><li>’) but WP Code would see that there are no closing HTML tags for those HTML tags in the second parameter of the function and just plop them at the end of the PHP snippet messing up the entire thing. In another case, I was searching for closing tags to dynamically insert content using the_content filter after X number of </ul> closing tags and when I saved the code snippet containing a variable assigned to ‘</ul>’, it just removed </ul> completely obviously rendering the code useless. The result is I had to use another code snippets plugin to achieve what I wanted in one situation and was able to reformat the the allowed tags in strip_tags to an array and make it work in the other situation.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @highlyresponsivetech,

    Can you please share more details about the setup where you encountered this issue?

    I tried creating a new PHP snippet in WPCode with the following code:

    $html = '';
    $html = strip_tags($html, '<p><div><ul><li>');

    Saving the snippet did not change anything in the code and I can’t think of any scenario where WPCode would try to close those tags.

    Is it possible that you are using another plugin that is attempting to fix the tags in the content of your posts/pages that may be interfering?

    If yes, we’d love to hear about it to try to prevent this from happening but on its own WPCode does not try to close those tags in the scenario you described.

    You can confirm this yourself by trying to use WPCode with your code on a site with no other plugin active.

    Thread Starter highlyresponsivetech

    (@highlyresponsivetech)

    It’s hard to imagine that any of the plugins on the site are doing that in, but I will try again on another site without any plugins active. The only potential plugin I can see that might interfere would be Wordfence, but I’ll give it a go on another site with all plugins deactivated. If it’s still happening, I’ll send a Loom or something of it happening.

    Thread Starter highlyresponsivetech

    (@highlyresponsivetech)

    Hi Mircea, I tested this on a few other sites and did not get the same results, so it does seem to be some other plugin causing the weird behavior. Thanks for your quick response!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘HTML tags removed or added in PHP snippet resulting in errors’ is closed to new replies.