developing formultisite
TRANSCRIPT
Developing for MultiSite
Freelance WordPress Developer
Owner and Lead Developer at
PhotographyBlogSites.com
martythornley.com @martythornley
A Little About Me
Standard WordPress
Single site for youSingle site for client
MultiSite
Series of personal sitesMultiple 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 databaseSingle set of core filesShared Plugins folderShared Themes folder
Shared Files and DB
Manages the networkThere should be only 1 ( or very
few )Installs and updates themes,
plugins
“Super Admin” user
MultiSiteAdmin
Can only access their site(s)Can not install, update or edit:Core, plugins, themes, users
“Administrator” users
Admin area for each siteAccessed by users of that site
Settings and content for that site
every-site/wp-admin/
MultiSiteAdmin Only the Super Admin can access
Network-wide settingsEdit configurations for each site
Add and edit sites and usersInstall and activate plugins &
themes
/wp-admin/network/
Plugins shared by all sitesCan be network activated
Can be activated site by site
/plugins/
Plugins and
MultiSitealways on
used on all sitesno activation hook
no deactivation hook
/mu-plugins/
Network Site-by-site
Settings
Plugin Developer
sNeed 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
BackWPupCan add user capabilities
Gives Non Super AdminsAccess 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 ScannerMultiSite - 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 CacheSame 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 SEOStandard 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 );
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_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_coreupdate_pluginsupdate_themesinstall_pluginsinstall_themesdelete_themes
edit_pluginsedit_themesedit_users
create_usersdelete_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-SiteBased 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
theuproots.com
PhotographyBlogSites.com martythornley.com
slideshare.net/MartyThornley/developing-formultisite