diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index 2309229..4fc4801 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -62,6 +62,23 @@ class WhatDidTheySayAdmin { $this->_update_options('allowed_users', $allowed_users); } + function handle_update_options($requested_options) { + $updated_options = array( + 'only_allowed_users' => false + ); + + foreach ($requested_options as $option => $value) { + switch ($option) { + case 'only_allowed_users': + $updated_options['only_allowed_users'] = true; + break; + } + } + + $options = array_merge(get_option('what-did-they-say-options'), $updated_options); + update_option('what-did-they-say-options', $options); + } + function read_language_file() { if (file_exists($this->language_file)) { foreach (file($this->language_file, FILE_IGNORE_NEW_LINES) as $language) { diff --git a/test/WhatDidTheySayAdminTest.php b/test/WhatDidTheySayAdminTest.php index df640eb..e17a807 100644 --- a/test/WhatDidTheySayAdminTest.php +++ b/test/WhatDidTheySayAdminTest.php @@ -38,6 +38,20 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase { $options = get_option('what-did-they-say-options'); $this->assertEquals(array(1), $options['allowed_users']); } + + function testHandleUpdateOptions() { + $admin = new WhatDidTheySayAdmin(); + + update_option('what-did-they-say-options', array('only_allowed_users' => false)); + + $admin->handle_update_options(array( + 'only_allowed_users' => 'yes' + )); + + $options = get_option('what-did-they-say-options'); + $this->assertTrue($options['only_allowed_users']); + + } } ?> \ No newline at end of file