Title: Using the get_option() function and escaping
Last modified: April 22, 2019

---

# Using the get_option() function and escaping

 *  Resolved [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [7 years ago](https://wordpress.org/support/topic/using-the-get_option-function-and-escaping/)
 * Hi,
 * I’m using `get_option()` quite a lot inside my plugin, to retrieve settings from
   my DB.
 * Many settings are checkboxes, with value “true” or “false”.
 * By default I use escaping:
 *     ```
       esc_attr( get_option('my-setting') );
       ```
   
 * My question: is it necessary to escape the output in this case? The value in 
   DB is always “true” or “false”. And I do sanitize upon input.
 * Guido

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

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [7 years ago](https://wordpress.org/support/topic/using-the-get_option-function-and-escaping/#post-11454225)
 * Are you actually printing out “true” or “false”? You would only need to use `
   esc_attr` if you are outputting a HTML attribute. That function escapes quotes
   so that the attribute comes out right.
    Look at the example on this page: [https://developer.wordpress.org/reference/functions/checked/](https://developer.wordpress.org/reference/functions/checked/)
 * Also, please use an array for your options, instead of a separate option for 
   each one. (like in the example) Using separate options makes a mess of the options
   table.
 *  Thread Starter [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [7 years ago](https://wordpress.org/support/topic/using-the-get_option-function-and-escaping/#post-11455647)
 * Hi Joy,
 * Thanks for your reply.
 * Yes, something like this:
 *     ```
       if (get_option('my-setting') == "true") {
         do stuff
       }
       ```
   
 * I did not know about an array for options, so I guess you mean storing multiple
   values in a single option instead of an individual option for each value. Will
   look into this for sure, because I have about 50 values which I now store in 
   50 options..
 * Guido
 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [7 years ago](https://wordpress.org/support/topic/using-the-get_option-function-and-escaping/#post-11455738)
 * The `checked()` function is for output of the checkbox, but your code example
   is not doing output, so not sure what we are talking about. You should not trust
   database values, and always escape when output, but comparing to a known value
   is a fine.
 * _But definitely use an array._
 *  Thread Starter [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [7 years ago](https://wordpress.org/support/topic/using-the-get_option-function-and-escaping/#post-11460137)
 * Hi Joy,
 * The `checked()` function was not really related to my question.
    I’m using that`
   if` condition to do stuff.. or not. If my checkbox is checked it outputs a “true”
   value, otherwise “false”. And I’m only using checkboxes for `if` conditions throughout
   my plugin:
 *     ```
       if (get_option('my-setting') == "true") {
         do stuff
       } else {
         do nothing
       }
       ```
   
 * Guido

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

The topic ‘Using the get_option() function and escaping’ is closed to new replies.

## Tags

 * [escaping](https://wordpress.org/support/topic-tag/escaping/)
 * [Get_Option](https://wordpress.org/support/topic-tag/get_option/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [Guido](https://wordpress.org/support/users/guido07111975/)
 * Last activity: [7 years ago](https://wordpress.org/support/topic/using-the-get_option-function-and-escaping/#post-11460137)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
