diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index d3c3068..6aaed23 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -12,8 +12,6 @@ class WhatDidTheySayAdmin { 'it', 'de' ), - 'only_allowed_users' => false, - 'users' => array(), 'capabilities' => array( 'submit_transcriptions' => 'administrator', 'approve_transcriptions' => 'administrator', @@ -124,19 +122,20 @@ class WhatDidTheySayAdmin { */ function user_has_cap($capabilities, $requested_capabilities, $capability_name) { $options = get_option('what-did-they-say-options'); + if (is_array($options)) { + $role_cascade = array('administrator', 'editor', 'author', 'contributor', 'subscriber'); + $allowed_roles = array(); + $capture_roles = false; - $role_cascade = array('administrator', 'editor', 'author', 'contributor', 'subscriber'); - $allowed_roles = array(); - $capture_roles = false; + for ($i = 0; $i < count($role_cascade); ++$i) { + if (in_array($role_cascade, $capabilities)) { $capture_roles = true; } + if ($capture_roles) { $allowed_roles[] = $role_cascade[$i]; } + } - for ($i = 0; $i < count($role_cascade); ++$i) { - if (in_array($role_cascade, $capabilities)) { $capture_roles = true; } - if ($capture_roles) { $allowed_roles[] = $role_cascade[$i]; } - } - - foreach ($requested_capabilities as $requested_capability) { - if (in_array($options['capabilities'][$requested_capability], $allowed_roles)) { - $capabilities[$requested_capability] = true; + foreach ($requested_capabilities as $requested_capability) { + if (in_array($options['capabilities'][$requested_capability], $allowed_roles)) { + $capabilities[$requested_capability] = true; + } } } @@ -227,7 +226,7 @@ class WhatDidTheySayAdmin { } } - $updated = __('Transcripts updated', 'what-did-they-say'); + $updated = __('Transcripts updated.', 'what-did-they-say'); break; } } @@ -301,7 +300,7 @@ class WhatDidTheySayAdmin { $options['capabilities'][$capability] = $info['capabilities'][$capability]; } } - $updated = __('User capabilities updated', 'what-did-they-say'); + $updated = __('User capabilities updated.', 'what-did-they-say'); } break; } @@ -312,6 +311,25 @@ class WhatDidTheySayAdmin { return $updated; } + /** + * Handle resettings what-did-they-say-options. + * @param array $info The part of the $_POST array for What Did They Say?!? + * @return string|false A string if a message is to be displayed, or false if no message. + */ + function handle_update_reset_options($info) { + $updated = false; + if (current_user_can('manage_options')) { + switch ($info['action']) { + case "reset_options": + delete_option('what-did-they-say-options'); + $this->install(); + $updated = __('What Did They Say?!? options reset.', 'what-did-they-say'); + break; + } + } + return $updated; + } + /** * Read a data file containing all the known languages on Earth. * The data originally came from http://www.langtag.net/, specifically http://www.langtag.net/registries/lsr-language.txt. @@ -337,8 +355,9 @@ class WhatDidTheySayAdmin { $options = get_option('what-did-they-say-options'); if (empty($options)) { $this->default_options['languages'] = $this->build_default_languages(); + ksort($this->default_options['languages']); update_option('what-did-they-say-options', $this->default_options); - } + } } /** @@ -397,6 +416,7 @@ class WhatDidTheySayAdmin { */ function manage_admin() { $options = get_option('what-did-they-say-options'); + $nonce = wp_create_nonce('what-did-they-say'); include(dirname(__FILE__) . '/admin.inc'); } @@ -408,6 +428,7 @@ class WhatDidTheySayAdmin { global $post; $options = get_option('what-did-they-say-options'); + $transcripts = $this->what_did_they_say->get_transcripts($post->ID); $queued_transcriptions = $this->what_did_they_say->get_queued_transcriptions_for_post($post->ID); diff --git a/classes/admin.inc b/classes/admin.inc index 65a9337..6980458 100644 --- a/classes/admin.inc +++ b/classes/admin.inc @@ -1,7 +1,7 @@

- +
@@ -31,74 +31,86 @@
- -

- - - - - - - - - $info) { - $default = isset($info['default']); - $name = $info['name']; - ?> + +

+ +
+ + + + + + + + $info) { + $default = isset($info['default']); + $name = $info['name']; + ?> + + + + + + + + - - - - + - - - - - - -
+ +
+ + + + + +
+
+ + + + +
+ + + + +
+
+
+ + + + +
+
- -
- - - - - -
-
- - - - +
- - - -
-
-
- - - - + + +
-
- - - - -
-
+ + + +

+

+
+ + + +
+
+ diff --git a/test/TestWhatDidTheySay.html b/test/TestWhatDidTheySay.html new file mode 100644 index 0000000..2e01b4b --- /dev/null +++ b/test/TestWhatDidTheySay.html @@ -0,0 +1,146 @@ + + + + + + +TestWhatDidTheySay + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TestWhatDidTheySay
open/wp-admin/
clickAndWaitlink=Installed
assertTextPresentWhat Did They Say?!?
click//table[@id='all-plugins-table']/tbody/tr[15]/td[2]/div/span[1]/a
clickAndWait//a[contains(@href,'what-did-they-say') and contains(@href,'activate')]
assertTextPresentPlugin activated.
assertElementPresent//a[contains(text(), "What Did They Say?!?")]
clicklink=exact:What Did They Say?!?
assertTextPresentReset Settings to Default
click//input[@value='Reset What Did They Say?!?']
assertConfirmationAre you sure? You could leave transcriptions inaccessible.
assertTextPresentWhat Did They Say?!? options reset
selectwdts[capabilities][submit_transcriptions]label=Editor
selectwdts[capabilities][approve_transcriptions]label=Editor
selectwdts[capabilities][change_languages]label=Editor
clickAndWait//input[@value='Change capabilities']
assertTextPresentUser capabilities updated.
assertSelectedLabelwdts[capabilities][submit_transcriptions]Editor
assertSelectedLabelwdts[capabilities][approve_transcriptions]Editor
assertSelectedLabelwdts[capabilities][change_languages]Editor
assertText//th/span[contains(text(), "English")]/../../td[1](yes)
clickAndWait//th/span[contains(text(), "German")]/../..//input[@value="Default"]
assertTextPresentGerman set as default.
assertNotText//th/span[contains(text(), "English")]/../../td[1](yes)
assertText//th/span[contains(text(), "German")]/../../td[1](yes)
+ +