Support

Home Forums Roles and Permissions Add-ons (EE3) Custom Role permission issues with EE3

Custom Role permission issues with EE3

Posted: May 26, 2015 at 2:09 pm


Michael Budd

May 26, 2015 at 2:09 pm

I am using WordPress 4.2.2 and EE3. With the latest updates the users with custom roles (I created one called Manager for the website client) can no longer edit their events. They can create them, just not edit. It was working great before these updates. We do not want to have to make these user Espresso Master Admins as we have other uses for the Manager role pertaining to their website. I installed the plugin User Role Editor to check if there were issues were maybe the Manager role wasn’t getting the espresso_group_admin, espresso_event_admin & espresso_event_manager capabilities, but they were set correctly. I have also checked the database to make sure the user ID’s match for the event and the user and they match. All of the EE3 plugins and the core are up to date. Please help.


Josh

  • Support Staff

May 28, 2015 at 8:52 am

Hi Michael,

I’m not sure how that’s set up to allow a custom role to manage events, since it’s not a built in feature of the basic R&P plugin. When you go to the Event Espresso > User Permissions page, does it let you select other user roles besides Administrator and Event Admin?

If you can outline the steps for how the custom manager role was set up to allow managing events I can investigate.


Michael Budd

May 28, 2015 at 9:37 am

Yes I can see the custom role in User Permissions. I created the Manager role in functions file for the theme using basically the same code that creates the administrator role for the core. I also added the three capabilities: espresso_group_admin, espresso_event_admin & espresso_event_manager at that level just in case. It worked up until the latest updates of both WP and EE3.


Josh

  • Support Staff

May 28, 2015 at 9:45 am

Can you post a link here to a gist of that function so I have something to work with?


Michael Budd

May 28, 2015 at 11:26 am

here is the code

add_role( ‘manager’, ‘Manager’);
function add_theme_caps() {
$role = get_role( ‘manager’ );
$role->add_cap(‘delete_others_pages’);
$role->add_cap(‘delete_others_posts’);
$role->add_cap(‘delete_pages’);
$role->add_cap(‘delete_posts’);
$role->add_cap(‘delete_private_pages’);
$role->add_cap(‘delete_private_posts’);
$role->add_cap(‘delete_published_pages’);
$role->add_cap(‘delete_published_posts’);
$role->add_cap(‘edit_others_pages’);
$role->add_cap(‘edit_others_posts’);
$role->add_cap(‘edit_pages’);
$role->add_cap(‘edit_posts’);
$role->add_cap(‘edit_private_pages’);
$role->add_cap(‘edit_private_posts’);
$role->add_cap(‘edit_published_pages’);
$role->add_cap(‘edit_published_posts’);
$role->add_cap(‘edit_theme_options’);
$role->add_cap(‘list_users’);
$role->add_cap(‘manage_categories’);
$role->add_cap(‘manage_options’);
$role->add_cap(‘moderate_comments’);
$role->add_cap(‘publish_pages’);
$role->add_cap(‘publish_posts’);
$role->add_cap(‘read_private_pages’);
$role->add_cap(‘read_private_posts’);
$role->add_cap(‘read’);
$role->add_cap(‘remove_users’);
$role->add_cap(‘upload_files’);
$role->add_cap(‘edit_users’);
$role->add_cap(‘create_users’);
$role->add_cap(‘delete_users’);
$role->add_cap(‘unfiltered_html’);
$role->add_cap(‘espresso_group_admin’);
$role->add_cap(‘espresso_event_admin’);
$role->add_cap(‘espresso_event_manager’);
}
add_action( ‘admin_init’, ‘add_theme_caps’);


Josh

  • Support Staff

May 28, 2015 at 11:57 am

I created a new role with your code and it does not show up in any of the dropdowns under Minimum Page Permissions in Event Espresso > User Permissions.

Since that’s the case, I need to know if there are any customizations on your site that were made directly to the Roles and Permissions plugin, or any functions added to override its default functionality?


Michael Budd

May 28, 2015 at 12:04 pm

I have not made any customizations to the plugin or any overrides.


Josh

  • Support Staff

May 28, 2015 at 12:37 pm

Can you double check on something?

This is the code that’s in the roles and permissions plugin, on lines 491 – 504 of espresso-permissions.php:

$values=array(
	array('id'=>'administrator','text'=> __('Administrator','event_espresso')),
	array('id'=>'espresso_event_admin','text'=> __('Event Admin','event_espresso')),
);
//OVerride the values array if the pro version is installed
if (function_exists('espresso_manager_pro_options')) {
	$values=array(
		array('id'=>'administrator','text'=> __('Administrator','event_espresso')),
		array('id'=>'espresso_event_admin','text'=> __('Master Admin','event_espresso')),
		array('id'=>'espresso_event_manager','text'=> __('Event Manager','event_espresso')),
		array('id'=>'espresso_group_admin','text'=> __('Regional Manager','event_espresso'))
	);
}

You’ll note there isn’t a “Manager” role included in the $values array, which means a Manager option should not be included in the Event Espresso > Permissions setting dropdown selects.


Josh

  • Support Staff

May 28, 2015 at 12:41 pm

Can you compare your copy of the roles and permissions plugin with the above?


Michael Budd

May 28, 2015 at 1:30 pm

It matches. Is there a way for me to include Manager in that array?


Josh

  • Support Staff

May 28, 2015 at 1:53 pm

I would not advise to add to the array. I’m trying to find out how Manager is being included in the dropdown selects there because you earlier wrote:

Yes I can see the custom role in User Permissions.


Michael Budd

May 28, 2015 at 2:13 pm

I don’t see it in permissions, sorry, I see it on the roles page. I only see the two (Administrator & Espresso Master Admin) in permissions.


Josh

  • Support Staff

May 28, 2015 at 2:22 pm

Thanks for the clarification. Here’s what I think is happening: there’s a check to make sure that only event managers can edit their own events, and your custom role is getting caught in that check.

There’s a function that you can add to a custom snippets plugin to override how it checks for this. Here’s some example code:

if (!function_exists('espresso_is_my_event')) {
	function espresso_is_my_event($event_id){
		global $wpdb;
		if( current_user_can('delete_others_pages') || espresso_member_data('role')=='espresso_event_admin'){
			return true;
		}
	}
}

Note that the above checks for ‘delete_others_pages’ cap. That should work since you’ve given the Manager role the ‘delete_others_pages’ cap.

The support post ‘Custom Role permission issues with EE3’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso