Is there any reason at all that I can’t use a space in a WP option name/key? Ex.
update_option( 'my option name', 'abc' );
I can’t find anything that states I can’t, but every example uses an underscore instead. I want to know if using a space will actually break anything now or in the future.
Other than general WordPress practice (http://make.wordpress.org/core/handbook/coding-standards/php/) which encourages spaces to always be replaced with – in file names and _ for other purposes, there isn’t a set reason that you can’t use spaces in an option name.
From my tests, there is no technical reason to limit you from using a space.
(edit) looking further, the SQL is:
$row = $wpdb->get_row( $wpdb->prepare( “SELECT autoload FROM $wpdb->options WHERE option_name = %s”, $option ) );
so any escaped value should work but just to be safe, you should always use esc_sql() as it doesn’t do it specifically.
You can use a space, but it is a little bit annoying to select this key per keyboard. Normally, you can use Ctrl + Shift + Arrow to select a string. Hyphens and spaces are stop points for this kind of selection.
You can actually use any characters in the settings (except maybe quotes).
These are all valid option names:
Important Limitations
If you specify a longer name, the option name will be truncated to fit 64 characters in DB (not in code). So this makes it impossible to retrieve the option value again. Always ensure your option name is max 64 characters long.
If you save an option
APIKEY
you can also access it viaapikey
My tipp
Create a small function that you use to prefix/sanitize your option keys in every plugin/theme, which takes care of the restrictions for you, like this here: