WordPress.org

Ready to get started?Download WordPress

Forums

Magic quotes escape for plugins (2 posts)

  1. Stefano Lissa
    Member
    Posted 6 years ago #

    Writing an option page for a plugin, I have to deal with the tedious magic quotes escaping.
    I think in WP there is already such a function (surely magic quotes are managed in the "public" part of WP, there is some row of code in wp-settings.php).

    This function can be used and will be stable in the future? What's its name? I rhink in WP there are lots of functions useful for plugin writers: what about organize a section in the documentation for those features?

    Satollo.

  2. gwycon
    Member
    Posted 5 years ago #

    Whilst developing my latest WordPress Plugin, To Do List, I had a problem when writing a text file from input into a textarea element. When magic quotes were turned on, the text file had all the special characters escaped!

    Looking around for information I found the following code fragment very useful that checks to see if magic quotes are turned on, on your server. And if so, the text is formatted to remove escape characters.

    if( get_magic_quotes_gpc() )
    {
     // if magic quotes on, get rid of escape slashes inserted into text
     $todo_list = stripslashes($todo_list);
    }

    This worked perfectly and meant only text was saved to file, and no escape characters. Obviously, you need a check to see if magic quotes are enabled as you do not want to try to remove escape characters when magic quotes are OFF!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.