Created
July 9, 2012 22:16
-
-
Save alexkingorg/3079382 to your computer and use it in GitHub Desktop.
Sample options data accessor function with defaults.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// return a value from the options table if it exists, | |
// or return a default value | |
my_plugin_get_option($key) { | |
$defaults = array( | |
'foo' => 'some string', | |
'bar' => true, | |
'baz' => array( | |
1, 2, 3 | |
) | |
); | |
if (!isset($defaults[$key])) { | |
$defaults[$key] = false; | |
} | |
return get_option($key, $defaults[$key]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment