All Good Things Must Come To An End

As you all know, I have been doing WordPress plugins and supporting it for the past 6 years. These 6 years of my life, I have been through my polytechnic education, my national service as well as my university education.

I just graduated from university in December 2009 and have been looking for full-time jobs. I am offered a full-time job and will be starting work on 1st February 2010.

I regret to say that I am NOT ABLE to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

However, I WILL still update my plugins whenever I can and you still can report bugs to me via email and I will try to fix it.


Author Topic: Custom Modifications / Access Control for Admins, Editors and Authors  (Read 4759 times)

0 Members and 1 Guest are viewing this topic.

Offline wiredsage

  • Newbie
  • *
  • Posts: 1
    • View Profile
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: [Select]

### 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:
Code: [Select]

### 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:
Code: [Select]

// 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.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Thanks for sharing this hack. Stickied!

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline Electron

  • Newbie
  • *
  • Posts: 24
    • View Profile
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.

Offline hugo

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
I made those modifications, but there is no "Polls"-Button on the left to manage and add polls for editors!?  :( ???

Offline boah123

  • Newbie
  • *
  • Posts: 3
    • View Profile
  • WordPress Version: WordPress 2.8.x
  • Theme Name: Self made
Thanks for sharing this hack. Stickied!


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.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
You can use a role/cap manager plugin to do that instead.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline boah123

  • Newbie
  • *
  • Posts: 3
    • View Profile
  • WordPress Version: WordPress 2.8.x
  • Theme Name: Self made
Well, then I hope that a role cap manager plugin will do the job (stupid to use another plugin). I tried to follow up each step in the first post, but the administrators role can't add polls: Access Denied. By making this thread sticky you suggest to support the solution. It's not working. I use the most recent version of your plugin and Wordpress. Sorry to tell you.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
The hack is also for the most recent version of the plugin. By making the thread sticky it means I recognize the contribution of the user and allow for other users who wanted the same feature be able to do it themselves. It is not possible to satisfy everyone.

The default admin role is able to add poll. If not it means something wrong with your WordPress or during the activation of WP-Polls somewhere went wrong. Do a fresh install of WP and WP-Polls on another folder on your server to see if it works in the first place.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline boah123

  • Newbie
  • *
  • Posts: 3
    • View Profile
  • WordPress Version: WordPress 2.8.x
  • Theme Name: Self made
Okay, I followd the steps over and over again. And guess what? It works!

Thanks for supporting me not giving up to find the answer. Good luck with the plugin. Thanks!