add per-user permission control

This commit is contained in:
John Bintz 2009-10-14 21:05:39 -04:00
parent b274c28d03
commit 71f974d2cf
3 changed files with 70 additions and 5 deletions

View File

@ -452,7 +452,9 @@ class WhatDidTheySayAdmin {
* @param object $capability_name * @param object $capability_name
* @return array The list of capabilities this user now has. * @return array The list of capabilities this user now has.
*/ */
function user_has_cap($capabilities, $requested_capabilities, $capability_name) { function user_has_cap($capabilities, $requested_capabilities, $args) {
list($capability_name, $user_id) = $args;
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
if (is_array($options)) { if (is_array($options)) {
$role_cascade = array('subscriber', 'contributor', 'author', 'editor', 'administrator'); $role_cascade = array('subscriber', 'contributor', 'author', 'editor', 'administrator');
@ -471,6 +473,16 @@ class WhatDidTheySayAdmin {
} }
} }
$user_capabilities = get_usermeta($user_id, 'transcript_capabilities');
if (is_array($user_capabilities)) {
foreach ($requested_capabilities as $requested_capability) {
if (isset($user_capabilities[$requested_capability])) {
$capabilities[$requested_capability] = true;
}
}
}
return $capabilities; return $capabilities;
} }
@ -788,6 +800,39 @@ class WhatDidTheySayAdmin {
return $updated; return $updated;
} }
/**
* Update per-user capabilities.
*/
function handle_update_user_capabilities($info) {
global $wpdb;
$updated = false;
if (current_user_can('edit_users')) {
$users = $wpdb->get_results("SELECT ID, user_login from $wpdb->users ORDER BY user_login");
foreach ((array)$users as $user) {
$user_capabilities = array();
foreach (array_keys($this->capabilities) as $key) {
if (isset($info['user_capabilities'][$user->ID])) {
if (isset($info['user_capabilities'][$user->ID][$key])) {
$user_capabilities[$key] = true;
}
}
}
if (!empty($user_capabilities)) {
update_usermeta($user->ID, 'transcript_capabilities', $user_capabilities);
} else {
delete_usermeta($user->ID, 'transcript_capabilities');
}
}
$updated = __('Per-user permissions updated.', 'what-did-they-say');
}
return $updated;
}
/** /**
* Handle resettings what-did-they-say-options. * Handle resettings what-did-they-say-options.
* @param array $info The part of the $_POST array for What Did They Say?!? * @param array $info The part of the $_POST array for What Did They Say?!?

View File

@ -47,11 +47,18 @@
if (!is_array($user_capabilities)) { $user_capabilities = array(); } if (!is_array($user_capabilities)) { $user_capabilities = array(); }
?> ?>
<tr> <tr>
<th scope="row"><?php echo $user->user_login ?></th> <th scope="row">
<?php echo get_avatar($user->ID, 20) ?>
<?php echo $user->user_login ?>
</th>
<?php foreach ($this->capabilities as $key => $label) { ?> <?php foreach ($this->capabilities as $key => $label) { ?>
<td> <td>
<label style="white-space: nowrap"> <label style="white-space: nowrap">
<input type="checkbox" name="wdts[user_capabilities][<?php echo $user->ID ?>][<?php echo $key ?>]" value="yes" /> <input type="checkbox"
name="wdts[user_capabilities][<?php echo $user->ID ?>][<?php echo $key ?>]"
value="yes"
<?php echo (isset($user_capabilities[$key])) ? 'checked="checked"' : '' ?>
/>
<?php echo $label ?> <?php echo $label ?>
</label> </label>
</td> </td>
@ -61,7 +68,7 @@
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td colspan="3"> <td colspan="3">
<input type="submit" value="<?php _e('Update per-user permissions', 'what-did-they-say') ?>" /> <input class="button" type="submit" value="<?php _e('Update per-user permissions', 'what-did-they-say') ?>" />
</td> </td>
</tr> </tr>
</table> </table>

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: what-did-they-say 0.9.1\n" "Project-Id-Version: what-did-they-say 0.9.1\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-10-14 08:16-0400\n" "POT-Creation-Date: 2009-10-14 20:49-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -650,6 +650,19 @@ msgstr ""
msgid "Change capabilities" msgid "Change capabilities"
msgstr "" msgstr ""
#: classes/partials/_capabilities.inc:33
msgid "Per-user Permissions"
msgstr ""
#: classes/partials/_capabilities.inc:35
msgid ""
"Give specified users permissions above and beyond their role permissions."
msgstr ""
#: classes/partials/_capabilities.inc:64
msgid "Update per-user permissions"
msgstr ""
#: classes/partials/_sample-transcript.inc:4 #: classes/partials/_sample-transcript.inc:4
msgid "[scene-heading]Ext. The Old Man's House[/scene-heading]" msgid "[scene-heading]Ext. The Old Man's House[/scene-heading]"
msgstr "" msgstr ""