1
« on: 16 May 2009, 05:47 »
I searched and found how to allow users other than administrators to post polls, but it was originally all or nothing. I wanted to allow Editors to only manage and add Polls. I didn't want them changing the look and feel of the polls (options and templates) and I definitely didn't want them un-installing the wp-polls plugin!!!
So I came up with these modifications.
In polls-add.php you need to modify the first bit of code at the top of the file:
### Check Whether User Can Manage Polls
if(!current_user_can('add_poll')) {
die('Access Denied');
}
Disable the plugin by going to "Plugins | Installed | WP-Polls | Deactivate". Then edit the recently disabled plugin.
Find the Poll Administration Menu function and modify it to look like the following:
### Function: Poll Administration Menu
add_action('admin_menu', 'poll_menu');
function poll_menu() {
if (function_exists('add_menu_page')) {
add_menu_page(__('Polls', 'wp-polls'), __('Polls', 'wp-polls'), 'manage_polls', 'wp-polls/polls-manager.php', '', plugins_url('wp-polls/images/poll.png'));
}
if (function_exists('add_submenu_page')) {
add_submenu_page('wp-polls/polls-manager.php', __('Manage Polls', 'wp-polls'), __('Manage Polls', 'wp-polls'), 'manage_polls', 'wp-polls/polls-manager.php');
add_submenu_page('wp-polls/polls-manager.php', __('Add Poll', 'wp-polls'), __('Add Poll', 'wp-polls'), 'add_poll', 'wp-polls/polls-add.php');
add_submenu_page('wp-polls/polls-manager.php', __('Poll Options', 'wp-polls'), __('Poll Options', 'wp-polls'), 'edit_plugins', 'wp-polls/polls-options.php');
add_submenu_page('wp-polls/polls-manager.php', __('Poll Templates', 'wp-polls'), __('Poll Templates', 'wp-polls'), 'edit_plugins', 'wp-polls/polls-templates.php');
add_submenu_page('wp-polls/polls-manager.php', __('Uninstall WP-Polls', 'wp-polls'), __('Uninstall WP-Polls', 'wp-polls'), 'delete_plugins', 'wp-polls/polls-uninstall.php');
}
}
And at the very end of the file you'll find this comment. Replace the comment to the end of the file to look like this:
// Set 'manage_polls' Capabilities To Administrator
$role = get_role('administrator');
if(!$role->has_cap('manage_polls')) {
$role->add_cap('manage_polls');
}
if(!$role->has_cap('add_poll')) {
$role->add_cap('add_poll');
}
$role = get_role('editor');
if(!$role->has_cap('manage_polls')) {
$role->add_cap('manage_polls');
}
if(!$role->has_cap('add_poll')) {
$role->add_cap('add_poll');
}
$role = get_role('author');
if(!$role->has_cap('add_poll')) {
$role->add_cap('add_poll');
}
cron_polls_place();
}
?>
And now this will allow Authors to Add Polls, but not Manage them. Editors can Manage and Add Polls, but can't change options or templates. And Administrators have complete control.
I wasn't sure if Authors could delete other people's polls or not. I was assuming they could. However, I didn't test whether they could or not when they had the manage_polls right, so I'm not sure. It would be interesting to know if anyone has time. I don't want polls to appear and disappear off my site too rapidly. So I thought that the editors can modify the POLL PAGE to publish the poll for the general audience. Although the newly created polls will show up on a POLL ARCHIVE page.
It would be nice to have the ability to approve polls... if anyone can hack something together for that quickly.
Thanks.