How do you allow certain user roles in WP to view a Plugin I am writing? Example would be I want the Administrator and Editor roles to see my plugin, but not Subscribers or Contributors?
"See" the plugin in "Dashboard/Plugins," or activate and use the plugin? They are different ideas. You can use various plugins to limit roles and plugin activation: WordPress › WordPress Plugins and they may limit the visibilty of activated plugins.
I don't know whether there is a function for the roles specifically, but I know you can access that information using the usermeta API.
So, for example, you can use
$capabilities = get_usermeta( $user_id, "wp_capabilities" );
to get the role of the user with id, $user_id. For a subscriber, it would return...
Array
(
[subscriber] => 1
)
There may be a more elegant way of doing this, and there are role management plugins that can add more sophistication.
Apparently get_usermeta will be deprecated in WP 3.0 in favor of get_user_meta(). You can read about that in the WP codex.
I'm assuming that you need to control the visibility of the plugin in the front end UI, in which case you could get the role using the above and then make the UI elements conditional on the result.
Check out Adminimize. I believe this will accomplish what you need and more.
add your plugin with a capability argument.
if your plugin entry point is an admin page menu, you can use something like this:
add_menu_page(page_title, menu_title, capability, handle, [function], [icon_url]);
you can set the "capability" to "upload_files". that function sees that capability argument as "The minimum capability required to display and use this menu page"
for more info: