Once I wanted to hide some ribbon options for a given permission set. Basically, in SharePoint 2010 the rich text content area allows to insert web part directly on it. I wanted to security trim so, only the users that has Contributor permission level or higher would be able to perform the web part insert.
While figuring out how to do this, I came across an option that, to create a new custom control to perform the show hide ribbon options.
1) Create a custom control (inheriting from System.Web.UI.Control)
2) Override the OnPreRender method
3) Retrieve the ribbon from the current viewing page.
SPRibbon ribbon = SPRibbon.GetCurrent(Page);
4) Do the necessary permission check
SPBasePermissions.AddAndCustomizePages) && ribbon != null)
5) SPContext.Current.Web.DoesUserHavePermissions will take a permission level as a parameter and returns true if the current user has the requested permission level.
6) Ribbon.TrimById will accept the id of a ribbon command or a group, and will trim it out (hide)
7) All available ribbon commands are defined a XML file. You can find it in the “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.XML”
Once you have completed the control place it in the masterpage so all your pages get the ribbon option filtering by default.
That’s it Happy Coding!!!