Developing formultisite
Upcoming SlideShare
Loading in...5

Developing formultisite






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Developing formultisite Developing formultisite Presentation Transcript

  • Developing for MultiSite
  • Freelance WordPress Developer Owner and Lead Developer at @martythornley A Little About Me
  • Standard WordPress Single site for you Single site for client MultiSite Series of personal sites Multiple client sites Signups open to the public What is MultiSite?
  • Single WordPress installation One “main site” Lots of “sub-sites” Network of Many Sites What is MultiSite? Single database Single set of core files Shared Plugins folder Shared Themes folder Shared Files and DB
  • Manages the network There should be only 1 ( or very few ) Installs and updates themes, plugins “Super Admin” user MultiSite Admin Can only access their site(s) Can not install, update or edit: Core, plugins, themes, users “Administrator” users
  • Admin area for each site Accessed by users of that site Settings and content for that site every-site/wp-admin/ MultiSite Admin Only the Super Admin can access Network-wide settings Edit configurations for each site Add and edit sites and users Install and activate plugins & themes /wp-admin/network/
  • Plugins shared by all sites Can be network activated Can be activated site by site /plugins/ Plugins and MultiSite always on used on all sites no activation hook no deactivation hook /mu-plugins/
  • Network Site-by-site Settings Plugin Developers Need to Think Ahead Network admin Sub-site admin Menus Super Admins Admins Users
  • BackWPup Sucuri Scanner W3 Total Cache WordPress SEO Let’s look at some Plugins
  • Standard Network Sub-Site The Plugins Screen
  • Standard Network Sub-Site Admin Menus No Sucuri Menu No BackWPup Menu
  • MultiSite - only in Network Admin BackWPup
  • BackWPup Can add user capabilities Gives Non Super Admins Access to /network/ admin!
  • BackWPup - Ideas Let each site back up their own stuff? Let Super Admins determine how often they can do that?
  • Standard WordPress Sucuri Scanner
  • MultiSite - No Network Admin Sucuri Scanner
  • MultiSite - SubSite as Super Admin Sucuri Scanner
  • MultiSite - SubSite as Admin User Sucuri Scanner
  • Sucuri Scanner MultiSite - SubSite as Admin User
  • Sucuri Scanner - Ideas Provide network admin screen so settings can be set site wide. Most settings for this plugin should be network wide. Right now, you need to go into each site and set it up again, even if you want to use the same settings.
  • W3 Total Cache Same screen - Standard, Network and SubSite
  • W3 Total Cache - Ideas Are these network settings or site settings? Most settings for this plugin should be network wide. Probably only needs a network admin screen. Each site should clear its own cache but not the entire cache.
  • WordPress SEO Standard WordPress
  • Network Admin WordPress SEO
  • SubSite - As Super Admin WordPress SEO
  • SubSite - As Admin WordPress SEO
  • Edit Files WordPress SEO
  • Edit Files WordPress SEO
  • Allow super admins option to control settings once. Still have subsite settings for Facebook, Twitter, etc. Why "Edit Files" within a subsite? Each subsite can not technically add or remove plugins so why advertise to them? Brand it, but don't advertise. WordPress SEO - Ideas
  • Navigating MultiSite
  • Knowing Where We Are is_multisite() is_main_site() is_admin() is_network_admin()
  • Knowing Who We Are is_super_admin() is_user_logged_in() $current_user = wp_get_current_user(); if( current_user_can( ‘edit_themes’ ) )
  • What Sub-Site are We In? global $blog_id; $id = get_current_blog_id(); $details = get_blog_details( $id );
  • URL Functions home_url(); site_url(); admin_url(); network_home_url(); network_site_url(); network_admin_url(); $url = get_home_url( $blog_id ); $url = get_site_url( $blog_id ); $url = get_admin_url( $blog_id );
  • Site-by-Site Settings add_option( $option , $value ); update_option( $option , $value ); get_option( $option ); add_blog_option( $blog_id , $option , $value ); update_blog_option( $blog_id , $option , $value ); get_blog_option( $blog_id , $option );
  • Network Settings add_site_option( $option , $value ); update_site_option( $option , $value ); get_site_option( $option );
  • Adding Menus add_action( ‘admin_menu’ , ‘add_my_menu’ ); add_action( ‘network_admin_menu’ , ‘add_my_menu’ ); function add_my_menu() {add_menu_page( $page_title , $menu_title , $capability , $menu_slug , $function , $icon_url , $position );add_submenu_page( $parent_slug , $page_title , $menu_title , $capability , $menu_slug , $function );} } }
  • Admin users lose a lot of capabilities. User Capabilities update_core update_plugins update_themes install_plugins install_themes delete_themes edit_plugins edit_themes edit_users create_users delete_users unfiltered_html
  • The register_setting functions work but ONLY on single site settings. Network settings need to be processed and saved. Saving Network Settings add_action( ‘admin_init’ , ‘process_and_save_my_settings’ );
  • Making Use of It All
  • Network Options Hide Stuff Add a network admin menu pageAllow super admins to save a setting update_site_option( ‘allow_sites_to_see_stuff’ , true );
  • Network Options Hide Stuff Check the site_option Only do stuff if allowed by site_option if ( get_site_option( ‘allow_sites_to_see_stuff’ ) ) { // do stuff }
  • Update Options Site-By-Site Based on Network Option Super admin chooses a setting ( like a permalink structure ) ALL sub-sites get the same setting. Lots of BAD ways to do this.
  • update_site_option( ‘awesome_site_option’ , $value ); $blogs = $wpdb->get_results( SELECT blog_id FROM {$wpdb->blogs} … a bunch of other stuff ... $value = get_site_option( ‘awesome_site_option’ ); foreach ( $blogs as $blog ) { update_blog_option( $blog['blog_id'] , ‘option_name’ , $value ); } Do NOT do this! Will cycle through EVERY blog, which could be 1,000‘s.
  • A Better Way update_site_option( ‘awesome_site_option’ , $value ); add_action( ‘init’ , ‘update_my_site_options’ ); function update_my_site_options() { $value = get_site_option( ‘awesome_site_option’ ); update_option( ‘awesome_option’ , $value ); } Only happens as each site loads. BUT... happens every page load.
  • An Even Better Way update_site_option( ‘awesome_site_option’ , $value ); update_site_option( ‘awesome_site_option_updated’ , time() ); add_action( ‘init’ , ‘update_my_site_options’ ); function update_my_site_options() { $net_time = get_site_option( ‘awesome_site_option_updated’ ); $site_time = get_option( ‘awesome_option_updated’ ); if ( $net_time > $site_time ) { $value = get_site_option( ‘awesome_site_option’ );update_option( ‘awesome_option’ , $value ); update_option( ‘awesome_option_updated’ , time() ); }} Checks times first. BUT... still happens every page load.
  • Maybe the Best Way? add_filter( ‘pre_option_posts_per_page’ , ‘network_limit_posts’ ); function network_limit_posts( $num_posts ) { if ( $network_posts = get_site_option( ‘network_post_limit’ ) ) { return $network_posts; } else { return $num_posts; } } Only looks for site_option when option is needed.
  • What settings should be network-wide? What settings should be site-by-site? Settings What should be in the network admin? What should be in the site admin? Menus What should Super Admins see? What should Admins see? Users Ask
  • Questions