Merge pull request #47 from darkwing/db-defaults

Organize option defaults
This commit is contained in:
David Walsh 2016-03-04 10:27:03 -06:00
Родитель 69cb0edcd4 49b5998b07
Коммит e206e7e838
2 изменённых файлов: 19 добавлений и 14 удалений

Просмотреть файл

@ -63,8 +63,8 @@ class SW_Cache_Admin {
public function on_switch_theme() { public function on_switch_theme() {
if(get_option('wp_sw_cache_enabled')) { if(get_option('wp_sw_cache_enabled')) {
update_option('wp_sw_cache_enabled', 0); update_option('wp_sw_cache_enabled', SW_Cache_DB::$options['wp_sw_cache_enabled']);
update_option('wp_sw_cache_files', array()); update_option('wp_sw_cache_files', SW_Cache_DB::$options['wp_sw_cache_files']);
add_action('admin_notices', array($this, 'show_switch_theme_message')); add_action('admin_notices', array($this, 'show_switch_theme_message'));
} }
} }

Просмотреть файл

@ -3,8 +3,19 @@
class SW_Cache_DB { class SW_Cache_DB {
private static $instance; private static $instance;
public static $options;
public function __construct() { public function __construct() {
self::$options = array(
// For v1 we'll prompt the user enable the plugin manually upon activation
'wp_sw_cache_enabled' => 0,
// The "style.css" file is a standard WordPress file, so we can safely assume this exists
'wp_sw_cache_files' => array('styles.css'),
// Create an initial SW version
'wp_sw_cache_version' => time(),
// Setting debug initially will help the user understand what the SW is doing via the console
'wp_sw_cache_debug' => 0
);
} }
public static function getInstance() { public static function getInstance() {
@ -15,24 +26,18 @@ class SW_Cache_DB {
} }
public static function on_activate() { public static function on_activate() {
// For v1 we'll prompt the user enable the plugin manually upon activation foreach(self::$options as $option => $default) {
update_option('wp_sw_cache_enabled', 0); update_option($option, $default);
// The "style.css" file is a standard WordPress file, so we can safely assume this exists }
update_option('wp_sw_cache_files', array('style.css'));
// Create an initial SW version
SW_Cache_Main::update_version();
// Setting debug initially will help the user understand what the SW is doing via the console
update_option('wp_sw_cache_debug', 1);
} }
public static function on_deactivate() { public static function on_deactivate() {
} }
public static function on_uninstall() { public static function on_uninstall() {
delete_option('wp_sw_cache_enabled'); foreach(self::$options as $option => $default) {
delete_option('wp_sw_cache_version'); delete_option($option);
delete_option('wp_sw_cache_files'); }
delete_option('wp_sw_cache_debug');
} }
} }