Slide 1

Slide 1 text

The Secret to Mastering WordPress Multi-site

Slide 2

Slide 2 text

Hello! Juliette Reinders Folmer @jrf_nl @jrfnl @jrf

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

UI for multi-network setup: https://wordpress.org/plugins/wp-multi-network/

Slide 6

Slide 6 text

How Does It Work ? xhowardlee

Slide 7

Slide 7 text

File System 1 WP installation 1 plugins folder 1 themes folder 1 must-use plugins folder 1 translations folder 1 uploads folder 1 WP installation 1 plugins folder 1 themes folder 1 must-use plugins folder 1 translations folder 1 uploads folder with #n subfolders in a sites subdirectory

Slide 8

Slide 8 text

Database 1 database no network tables 1 options table 1 set of user tables 1 set of content tables 1 database 1 set of network tables #n sets of options tables 1 set of user tables #n sets of content tables

Slide 9

Slide 9 text

Database wp_comments wp_commentmeta wp_links wp_options wp_posts wp_postmeta wp_terms wp_termmeta wp_term_relationships wp_term_taxonomy wp_users wp_usermeta wp_users wp_usermeta wp_comments wp_commentmeta wp_links wp_options wp_posts wp_postmeta wp_terms wp_termmeta wp_term_relationships wp_term_taxonomy wp_2_comments wp_2_commentmeta wp_2_links wp_2_options wp_2_posts wp_2_postmeta wp_2_terms wp_2_termmeta wp_2_term_relationships wp_2_term_taxonomy wp_3_comments wp_3_commentmeta wp_3_links wp_3_options wp_3_posts wp_3_postmeta wp_3_terms wp_3_termmeta wp_3_term_relationships wp_3_term_taxonomy wp_blogs wp_blog_versions wp_registration_log wp_signups wp_site wp_sitemeta

Slide 10

Slide 10 text

Users 1 set of users 1 set of user meta per user 1 set of user capabilities Highest role: admin 1 set of users 1 set of user meta per user 1 set of user capabilities per sub-site Highest role: super-admin

Slide 11

Slide 11 text

Plugin Actions ▪ Activate ▪ Deactivate ▪ Uninstall ▪ Network Activate ▪ Activate ▪ Network Deactivate ▪ Deactivate ▪ Uninstall

Slide 12

Slide 12 text

What is needed for a plugin or theme to be compatible with WordPress multi-site ?

Slide 13

Slide 13 text

NOTHING (for most plugins and nearly all themes)

Slide 14

Slide 14 text

Fine Tuning for the Other 20% djouby

Slide 15

Slide 15 text

 Database  Autoloaded Options  Plugins  Theme  Rewrite Rules  $GLOBALS       Understanding Context

Slide 16

Slide 16 text

 Database  Autoloaded Options  Plugins  Theme  Rewrite Rules  $GLOBALS             Understanding Context

Slide 17

Slide 17 text

 Database  Autoloaded Options  Plugins  Theme  Rewrite Rules  $GLOBALS             Understanding Context

Slide 18

Slide 18 text

 Database  Autoloaded Options  Plugins  Theme  Rewrite Rules  $GLOBALS             Understanding Context

Slide 19

Slide 19 text

Switching Between Blogs switch_to_blog() restore_current_blog() ms_is_switched()

Slide 20

Slide 20 text

 Database  Autoloaded Options  Plugins  Theme  Rewrite Rules  $GLOBALS                /  / Understanding Context

Slide 21

Slide 21 text

Uh oh....

Slide 22

Slide 22 text

Terminology Network of Networks •get_network_by_path() Network • get_site_by_path() • WP_Network • $current_site • is_main_network() • get_current_site() • is_network_admin() • is_super_admin() Site • WP_Site • $current_blog • is_main_site() • get_blog_details() • get_site() • get_sites() • is_admin() • current_user_can()

Slide 23

Slide 23 text

Confused yet ?

Slide 24

Slide 24 text

“ People will write code

Slide 25

Slide 25 text

Become a Better Developer

Slide 26

Slide 26 text

Network Plugins

Slide 27

Slide 27 text

Network Plugins

Slide 28

Slide 28 text

Non-Network Plugins

Slide 29

Slide 29 text

Update, don't Activate class Prefix_My_Class { const VERSION = '1.0'; function __construct() { $option = get_option( 'prefix_option' ); if ( false === $option || ! isset( $option['version'] ) || version_compare( $option['version'], self::VERSION, '<') ) { $this->upgrade( $option ); } } }

Slide 30

Slide 30 text

Update, don't Activate class Prefix_My_Class { const VERSION = '1.0'; protected function upgrade( $option ) { // Add DB tables // Add action to flush rewrite rules at a later hook // Add cron jobs // etc $option['version'] = self::VERSION; update_option( 'prefix_option', $option ) } }

Slide 31

Slide 31 text

Deactivation & Uninstall Routines jackiebabe

Slide 32

Slide 32 text

Dealing with User Data  Differentiate between global and local data  "Blog" specific meta keys  is_super_admin() greyerbaby

Slide 33

Slide 33 text

Rewrite Rules Jeff Djevdet flush_rewrite_rules()

Slide 34

Slide 34 text

Scheduling Cron Events  Differentiate between global and local data  is_main_site() irkengirdib

Slide 35

Slide 35 text

is_multisite()

Slide 36

Slide 36 text

is_network_admin() Action: 'network_admin_menu' wp_is_large_network () current_user_can _for_blog() self_admin_url() get_current_blog_id () Other Useful Snippets

Slide 37

Slide 37 text

Thanks! Any questions ? Slides: https://speakerdeck.com/jrf @jrf_nl @jrfnl @jrf