developing formultisite

51
Developing for MultiSite

Upload: marty-thornley

Post on 08-May-2015

1.672 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Developing formultisite

Developing for MultiSite

Page 2: Developing formultisite

Freelance WordPress Developer

Owner and Lead Developer at

PhotographyBlogSites.com

martythornley.com @martythornley

A Little About Me

Page 3: Developing formultisite

Standard WordPress

Single site for youSingle site for client

MultiSite

Series of personal sitesMultiple client sites

Signups open to the public

What is MultiSite?

Page 4: Developing formultisite

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

Page 5: Developing formultisite

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

Page 6: Developing formultisite

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/

Page 7: Developing formultisite

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/

Page 8: Developing formultisite

Network Site-by-site

Settings

Plugin Developer

sNeed to

Think Ahead Network admin

Sub-site admin

Menus

Super Admins Admins

Users

Page 9: Developing formultisite

BackWPup

Sucuri Scanner

W3 Total Cache

WordPress SEO

Let’s look at some Plugins

Page 10: Developing formultisite

Standard Network Sub-Site

The Plugins Screen

Page 11: Developing formultisite

Standard Network Sub-Site

Admin Menus

No Sucuri Menu

No BackWPup Menu

Page 12: Developing formultisite

MultiSite - only in Network Admin

BackWPup

Page 13: Developing formultisite

BackWPupCan add user capabilities

Gives Non Super AdminsAccess to /network/ admin!

Page 14: Developing formultisite

BackWPup - Ideas

Let each site back up their own stuff?

Let Super Admins determine how often they can do that?

Page 15: Developing formultisite

Standard WordPress

Sucuri Scanner

Page 16: Developing formultisite

MultiSite - No Network Admin

Sucuri Scanner

Page 17: Developing formultisite

MultiSite - SubSite as Super Admin

Sucuri Scanner

Page 18: Developing formultisite

MultiSite - SubSite as Admin User

Sucuri Scanner

Page 19: Developing formultisite

Sucuri ScannerMultiSite - SubSite as Admin User

Page 20: Developing formultisite

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.

Page 21: Developing formultisite

W3 Total CacheSame screen - Standard, Network and SubSite

Page 22: Developing formultisite

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.

Page 23: Developing formultisite

WordPress SEOStandard WordPress

Page 24: Developing formultisite

Network Admin

WordPress SEO

Page 25: Developing formultisite

SubSite - As Super Admin

WordPress SEO

Page 26: Developing formultisite

SubSite - As Admin

WordPress SEO

Page 27: Developing formultisite

Edit Files

WordPress SEO

Page 28: Developing formultisite

Edit Files

WordPress SEO

Page 29: Developing formultisite

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

Page 30: Developing formultisite

Navigating MultiSite

Page 31: Developing formultisite

Knowing Where We Are

is_multisite()

is_main_site()

is_admin()

is_network_admin()

Page 32: Developing formultisite

Knowing Who

We Are

is_super_admin()

is_user_logged_in()

$current_user = wp_get_current_user();

if( current_user_can( ‘edit_themes’ ) )

Page 33: Developing formultisite

What Sub-Site

are We In?

global $blog_id;

$id = get_current_blog_id();

$details = get_blog_details( $id );

Page 34: Developing formultisite

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 );

Page 35: Developing formultisite

WP Constants

WP_CONTENT_DIR

WP_CONTENT_URL

WP_PLUGIN_DIR

WP_PLUGIN_URL

WPMU_PLUGIN_DIR

WPMU_PLUGIN_URL

Page 36: Developing formultisite

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 );

Page 37: Developing formultisite

Network Settings

add_site_option( $option , $value );

update_site_option( $option , $value );

get_site_option( $option );

Page 38: Developing formultisite

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 );}

Page 40: Developing formultisite

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’ );

Page 41: Developing formultisite

Making Use of It All

Page 42: Developing formultisite

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 );

Page 43: Developing formultisite

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

}

Page 44: Developing formultisite

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.

Page 45: Developing formultisite

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.

Page 46: Developing formultisite

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.

Page 47: Developing formultisite

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.

Page 48: Developing formultisite

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.

Page 49: Developing formultisite

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

Page 50: Developing formultisite

Questions

Page 51: Developing formultisite

theuproots.com

PhotographyBlogSites.com martythornley.com

slideshare.net/MartyThornley/developing-formultisite