WordPress & libxml2 Episode IV: A New Plugin

Despite the libxml2 problems having been solved by the release of PHP 5.2.9 and libxml2 2.7.3 there are still hosts out there who refuse to update their known to be broken setup. This really bummed me out, I didn’t want to include a hack to deal with this in core WordPress.

Just as I was ready to throw in the towel and look at getting a work around into core WordPress Peter Westwood suggested a method that would allow this “fix” to work in a plugin. His idea was spot on and I wrote a small WordPress plugin, LibXML2 Fix, the next day and tested it on a WordPress install with this problem. It fixed the stripped brackets problem for XML-RPC requests, so I’ve submitted it to the plugin directory and it’s now available at http://wordpress.org/extend/plugins/libxml2-fix/.

To be clear, the best way to fix this is to upgrade to PHP 5.2.9+ and libxml2 2.7.3+. But if you are stuck in a hosting situation where that’s not possible then the LibXML2 Fixed plugin will fix XML-RPC requests so that brackets don’t get stripped.

I’ve closed ticket 7771 and will be pointing people to this plugin if they can’t upgrade PHP and libxml2.

26 Comments

  1. Thanks alot! I have this problem again after upgrading to FC10 🙁

    Will use this plugin until I have time to upgrade to latest PHP.

  2. Joseph –

    Have you found any situations in which the plugin does not work? I have WordPress 2.7.1 – with the plugin installed (and active) and all the are still stripped.

    Is there anything that needs to be done beyond putting it in the plugins directory and activating it?

    Any help would be appreciated.

    Brian Roy

  3. The plugin only tries to work around libxml2 bracket stripping if it detects that your PHP build is using libxml2 2.7.0, 2.7.1 or 2.7.2. If you are using any other version then the plugin does nothing. First thing I’d look at is a phpinfo() page to see what version of libxml2 your PHP was built with.

  4. I added libxml 2.7.3, since I’m still on an old php and that worked for me. thanks

  5. Hi there, just realised I’ve been having this problem for months on one of my servers without anyone having noticed!

    Hmm I’ve got libxml 2.7.3 and php 5.2.5 and the plugin LibXML2 Fixed but posts are still coming through mangled

    Any other ideas?

    Best regards

    Roger

  6. You only fix 1 section of a 2 part problem. In order to things to work normally again you must be using PHP 5.2.9 and libxml2 2.7.3. Only upgrading one with out the other won’t do any good.

  7. I’ve upgraded everything on my FC10 machine but phpinfo still shows the old libXML version. I then tried installing this plugin, but I’m still getting the stripped when I use the FeedWordPress plugin to syndicate content from some other sites.

  8. Sounds like you need to rebuild PHP in order for it to use the correct version of libXML2.

  9. I just installed it with Yum. I ran yum update and I think I have the most recent version. Are you saying I need to uninstall the yum version and rebuild from source?

  10. If the PHP build from Yum uses the old version of libxml2 then you’ll need to build from source.

  11. Joseph, I ran into this same issue with FC10 and yum install – a simple restart of my web server fixed the problem. FC10 and yum update on both php and libxml2 should do the trick, no source build necessary.

  12. php 5.2.9 and libxml2 2.7.3 on my server, plugin on wordpress 2.7.1 doesnt not work (josephscott.org/code/wordpress/plugin-libxml2-fix/)
    restart server- problem too – HELP!!!

  13. ErnestoJustiniano.org

    Mon 3 Aug 2009 at 5:49 am

    hi, sorry my spanglish…

    i recently change to a dedicated server:
    1) i had a problem with “ –> p
    2) i did install the plugin libxml2
    3) still having problems and
    4) so people do this: ”
    I have enabled suPHP. I have also installed the latest version of PHP and libXML”
    5) all is correct now but still having this problem: publishing with wordpress this example: ¿Dónde están mis viejos amigos de la izquierda? is ok
    but with xmlrpc (windows live writer) this example: `¿Dónde están mis viejos amigos de la izquierda?` is not ok
    6) Having searched a lot the only thing that i have found is to do some modifications to wordpress files…http://blog.hoofoo.net/2009/01/14/wordpress-patch-for-problamatic-libxml2-version/…should i do this? or is another simplier solution? TY

  14. If you PHP 5.2.9 install was built against libxml 2.7.3 then you shouldn’t need this plugin.

  15. I don’t think that has anything to do with the libxml problems that people were seeing. That looks like a language encoding problem.

  16. ok, i will try to explain again my problem:

    1) when i post to wordpress inside wordpress (mean from the administrator) any accented letter is an accented letter. example: á is á, ¿ is ¿ …and so. [write so in database]

    2) when i post using windows live writer an á is á – ¿ is &iquest, this i can see when i go to edit the article. [write acute, rdaquo, iquest… in database]

    3) both 1 and 2 shows correct in browser. but not when i edit the article. so my database can have titles with condition 1 or 2.

    4) the interesting thing is that happens only with the title of the article. the content for both 1 and 2 is correctly written.

    5) i did notice it because my post goes to twitter (shows correct) and then goes to facebook (shows incorrect with acute, iquest, rdaquo …)

    6) i have checked my database tables. wordpress tables are utf8_general, collate for all the database is latin. yesterday i did make a new database with tables utf8 and collate utf8 and the problems persist. so, it is not a question of database format.

    7) i did deactivate all plugins and the problem persist…

    8) information from my new dedicated server people: I have enabled suPHP. I have also installed the latest version of PHP (5.2.10) and libXML (2.7.3), provided by cPanel.

    9) i have tried changing my theme and the problem persist..

    Now what can i do to resolve this? I will appreciate a lot your answer. TY

  17. Something in WordPress is likely not dealing with the encoding correctly. This might be related to long standing problem with WordPress has in storing the encoded version of a post title in the database, instead of the raw (but properly escaped) version of the title string.

  18. Hello,

    When I post on by WordPress blog from flickr, the are stripped from the message and I see only html content as text.
    see:
    http://mgroleau.com/wp/?p=53

    My WordPress version is 2.8.5 and my PHP version is 5.2.9 and my libxml2 version is 2.6.27

    Like the LibXML2 version is not the 2.7.3+ I installed and activate the LibXML2 fix plugin, but the result is the same.

  19. That certainly looks like the same libxml problem where brackets are stripped. But with that version of libxml it shouldn’t be an issue.

    Try adding that version to the plugin and see if it solves it.

  20. Hello,

    Wich version? I already installed and activated the last version (0.2.2) available on WordPress repository without positive result.

    Thanks for your help

  21. The plugin looks up your libxml version number and then compares to a list of versions that are know to have this problem. Add your libxml version to that list and see if that fixes the problem.

  22. Thanks, You are a champion, it works now!

  23. No problem, glad that fixed it.

  24. Thank you so much! Your plugin worked like magic. I just had to edit it to include the following lines since I also needed to be able to use single and double quotes.

    $HTTP_RAW_POST_DATA = str_replace( ‘'’, ‘'’, $HTTP_RAW_POST_DATA );
    $HTTP_RAW_POST_DATA = str_replace( ‘"’, ‘"’, $HTTP_RAW_POST_DATA );

    (Hope this code displays properly)

    Looking forward to my hosting company upgrading their PHP. :

  25. Oops! Well, my code almost displayed properly. It just converted the character codes into the actual characters, let’s see if I can portray it another way (for those who need to know).

    As seen the pattern of the character codes in the lines already included within the plugin, character codes start with an ampersand (&) and end with a semicolon (;). The part in between goes as follows:

    For a single quote (‘):
    apos
    #39

    For a double quote (“):
    quot
    #34

    Hope this helps somebody.

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2019 Joseph Scott

Theme by Anders NorénUp ↑