Hide Site Definitions via a Feature

Creating site definitions is a good way to deploy customisations for different projects or clients. However if they all run on the same farm, how do you stop users from creating sites based on the wrong project?

By default if you create a site definition, it will appear in the Site Actions -> Create Site sites list (publishing feature), unless you have limited the site templates available through site settings. 

But what if you dont want to allow the site owners access to provide these templates to their users? You can restrict it at the Site Definition level.

  1. Create an empty site feature called something like ‘Project.EnableSiteTemplates’ (set hidden=”TRUE” if you want to control the feature activation via Site Def or STSADM only – not through Site Settings) 
  2. In the webtemp*.xml for your site definition, in each <Configuration> template node set the VisibilityFeatureDependency property to the GUID of your newly created feature so that the site only appears for users to select in Create Site box when that feature has been activated. eg. VisibilityFeatureDependency=”7C30466D-62A2-43eb-99EB-7650E5D14B77″
  3. In your onet.xml file of the project Site Definition, enable the ‘Project.EnableSiteTemplates’ feature in the <SiteFeatures> section, so when your new site collection is created it also enables your site templates for this project. 
This is the same principle behind hiding sites based on publishing infrastructure until the prerequisite features for Publishing have been enabled.
Note: The Site Owner will actually see and be able to select the custom site templates on the ‘Page Layout and Site Template Settings’ page even when the feature is not activate on the site collection. However nobody can actually see the site on the ‘Create Site’ page until the feature is activated.