Skip to content

Instantly share code, notes, and snippets.

@whalesalad
Created October 1, 2009 23:54
Show Gist options
  • Select an option

  • Save whalesalad/199333 to your computer and use it in GitHub Desktop.

Select an option

Save whalesalad/199333 to your computer and use it in GitHub Desktop.
<?php
/**
* @package Word-Press
* @subpackage Tasty
*/
class Settings {
function __construct() {
$this->get_settings();
// update_option('tasty_settings', NULL);
}
function defaults() {
$defaults->color = 'pink';
$defaults->sidebar_alignment = 'right';
$defaults->disable_header_text = false;
$defaults->disable_header_search = false;
$defaults->socialgrid_enabled = true;
return $defaults;
}
function get_settings() {
$saved_settings = maybe_unserialize(get_option('tasty_settings'));
$defaults = $this->defaults();
if (!empty($saved_settings) && is_object($saved_settings)) {
foreach ($saved_settings as $setting => $value)
if (empty($setting)) {
$this->$setting = $defaults->$setting;
} else {
$this->$setting = $value;
}
}
if (empty($saved_settings)) {
update_option('tasty_settings', $defaults);
}
}
function save_settings() {
$default_settings = $this->defaults();
foreach ($default_settings as $setting => $value) {
if (!isset($this->$setting))
$this->$setting = $default_settings->$setting;
}
update_option('tasty_settings', $this);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment