Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add set() method and small change to get() #32

Merged
merged 1 commit into from

2 participants

@cgutierrez

Hola!

I wasn't sure if you would be interested in this or not. I updated the get() method to take an optional default value and to check if the option is empty to prevent a notice if the option doesn't exist.

I also added a set() method to enable setting arbitrary options using the opt_name in the $args array.

@cgutierrez cgutierrez 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.
8564476
@leemason
Owner

nice one, merged.

@leemason leemason merged commit e986480 into leemason:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 23, 2012
  1. @cgutierrez

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

    cgutierrez authored
    …ethod to take a default value and not error if the option doesn't exist.
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 4 deletions.
  1. +17 −4 options/options.php
View
21 options/options.php
@@ -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
Something went wrong with that request. Please try again.