Permalink
Browse files

added set method to allow for setting arbitrary options. update get m…

…ethod to take a default value and not error if the option doesn't exist.
  • Loading branch information...
1 parent 04fa31e commit 8564476ba3f5c352bd3bf514b553b95f6be80bd7 @cgutierrez committed Apr 23, 2012
Showing with 17 additions and 4 deletions.
  1. +17 −4 options/options.php
View
@@ -100,11 +100,24 @@ function __construct($sections = array(), $args = array(), $extra_tabs = array()
*
* @param $array $args Arguments. Class constructor arguments.
*/
- function get($opt_name){
- return $this->options[$opt_name];
+ function get($opt_name, $default = null){
+ return (!empty($this->options[$opt_name])) ? $this->options[$opt_name] : $default;
}//function
/**
+ * ->set(); This is used to set an arbitrary option in the options array
+ *
+ * @since NHP_Options 1.0.1
+ *
+ * @param string $opt_name the name of the option being added
+ * @param mixed $value the value of the option being added
+ */
+ function set($opt_name, $value) {
+ $this->options[$opt_name] = $value;
+ update_option($this->args['opt_name'], $this->options);
+ }
+
+ /**
* ->show(); This is used to echo and option value from the options array
*
* @since NHP_Options 1.0.1
@@ -441,8 +454,8 @@ function _validate_options($plugin_options){
unset($plugin_options['import']);
unset($plugin_options['import_code']);
unset($plugin_options['import_link']);
-
- return $plugin_options;
+
+ return $plugin_options;
}//function

0 comments on commit 8564476

Please sign in to comment.