When a new blog is created in a WP Multisite instance I want to be able to set the default theme and configuration options

  • create 2 menus (main and secondary) and associate them with the 2 slots provided by the theme

  • set various theme options as defined on the theme option page

What’s the best way to go about achieving this?

  • which hook should i use – I’m going to use this: (‘WP_DEFAULT_THEME’, ‘theme-folder-name’ in wp-config.php to set the default theme – unless this prevents a needed hook from firing.

  • easiest way to programatically create menus and associate them with existing theme menu ‘slots’

3 Answers
3

The best hook I can find is wpmu_new_blog (line 1086, wp-includes/ms-functions.php, wpmu_create_blog()) – it passes 6 arguments like so;

do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );

$meta is an array of initial site options, not to be confused with the options generated by populate_options().

Programatically creating nav menus may prove to be a little tricky, as there is no ‘API’ as such – they’re a mix of posts, post meta and nav_menu terms, coupled with a few available functions such as is_nav_menu_item() and wp_setup_nav_menu_item().

My best advice would be to check out wp-admin/nav-menus.php, as this is where all the core code lies for creating menus.

Using WP_DEFAULT_THEME should be fine, and is probably the best approach too.

Leave a Reply

Your email address will not be published. Required fields are marked *