One-button website publishing using WordPress-mu

I’m kinda loving on WordPress MU. One of my recent projects required building web sites that pulled from a shared database. WordPress MU allowed me to create a one-button website builder for my client. WordPress MU calls them blogs, but my client will map a unique domain to each blog, and, well, doesn’t use them as blogs at all. So I’m calling them sites here.

By filling in three fields and clicking a button, my client creates a website that

  • Associates metadata with the site that specifies filter criteria to select records from the shared database
  • Sets the permalink structure for the new site to a custom setting
  • Creates a key category for the new site, one that is used for the posts generated in a later step
  • Sets the theme
  • All the initial pages are created, including content. The “slug” is set specifically to support the URL structure we want. Page template is also set here because our design calls for a hierarchy of pages.
  • If the PageMash plugin is active (it is auto-activated for all new blogs using Plugin Commander), certain pages are hidden, and a specific order is set so that page navigation comes out looking good
  • The front page is set, because we are creating CMS sites, not blogs
  • Several hundred posts are generated out of the underlying shared non-WPMU database tables

All of this takes something like 20 seconds, at which point the admin can visit the new site as a subdomain.  The theme has been applied, navigation works correctly, it is beauty.

Here’s how it is done in code.  All you need to do is register a function for the action hook that WordPress MU runs when a new blog is created.

function mypp_initialize_blog($blog_id) {
  global $wp_rewrite;
 
  // first, switch to the new blog; we will undo this at the
  // end of the function with restore_current_blog()
  switch_to_blog($blog_id);
  // add a blog option, here a filter with a default value
  add_option($blog_id, 'campus_selection_criteria', "CampusStateID='CA'");
  // Set a custom permalink structure
  $wp_rewrite->set_permalink_structure('/%category%/%postname%');
  $wp_rewrite->flush_rules();
  if (function_exists('wp_create_category')) {
      wp_create_category('schools');
  }
 
  // switch theme - this one specifies a child theme
  switch_theme('corporate', 'tweaked-corporate');
  // Prepare options used by the pageMash plugin, auto-activated for new sites
  if(!is_array(get_option('exclude_pages')))
    $excludePagesList=array();
  else
    $excludePagesList = get_option('exclude_pages'); //if it's empty set as an empty array
  // add pages to support the basic page structure
  // NOTE: the full code is not shown, standard use of wp_insert post
  // for each page:
  $newid = wp_insert_post($postdata);
  if ($newid && !is_wp_error($newid)) {
    add_meta($newid);
    if ( IWANTOEXCLUDETHISPARTICULARPAGEFROMNAVIGATION )
      $excludePagesList[] = $newid;
    if (THISPARTICULARPAGE == 'home') {
      update_option('show_on_front', 'page');
      update_option('page_on_front', $newid);
    }
  } else {
    // error handling if insert post failed
  }
  // end for each page
  update_option('exclude_pages', $excludePagesList);
  // now generate posts for schools from the shared database
  createSchoolAsPost('', $blog_id);
  // we're done! restore our initial blog
  restore_current_blog();
} // function mypp_initialize_blog
 
add_action('wpmu_new_blog', 'mypp_initialize_blog');
This entry was posted in Development, wordpress, wordpress-mu and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted August 25, 2009 at 3:22 am | Permalink

    Hi Greg,
    Excellent post! I’m doing something similar for ‘instant’ partially populated websites using WPMU. I’ve been making edits to wpmu-functions.php to create the initial pages but was having serious bother with hierarchy and child pages.

    I really like what you’ve done and I am going to give your method a try instead.

    Fiona

  2. Posted May 24, 2010 at 2:19 am | Permalink

    Hi Greg,
    Even am working on a similar project. Am researching on how to use the e-commerce plugin so that the client can register and after registering, he can buy any particular theme, and then use it. Do you have any particular suggestions?

    Thank you.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*
  • randy moss combine results
  • tea party zombies download
  • search 78search 800 numbers
  • randy moss bio
  • dis systems
  • archos
  • randy moss yahoo stats
  • roses
  • dis quand reviendras-tu
  • xanadu bengals
  • zara phillips and the queen
  • 4pm cspancspan area 51cspan 90.1
  • freida pinto miral
  • search lsu.edu
  • mtv oddities
  • seagate
  • battleship aurora
  • greg olsen university of miami
  • mtv kings of leon
  • chad ochocinco sisterchad ochocinco twitter
  • tolerance
  • search engines cookiessearch engines definition
  • bonus
  • gears
  • hartmann
  • dis 0 0.9
  • vince young yahoo stats
  • radar
  • beers
  • search 2.0
  • homeless
  • dis boards cruise
  • search engines us
  • chad ochocinco johnson
  • bengals qb situation
  • gregg olsen books
  • zara phillips dating
  • vince young uncle rico gif
  • freida pinto green dress
  • bea luna
  • chicago bears media relations
  • framed
  • la ink 2011 season 5
  • deed
  • battleship vittorio veneto
  • di's hallmark
  • meant
  • chicago bears 61
  • vince young depression
  • cspan hosts
  • ratchet
  • new england patriots gillette stadium
  • chicago bears 08 record
  • chicago bears bleacher report
  • battleship yamato wreck
  • chicago bears training camp
  • la ink corey
  • chicago bears 1985
  • search engines watch
  • search engines questions
  • pendant
  • cspan facebook
  • connecticut renaissance faire
  • battleship egg hunt
  • serenity
  • kilo
  • bangles eternal flame mp3bengals forum
  • prairie
  • afternoon
  • greg olsen vikingsgreg olsen wife
  • springhill
  • tea party birthday
  • vince young quiz
  • bea zuberbühler
  • battleship ipad
  • betty
  • search engines of the world
  • bea 0b0 105
  • dis x
  • chicago bears tattoos
  • greg olsen vancouver
  • hp support 530
  • chicago bears expo
  • quran
  • legend
  • search engines 9
  • 60 search engines virus
  • zara phillips baby
  • freida pinto zac posen
  • connecticut education
  • battleship yamato 2010
  • search vim
  • hp support error 1005
  • pads
  • connecticut post
  • mtv executivesmtv fantasy factory
  • connecticut secretary of state
  • search 990 finder
  • rooster
  • homeowners
  • wein
  • chicago bears 96
  • vince young yahoo stats
  • worst
  • c span yesterdayc span zelaya
  • randy moss jail
  • new england patriots 98.5
  • hp support quick test pro
  • zara phillips baby
  • la ink games online
  • chicago bears pictures
  • chad ochocinco bears
  • zara phillips wedding hat
  • chad ochocinco vs skip bayless
  • chad ochocinco and cheryl burke
  • new england patriots jake locker
  • tijuana
  • hp support englandhp support forum
  • bengals arrests
  • c span video contest
  • mtv dougie
  • new england patriots 80
  • tea party zombies download
  • vince young redskins
  • cspan presidents
  • palma
  • bear gryllsbea hive dance studio
  • zara phillips kids
  • battleship galactica
  • randy moss 98 vikings
  • beagle
  • extending
  • hp support id
  • connecticut 5th district
  • vince young football camp
  • search tumblr
  • la ink cast
  • search 32
  • battleship wilmington nc
  • randy moss 07 08 highlights
  • hose
  • dis pater
  • crimper
  • la ink 03x05
  • mandolin
  • hp support 6500a plus
  • battleship bismarck wreck
  • search engines before google
  • cspan washington correspondents dinner 2011
  • reign
  • chad ochocinco quotes video
  • bea goldfishberg
  • dependency
  • spherical
  • coronado
  • randy moss vikings 2011
  • battleship lexington
  • mtv true life
  • vince young endorsementsvince young foundation
  • hiding
  • search and seizure
  • search engines usage statistics 2010
  • connecticut lottery
  • dressing
  • licensed
  • mtv overdrive
  • tea party nj
  • hp support chat
  • hp support greece
  • connecticut juvenile training schoolconnecticut kids
  • hp support error 1005
  • dis lyrics
  • bea 71 series staples
  • odessey
  • bea test
  • mtv 5 cover
  • new england patriots needs
  • la ink 04x01
  • vince young 99 yard video
  • rotation
  • search operatorssearch people
  • battleship hacked
  • bea verdi
  • zara phillips fascinator