What is the best way to prevent a Sitecore user from accidentally publishing the home page?


In the last year we've had a couple of incidents where a user accidentally unpublished the 'Home' item (which is the root item in our site), before publishing it to our 'Live' database, which removed it from the site.

What is the best way to prevent important content from being unpublished from a production Sitecore web site?

Your "easy" security options are to either protect the Home item itself from editing, or to restrict access to publishing options. Using standard Sitecore security, disable write access on Home for a particular user role, or disable read access on the Publishing Restrictions chunk or button in core (/sitecore/content/Applications/Content Editor/Ribbons/Chunks/Publish Restrictions/Change).

If you really don't need anyone besides admins editing the Home item, you can also Protect the item from the Configure ribbon.

If you'd like to just disable publishing restrictions on Home, that could be more complicated. Your best approach would likely be to extend the SetPublishing command. The following is untested:

  1. Extend Sitecore.Shell.Framework.Commands.SetPublishing
  2. Override Execute(CommandContext)
  3. Check context.Items[0] to see if it's your home page (GUID or Template ID check if multi-site). If so, abort. If not, call base.Execute(context). (You could also add a check for Sitecore.Context.User.IsAdministrator if so desired.)
  4. Replace item:setpublishing command in Commands.config.

Reference Sitecore.Shell.Framework.Commands.SetPublishing in your favorite decompiler as needed.