WordPress.org

Ready to get started?Download WordPress

Forums

WP-Polls
[resolved] Allow Editor to manage Poll (10 posts)

  1. Xcellence IT
    Member
    Posted 1 year ago #

    Hi, this is a one of the great polls plugin, its so simple to use.. and most of the times it just works out of the box... Thank you for this great plugin!

    While I was working on a project, I have one requirement. Currently polls are only available to administrator in admin panel. I want to give editors rights to manage Polls.

    Can you please advise how to do that? And more whether it is possible to do without modifying the Plugin using theme function file?

    http://wordpress.org/extend/plugins/wp-polls/

  2. Xcellence IT
    Member
    Posted 1 year ago #

    Any update here?

  3. kanuharis
    Member
    Posted 1 year ago #

    First Add below code to your theme's functions.php.

    // add poll for editors
    add_action('activate_wp-polls/wp-polls.php', 'tc_add_poll_permissions');
    function tc_add_poll_permissions()	{
    	$add_role = get_role('editor');
    	if(!$add_role->has_cap('manage_polls')) {
    		$add_role->add_cap('manage_polls');
    	}
    }

    Second: If you want to restrict poll menu to "Manage Poll and Add Poll"
    (hide menu like uninstall and Poll options from editors)add this code

    // remove poll admin options for editors
    function tc_remove_poll_menus () {
    	global $current_user;
    
    	if (!current_user_can('administrator')) :
    		global $menu;
    		global $submenu; 
    
    		//remove poll sub menus
    		unset($submenu['wp-polls/polls-manager.php'][2]);   //poll options
    		unset($submenu['wp-polls/polls-manager.php'][3]);   //poll template
    		unset($submenu['wp-polls/polls-manager.php'][4]);   //uninsall plugin
    	endif;
    }
    add_action('admin_menu', 'tc_remove_poll_menus');
  4. Xcellence IT
    Member
    Posted 1 year ago #

    Hi, This doesn't work.

    Just adding that, I'm using Roots theme.

    Any idea?

  5. kanuharis
    Member
    Posted 1 year ago #

    I don't know why its not working. Its works fine on my custom theme. Did you pasted below code to functions.php?

    // add poll for editors
    add_action('activate_wp-polls/wp-polls.php', 'tc_add_poll_permissions');
    function tc_add_poll_permissions()	{
    	$add_role = get_role('editor');
    	if(!$add_role->has_cap('manage_polls')) {
    		$add_role->add_cap('manage_polls');
    	}
    }
    // remove poll admin options for editors
    function tc_remove_poll_menus () {
    	global $current_user;
    
    	if (!current_user_can('administrator')) :
    		global $menu;
    		global $submenu; 
    
    		//remove poll sub menus
    		unset($submenu['wp-polls/polls-manager.php'][2]);   //poll options
    		unset($submenu['wp-polls/polls-manager.php'][3]);   //poll template
    		unset($submenu['wp-polls/polls-manager.php'][4]);   //uninsall plugin
    	endif;
    }
    add_action('admin_menu', 'tc_remove_poll_menus');

    hmm.. forgot to tell you one thing. You should deactivate and activate the plugin after adding the above code to functions.php
    Please update if it worked..

  6. Xcellence IT
    Member
    Posted 1 year ago #

    Hey, thanks for your advise. It works. Earlier I didn't re-activated the plugin, may be that's why it was not working. But it does work correctly after deactivating the plugin, and activitating it again.

    Thanks

  7. kanuharis
    Member
    Posted 1 year ago #

    glad to know that worked

  8. Xcellence IT
    Member
    Posted 1 year ago #

    Thank you for your great support. :)

  9. Jake Love
    Member
    Posted 1 year ago #

    Yup totally worked. Added to functions, deactivated plugin, reactivated, then BOOM!

    Really appreciate the assistance!

  10. Mayeenul Islam
    Member
    Posted 1 year ago #

    It works for me too.
    Thank you very much @kanuharis. :)
    Wish you all the very best.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic