Solution: Role Manager Issue With NextGen Gallery WordPress Plugin

When I was trying to use Role Manager WordPress plugin with NextGen gallery, I got an issue that when I try to change the roles for NextGen Gallery thru Gallery –> Roles settings on wp-admin panel, say from Administrator to Contributor, all the users of the blog including subscribers get the access to the complete NextGen Gallery menu. This is only when you have Role Manager Plugin activated.

But what if you want to use both the plugins on the site due to some other requirement. Below is a simple hack to resolve this.

Deactivate the NextGen Gallery plugin. Go to wp-content->plugins->nextgen-gallery->admin->roles.php (You can also use the wp-admin plugin editor for this)

Find the below code (may be some variation from version to version of NextGen gallery):-

function ngg_get_sorted_roles() {
	// This function returns all roles, sorted by user level (lowest to highest)
	global $wp_roles;
	$roles = $wp_roles->role_objects;
	$sorted = array();
	
	if( class_exists('RoleManager') ) {
		foreach( $roles as $role_key => $role_name ) {
			$role = get_role($role_key);
			if( empty($role) ) continue;
			$role_user_level = array_reduce(array_keys($role->capabilities), array('WP_User', 'level_reduction'), 0);
			$sorted[$role_user_level] = $role;
		}
		$sorted = array_values($sorted); 
	} else {
		$role_order = array("subscriber", "contributor", "author", "editor", "administrator");
		foreach($role_order as $role_key) {
			$sorted[$role_key] = get_role($role_key);
		}
	}
	return $sorted;
}

Replace the above code with the below code snippet (I have commented some lines specific to Role Manager):-

function ngg_get_sorted_roles() {
	// This function returns all roles, sorted by user level (lowest to highest)
	global $wp_roles;
	$roles = $wp_roles->role_objects;
	$sorted = array();
	
	if( class_exists('RoleManager1') ) {
/*		foreach( $roles as $role_key => $role_name ) {
			$role = get_role($role_key);
			if( empty($role) ) continue;
			$role_user_level = array_reduce(array_keys($role->capabilities), array('WP_User', 'level_reduction'), 0);
			$sorted[$role_user_level] = $role;
		}
		$sorted = array_values($sorted); */
	} else {
		$role_order = array("subscriber", "contributor", "author", "editor", "administrator");
		foreach($role_order as $role_key) {
			$sorted[$role_key] = get_role($role_key);
		}
	}
	return $sorted;
}

Activate NextGen Gallery and all done. Now you can properly update the capabilities from the ‘Roles’ settings panel of NextGen Gallery and it works as expected.

  • http://www.serradinho.com George Serradinho

    Thanks for sharing this although I think you should maybe contact the plugin developer and let them know of this issue. Then they can update the plugin and all will be ok. I currently only use Role Manage of the two, I needed it for my guest authors.

  • http://webcoded.net Buddi

    I m using (V1.5.3 ) it and works fine for me. Guess they have updated it.

Shares