Solution: Role Manager Issue With NextGen Gallery Wordpress Plugin

Print This Post

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.

Google Buzz
RSS for Internet Techies Hello there! If you are new here, you might want to subscribe to the RSS feed for updates.
Share it
One Response to “Solution: Role Manager Issue With NextGen Gallery Wordpress Plugin”
  1. 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.

Leave a Reply

If you have any query or question related to Blogging, Wordpress, Monetization thru Adsense, Plugins then kindly post your queries on Internet Techies Forum. We will definitely try to resolve that or some other members from our forum will do. Thanks for the consideration.

(required)

(required)