Skip to content

Commit

Permalink
added set method to allow for setting arbitrary options. update get m…
Browse files Browse the repository at this point in the history
…ethod to take a default value and not error if the option doesn't exist.
  • Loading branch information
cgutierrez committed Apr 23, 2012
1 parent 04fa31e commit 8564476
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions options/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,23 @@ 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
*
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8564476

Please sign in to comment.