diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index 8a4c83c..2309229 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -30,6 +30,12 @@ class WhatDidTheySayAdmin { } } + function _update_options($which, $value) { + $options = get_option('what-did-they-say-options'); + $options[$which] = $value; + update_option('what-did-they-say-options', $options); + } + function handle_update_languages($language_info) { $languages = array(); foreach ($language_info as $code => $info) { @@ -39,7 +45,21 @@ class WhatDidTheySayAdmin { $languages[] = $language; } } - update_option('what-did-they-say-languages', $languages); + $this->_update_options('languages', $languages); + } + + function handle_update_allowed_users($users) { + $allowed_users = array(); + foreach ($users as $user) { + if (is_numeric($user)) { + $user_info = get_userdata($user); + if (!empty($user_info)) { + $allowed_users[] = $user; + } + } + } + + $this->_update_options('allowed_users', $allowed_users); } function read_language_file() { @@ -82,7 +102,7 @@ class WhatDidTheySayAdmin { } function manage_transcriptions_admin() { - $languages = get_option('what-did-they-say-languages'); + $options = get_option('what-did-they-say-options'); include(dirname(__FILE__) . '/admin.inc'); } diff --git a/test/WhatDidTheySayAdminTest.php b/test/WhatDidTheySayAdminTest.php index 3480df6..df640eb 100644 --- a/test/WhatDidTheySayAdminTest.php +++ b/test/WhatDidTheySayAdminTest.php @@ -23,8 +23,20 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase { ); $admin->handle_update_languages(array('en' => array(), 'de' => array('default' => 'yes'), 'meow' => array())); + + $options = get_option('what-did-they-say-options'); + $this->assertEquals(array('en', array('code' => 'de', 'default' => true)), $options['languages']); + } + + function testHandleUpdateAllowedUsers() { + $admin = new WhatDidTheySayAdmin(); + + wp_insert_user((object)array('ID' => 1)); - $this->assertEquals(array('en', array('code' => 'de', 'default' => true)), get_option('what-did-they-say-languages')); + $admin->handle_update_allowed_users(array(1, 2)); + + $options = get_option('what-did-they-say-options'); + $this->assertEquals(array(1), $options['allowed_users']); } }