Created
February 8, 2013 15:49
-
-
Save ericjuden/4739857 to your computer and use it in GitHub Desktop.
WordPress Options Class
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 | |
class My_Plugin_Options { | |
var $options; | |
var $option_name; | |
var $is_site_option; // Are we using Multisite and saving to global options? | |
function My_Plugin_Options($option_name, $is_site_options = false){ | |
$this->option_name = $option_name; | |
$this->is_site_option = $is_site_options; | |
if($this->is_site_option){ | |
$this->options = get_site_option($this->option_name); | |
} else { | |
$this->options = get_option($this->option_name); | |
} | |
if(!is_array($this->options)){ | |
$this->options = array(); | |
} | |
} | |
function __get($key){ | |
return $this->options[$key]; | |
} | |
function __set($key, $value){ | |
$this->options[$key] = $value; | |
} | |
function __isset($key){ | |
return array_key_exists($key, $this->options); | |
} | |
function save(){ | |
if($this->is_site_option){ | |
update_site_option($this->option_name, $this->options); | |
} else { | |
update_option($this->option_name, $this->options); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment