multisite - · pdf filemultisite is • “multiple sites using one installation”...

25
1

Upload: vuongkien

Post on 15-Feb-2018

223 views

Category:

Documents


2 download

TRANSCRIPT

1

Making Multisite Work for YouBEN BYRNE CORNERSHOP CREATIVE

2

What is Multisite?

3

Multisite is…

• “Multiple sites using one installation”

• Shared codebase

• Shared database — but mostly separate tables

• Used by wpengine, wordpress.com, wordcamp.org, and many others

4

Good for…

• A network of blogs (or personal fundraising sites!)

• An association with local chapters

• Rapid-launch campaign sites

5

Bad for…• When sites need to be on multiple hosts

• When sites need to have separate databases*

• When each site will need its own IP address.

• Site administrators will need to install their own themes or plugins.

• Temporary setups

• Limited hosts

6

Cons• Separating out multisite sites into individual sites

• Single point of failure

• Confusing and complicated

• Code changes affect all sites…

7

Enabling Multisite• define( 'WP_ALLOW_MULTISITE', true );

• http://codex.wordpress.org/Create_A_Network

• http://premium.wpmudev.org/manuals/wpmu-manual-2/creating-a-network-to-enable-wordpress-multisite/

8

URL Handling1. Subdomain

• site1.domain.org

• site2.domain.org

2. Subdirectory

• domain.org/site1

9

3. Separate Domains

• domain.org

• otherdomain.org

• domain.org/site2

Not so fast…• Sub-directory approach won’t be offered by

WordPress if your site is more than 30 days old — permalink conflicts

• Sub-domain won’t work if the URL is localhost, is an IP address, has a port, or if WP is in a subdirectory

• Unique domains won’t work without a plugin and some code

• https://github.com/humanmade/Mercator

10

Open or closed?• Public aka Open: anyone can create a blog/site

• Good for schools, social fundraisers, etc.

• But can be scary…

• Private aka Closed: only administrator can add new

• Much safer, but more limited

11

define( ‘DISALLOW_FILE_EDIT’, true );

12

Network admin role

• /wp-admin/network

• manage_networkmanage_sitesmanage_network_usersmanage_network_pluginsmanage_network_themesmanage_network_options

• User Role Editor is your friend

13

Shared users

• Users can be assigned to one site or many

• Single login gives access to all sites they’re assigned to

• But that means user profiles are consistent across all sites*

14

Shared Themes & Plugins• Restrict theme availability to certain sites

• Pro-tip: use child themes!

• Plugins available to all

• Activate per-site or “network activate”

• mu-plugins directory: can’t be deactivated but don’t work like regular plugins

15

Plugin Stuff• Not all plugins are multisite friendly

• Others might have network-specific settings

• Plenty of plugins specifically for multisite

• Individual Multisite Author

• One-Click Child Theme

16

Nerdy• You’ll find the the .htaccess, wp-config.php

different

• wp-content/uploads is different: sites dir, every site gets an id number

• Be thoughtful about (s)FTP access

• mySQL tables aplenty

• Hosting is critical — many WP-optimized hosts don’t support multisite

17

Database Structure• wp_blogs

wp_blog_versionswp_registration_logwp_signupswp_sitewp_sitemeta

18

• wp_userswp_usermeta

• wp_optionswp_postswp_postmeta wp_commentswp_commentmetawp_termswp_termmeta wp_term_taxonomywp_term_relationships

• wp_2_optionswp_2_postswp_2_postmetawp_2_commentswp_2_commentmetawp_2_termswp_2_termmetawp_2_term_taxonomywp_2_term_relationships

“Site”

19

A blog is a site and a site is a network

20

Ramifications• Global objects:

• $current_site

• $current_blog

• get_current_site() != get_blog_details()

• get_site_option() vs. get_option()

• Counterintuitive: more like get_network_option()

• wp_get_sites();

• unless wp_is_large_network() is true

21

switch_to_blog()

22

switch_to_blog()• Changes DB prefix

• Re-initializes user roles

• Doesn’t verify $site_id

• Doesn’t change translation or permalink settings

• restore_current_blog() backs up just 1 step

• … use ms_is_switched() to check state

23

Other handy stuff• is_network_admin();

• is_multisite();

• get_blog_list(); => wp_get_sites();

• update_blog_option( $blog_id, $key, $value );

• is_archived( $blog_id );

• is_user_member_of_blog( $user_id, $blog_id ); compare with get_blogs_of_user( $user_id );

24

Thank You

25