WordPress Plugins > WP-Polls
Custom Modifications / Access Control for Admins, Editors and Authors
wiredsage:
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:
--- Code: ---
### Check Whether User Can Manage Polls
if(!current_user_can('add_poll')) {
die('Access Denied');
}
--- End code ---
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:
--- Code: ---
### 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');
}
}
--- End code ---
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:
--- Code: ---
// 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();
}
?>
--- End code ---
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.
GaMerZ:
Thanks for sharing this hack. Stickied!
Electron:
Wow nice. This is really useful. It would be nice if the add poll code was combined with the add post code. That way it would be easier for most to post.
hugo:
I made those modifications, but there is no "Polls"-Button on the left to manage and add polls for editors!? :( ???
boah123:
--- Quote from: GaMerZ on 16 May 2009, 07:03 ---Thanks for sharing this hack. Stickied!
--- End quote ---
I have an update suggestion:
- Why not give user the option to add a global var in the wp-config.php file of wordpress if they want to give editors access to add polls and poll management (first to menu items).
I would love to have this option instead of self changing the plugin.
Navigation
[0] Message Index
[#] Next page
Go to full version