Your SlideShare is downloading. ×
0
Developing for MultiSite
Freelance WordPress Developer
Owner and Lead Developer at
PhotographyBlogSites.com
martythornley.com @martythornley
A Litt...
Standard WordPress
Single site for you
Single site for client
MultiSite
Series of personal sites
Multiple client sites
Sig...
Single WordPress installation
One “main site”
Lots of “sub-sites”
Network of Many Sites
What is
MultiSite?
Single database...
Manages the network
There should be only 1 ( or very few )
Installs and updates themes, plugins
“Super Admin” user
MultiSi...
Admin area for each site
Accessed by users of that site
Settings and content for that site
every-site/wp-admin/
MultiSite
...
Plugins shared by all sites
Can be network activated
Can be activated site by site
/plugins/
Plugins
and
MultiSite always ...
Network
Site-by-site
Settings
Plugin
Developers
Need to
Think
Ahead Network admin
Sub-site admin
Menus
Super Admins
Admins...
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...
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.
...
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 File...
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...
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...
WP
Constants
WP_CONTENT_DIR
WP_CONTENT_URL
WP_PLUGIN_DIR
WP_PLUGIN_URL
WPMU_PLUGIN_DIR
WPMU_PLUGIN_URL
Site-by-Site Settings
add_option( $option , $value );
update_option( $option , $value );
get_option( $option );
add_blog_o...
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_...
Admin users lose a lot of capabilities.
User Capabilities
update_core
update_plugins
update_themes
install_plugins
install...
The register_setting functions work but ONLY on
single site settings.
Network settings need to be processed and saved.
Sav...
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_si...
Network Options Hide Stuff
Check the site_option Only do stuff if allowed by
site_option
if ( get_site_option( ‘allow_site...
Update Options Site-By-Site
Based on Network Option
Super admin chooses a setting
( like a permalink structure )
ALL sub-s...
update_site_option( ‘awesome_site_option’ , $value );
$blogs = $wpdb->get_results( SELECT blog_id FROM {$wpdb->blogs} … a ...
A Better Way
update_site_option( ‘awesome_site_option’ , $value );
add_action( ‘init’ , ‘update_my_site_options’ );
functi...
An Even Better Way
update_site_option( ‘awesome_site_option’ , $value );
update_site_option( ‘awesome_site_option_updated’...
Maybe the Best Way?
add_filter( ‘pre_option_posts_per_page’ , ‘network_limit_posts’ );
function network_limit_posts( $num_...
What settings should be network-wide?
What settings should be site-by-site?
Settings
What should be in the network admin?
...
Questions
theuproots.com
PhotographyBlogSites.com martythornley.com
slideshare.net/MartyThornley/developing-formultisite
Upcoming SlideShare
Loading in...5
×

Developing formultisite

1,694

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,694
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Developing formultisite"

  1. 1. Developing for MultiSite
  2. 2. Freelance WordPress Developer Owner and Lead Developer at PhotographyBlogSites.com martythornley.com @martythornley A Little About Me
  3. 3. 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?
  4. 4. 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
  5. 5. 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
  6. 6. 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/
  7. 7. 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/
  8. 8. Network Site-by-site Settings Plugin Developers Need to Think Ahead Network admin Sub-site admin Menus Super Admins Admins Users
  9. 9. BackWPup Sucuri Scanner W3 Total Cache WordPress SEO Let’s look at some Plugins
  10. 10. Standard Network Sub-Site The Plugins Screen
  11. 11. Standard Network Sub-Site Admin Menus No Sucuri Menu No BackWPup Menu
  12. 12. MultiSite - only in Network Admin BackWPup
  13. 13. BackWPup Can add user capabilities Gives Non Super Admins Access to /network/ admin!
  14. 14. BackWPup - Ideas Let each site back up their own stuff? Let Super Admins determine how often they can do that?
  15. 15. Standard WordPress Sucuri Scanner
  16. 16. MultiSite - No Network Admin Sucuri Scanner
  17. 17. MultiSite - SubSite as Super Admin Sucuri Scanner
  18. 18. MultiSite - SubSite as Admin User Sucuri Scanner
  19. 19. Sucuri Scanner MultiSite - SubSite as Admin User
  20. 20. 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.
  21. 21. W3 Total Cache Same screen - Standard, Network and SubSite
  22. 22. 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.
  23. 23. WordPress SEO Standard WordPress
  24. 24. Network Admin WordPress SEO
  25. 25. SubSite - As Super Admin WordPress SEO
  26. 26. SubSite - As Admin WordPress SEO
  27. 27. Edit Files WordPress SEO
  28. 28. Edit Files WordPress SEO
  29. 29. 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
  30. 30. Navigating MultiSite
  31. 31. Knowing Where We Are is_multisite() is_main_site() is_admin() is_network_admin()
  32. 32. Knowing Who We Are is_super_admin() is_user_logged_in() $current_user = wp_get_current_user(); if( current_user_can( ‘edit_themes’ ) )
  33. 33. What Sub-Site are We In? global $blog_id; $id = get_current_blog_id(); $details = get_blog_details( $id );
  34. 34. 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 );
  35. 35. WP Constants WP_CONTENT_DIR WP_CONTENT_URL WP_PLUGIN_DIR WP_PLUGIN_URL WPMU_PLUGIN_DIR WPMU_PLUGIN_URL
  36. 36. 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 );
  37. 37. Network Settings add_site_option( $option , $value ); update_site_option( $option , $value ); get_site_option( $option );
  38. 38. 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 );} } }
  39. 39. 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
  40. 40. 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’ );
  41. 41. Making Use of It All
  42. 42. 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 );
  43. 43. 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 }
  44. 44. 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.
  45. 45. 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.
  46. 46. 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.
  47. 47. 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.
  48. 48. 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.
  49. 49. 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
  50. 50. Questions
  51. 51. theuproots.com PhotographyBlogSites.com martythornley.com slideshare.net/MartyThornley/developing-formultisite
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×