This is how I would do it in a plugin:
-
Install WordPress as a multisite with subdomains.
-
Use the main site for the theme shop, install Easy Digital Downloads or another shop plugin. Create a product for each theme, make sure the slug matches the theme directory name.
-
Upload your themes.
-
Write an empty function
wp_install_defaults()
to prevent the default content in new sites. -
Add the test data from wptest.io to your plugin. They are better than the WordPress theme test data.
-
Hook into
wpmu_new_blog
and check if the site slug matches an existing theme. Then:- Install the test data.
- Set the option
blog_public
toFALSE
to prevent search engines from indexing your test data. - Create or update a site option with an array containing the site ID, the theme slug and the visible theme name that you get from the
style.css
. - Activate the matching theme.
- Create a sticky post from the content of the
style.css
and add a Buy now! link that goes to the product on the main site with a matching slug.
-
Force the admin bar to be visible on all sites, even when the user is not logged in. Add a menu that is fed from the site option and build a list of all theme preview sites. You can also use a widget for that.
-
Filter the product page on the main site and add a link to the demo site with the information from the site option.
There are probably many details that I missed here, but as a basic concept, this should work fine.