SlideShare a Scribd company logo
1 of 29
The Wonders of WordPress
Multisite
Patrick Johanneson
bona fides
➢ Web Coordinator at Brandon University
➢ Assisted with BU's first webserver, 1996(ish)
➢ Working with WordPress since v. 1.5 or so
➢ Doing dev work in WordPress Multisite since v.
3.0
What is Multisite?
● Multisite allows multiple virtual sites to be run
from a single WP installation (Codex Glossary)
● Prior to version 3.0, WordPress MultiUser was
required for this functionality
● With WordPress version 3.0, Multisite
functionality was rolled into WP's core
Why does BU use Multisite?
● BU has several faculties with many
departments within them
● Each faculty and department has a website
● Each website has its own coterie of editors
● With WP Multisite, this is easy to set up and
maintain
How does one set up Multisite?
● See the WordPress Codex "Create A Network"
page for a full explanation
● You need to edit your wp-config.php file...
● ...set up your Network in /wp-admin/...
● ...and then edit your wp-config.php and
.htaccess files again.
● Don't panic!
wp-config.php
define( 'WP_ALLOW_MULTISITE', true );
/* That's all, stop editing! Happy blogging. */
Tools > Network Setup
Network Setup
Network Setup complete
wp-config.php
define( 'WP_ALLOW_MULTISITE', true );
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'example' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
/* That's all, stop editing! Happy blogging. */
Users in Multisite
● Each site in a Multisite installation can have its
own unique users, but all users are added to a
site-wide "pool" of users
● A user who is an Administrator on Site A can
be a Contributor on Site B, a Subscriber on
sites C and D, and have no privileges at all on
Site E
● Also, Multisite adds a new administrative level:
Super Admin, who can make network-wide
changes
Network Users list
Add New User -- "classic" vs. Multisite
Adding Sites
● The Super Admin(s) can add sites
Connecting Sites
● News and Events – Centralized or distributed?
● Parents and grandparents
– Breadcrumbs
– Contact information
News (Centralized)
● BU's news lives in the /news/ site, and is
maintained by a handful of people
● The news articles are categorized by site --
eg, news for the English homepage is in the
English category, news for Physics in the
Physics category, etc.
● Custom code fetches & displays the news for
each site in the BU network
Music Homepage
add_action( 'bu_news_region', 'bu_get_news' );
function bu_get_news() {
// Current site
$site_name = get_bloginfo( 'name' );
if( 'News' == $site_name ) return;
// no point doing anything *in* the News site
$cat_id = bu_get_category_from_site( $site_name );
$url = get_bloginfo( 'wpurl' );
// Some site details
$news_site = get_blog_details( 'News' );
$original_site = get_current_blog_id();
// so we can come back later
// switch to the news site
switch_to_blog( $news_details->blog_id );
// get the posts with category matching the site name
$args = array( 'category' => $cat_id, 'numberposts' => 4 );
$articles = get_posts( $args );
if( is_array( $articles ) && ! empty( $articles ) ) {
$article_list = "<h2>$site_name News</h2>";
$article_list .= '<dl>';
foreach ( $articles as $post ) {
setup_postdata( $post );
$article_list .= '
<dt>
<a href="' . get_permalink() . '">' . get_the_title() . '</a>
</dt>
<dd>
<span class="news-date">' . get_the_date() . '</span>
</dd>';
} // end foreach
$article_list .= '</dl>';
} // endif
switch_to_blog( $original_site );
if( strlen( $article_list ) > 0 ) {
echo( $article_list );
}
} // end of function
Events (Distributed (well, soon))
● BU is moving to tri.be's The Event Calendar,
which will allow site editors to maintain their
own events
● Events may be suggested for promotion by
site editors, so that they might appear on the
BU Home Page Event listing
● Promoted events must be authorized by a site
administrator
events.php Assumptions
The code that follows is the core of the event promotion
system. Several checks have been trimmed for brevity:
● Checking to ensure we're not in the root site (if we
are, bail out with a return; )
● The following must all be true:
– tribe_is_event()
– event is in the appropriate category in the sub-site
– there isn't already a promoted event for the given $id
add_action( 'save_post', 'bu_event_promote' );
function bu_event_promote( $id ){
if( ! isset($id) || ! is_numeric($id) ) { return(false); }
$from_site = get_bloginfo('name');
$from_site_id = get_current_blog_id();
// setup the required variables BEFORE we switch to the home site
$event_title = get_the_title( $id );
$event_url = get_permalink( $id );
$event_start = tribe_get_start_date( $id, false, 'Y-M-d' );
$event_end = tribe_get_end_date( $id, false, 'Y-M-d' );
switch_to_blog( BLOG_ID_CURRENT_SITE );
$args = array(
'post_status' => 'draft',
'post_content' => "This is a promoted post, from the '$from_site'
site.nPlease do not edit this post; just publish it if appropriate, or ignore
it.",
'post_title' => $event_title,
'EventStartDate' => $event_start,
'EventEndDate' => $event_end,
);
$new_event_id = tribe_create_event( $args );
// Meta info (redirection)
$meta = array(
'_pprredirect_active' => 1,
'_pprredirect_type' => 301,
'_pprredirect_rewritelink' => 1,
'_pprredirect_url' => $event_url,
);
$meta_unique = true;
foreach($meta as $key => $value){
add_post_meta($new_event_id, $key, $value, $meta_unique);
}
switch_to_blog( $from_site_id );
// back from whence you came
// once all that's done, add the _bu_promoted_event meta to the original $event
// using the new event's $post->ID so it can be removed later, if necessary
add_post_meta($id, '_bu_promoted_event', $new_event_id, true);
// All done
}
Site Parents & Breadcrumbs
● WordPress Multisite does not support nested
sub-sites (ie, /arts cannot contain /arts/english)
● /arts and /english are two separate sites
● With a bit of plugin magic, though, we can
set /arts as the parent site of /english, so that
breadcrumbs look like this:
Site Parent
● Arts is interposed in the breadcrumb via an in-
house plugin named Site Parent. Site Parent
sets an option in the current site with the ID of
the selected "Parent".
More Site Parent uses
● The Site Parent option is also used by the in-house
Contact Info plugin
● If the current site has no contact information set, the
plugin will look to the site's Site Parent, using
switch_to_blog()
● If there's no contact info there, the plugin ascends
level after level, until it gets to the root site
● If the root site's contact info is empty, the plugin
displays a default string
References
● Codex.WordPress.org
– Glossary
– Before You Create a Network
– Create a Network
– Function Reference (x1000)
– Plugin API pages (filters, hooks, etc)
● WordPress.org/support
● Tri.be support pages & forums
● WordPress.StackExchange.com
You've got questions,
I've got answers.
...hopefully.
fin.

More Related Content

Similar to WordPress Multisite

Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 minsChandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 minswpnepal
 
Worcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20minsWorcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20minsChandra Prakash Thapa
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
Plugging into plugins
Plugging into pluginsPlugging into plugins
Plugging into pluginsJosh Harrison
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin developmentMostafa Soufi
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
Max Voloshin - "Organization of frontend development for products with micros...
Max Voloshin - "Organization of frontend development for products with micros...Max Voloshin - "Organization of frontend development for products with micros...
Max Voloshin - "Organization of frontend development for products with micros...IT Event
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Yevhen Kotelnytskyi
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentNuvole
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 
Developing formultisite
Developing formultisiteDeveloping formultisite
Developing formultisiteMarty Thornley
 
Magento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowMagento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowVrann Tulika
 
Creating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressCreating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressHristo Chakarov
 
Extending CMS Made Simple
Extending CMS Made SimpleExtending CMS Made Simple
Extending CMS Made Simplecmsmssjg
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2Paras Mendiratta
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Acquia BLT for the Win, or How to speed up the project setup, development an...
Acquia BLT for the Win, or  How to speed up the project setup, development an...Acquia BLT for the Win, or  How to speed up the project setup, development an...
Acquia BLT for the Win, or How to speed up the project setup, development an...DrupalCamp Kyiv
 
Drupal8 migrate
Drupal8 migrateDrupal8 migrate
Drupal8 migrateJohn Doyle
 

Similar to WordPress Multisite (20)

Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 minsChandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
 
Worcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20minsWorcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20mins
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Plugging into plugins
Plugging into pluginsPlugging into plugins
Plugging into plugins
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Max Voloshin - "Organization of frontend development for products with micros...
Max Voloshin - "Organization of frontend development for products with micros...Max Voloshin - "Organization of frontend development for products with micros...
Max Voloshin - "Organization of frontend development for products with micros...
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?
 
Moving to Drupal
Moving to DrupalMoving to Drupal
Moving to Drupal
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
Developing formultisite
Developing formultisiteDeveloping formultisite
Developing formultisite
 
Magento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowMagento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request Flow
 
Creating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressCreating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPress
 
Extending CMS Made Simple
Extending CMS Made SimpleExtending CMS Made Simple
Extending CMS Made Simple
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Acquia BLT for the Win, or How to speed up the project setup, development an...
Acquia BLT for the Win, or  How to speed up the project setup, development an...Acquia BLT for the Win, or  How to speed up the project setup, development an...
Acquia BLT for the Win, or How to speed up the project setup, development an...
 
Drupal8 migrate
Drupal8 migrateDrupal8 migrate
Drupal8 migrate
 

Recently uploaded

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

WordPress Multisite

  • 1. The Wonders of WordPress Multisite
  • 2. Patrick Johanneson bona fides ➢ Web Coordinator at Brandon University ➢ Assisted with BU's first webserver, 1996(ish) ➢ Working with WordPress since v. 1.5 or so ➢ Doing dev work in WordPress Multisite since v. 3.0
  • 3. What is Multisite? ● Multisite allows multiple virtual sites to be run from a single WP installation (Codex Glossary) ● Prior to version 3.0, WordPress MultiUser was required for this functionality ● With WordPress version 3.0, Multisite functionality was rolled into WP's core
  • 4. Why does BU use Multisite? ● BU has several faculties with many departments within them ● Each faculty and department has a website ● Each website has its own coterie of editors ● With WP Multisite, this is easy to set up and maintain
  • 5. How does one set up Multisite? ● See the WordPress Codex "Create A Network" page for a full explanation ● You need to edit your wp-config.php file... ● ...set up your Network in /wp-admin/... ● ...and then edit your wp-config.php and .htaccess files again. ● Don't panic!
  • 6. wp-config.php define( 'WP_ALLOW_MULTISITE', true ); /* That's all, stop editing! Happy blogging. */
  • 10. wp-config.php define( 'WP_ALLOW_MULTISITE', true ); define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', false ); $base = '/'; define( 'DOMAIN_CURRENT_SITE', 'example' ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); /* That's all, stop editing! Happy blogging. */
  • 11. Users in Multisite ● Each site in a Multisite installation can have its own unique users, but all users are added to a site-wide "pool" of users ● A user who is an Administrator on Site A can be a Contributor on Site B, a Subscriber on sites C and D, and have no privileges at all on Site E ● Also, Multisite adds a new administrative level: Super Admin, who can make network-wide changes
  • 13. Add New User -- "classic" vs. Multisite
  • 14. Adding Sites ● The Super Admin(s) can add sites
  • 15. Connecting Sites ● News and Events – Centralized or distributed? ● Parents and grandparents – Breadcrumbs – Contact information
  • 16. News (Centralized) ● BU's news lives in the /news/ site, and is maintained by a handful of people ● The news articles are categorized by site -- eg, news for the English homepage is in the English category, news for Physics in the Physics category, etc. ● Custom code fetches & displays the news for each site in the BU network
  • 18. add_action( 'bu_news_region', 'bu_get_news' ); function bu_get_news() { // Current site $site_name = get_bloginfo( 'name' ); if( 'News' == $site_name ) return; // no point doing anything *in* the News site $cat_id = bu_get_category_from_site( $site_name ); $url = get_bloginfo( 'wpurl' ); // Some site details $news_site = get_blog_details( 'News' ); $original_site = get_current_blog_id(); // so we can come back later // switch to the news site switch_to_blog( $news_details->blog_id ); // get the posts with category matching the site name $args = array( 'category' => $cat_id, 'numberposts' => 4 ); $articles = get_posts( $args );
  • 19. if( is_array( $articles ) && ! empty( $articles ) ) { $article_list = "<h2>$site_name News</h2>"; $article_list .= '<dl>'; foreach ( $articles as $post ) { setup_postdata( $post ); $article_list .= ' <dt> <a href="' . get_permalink() . '">' . get_the_title() . '</a> </dt> <dd> <span class="news-date">' . get_the_date() . '</span> </dd>'; } // end foreach $article_list .= '</dl>'; } // endif switch_to_blog( $original_site ); if( strlen( $article_list ) > 0 ) { echo( $article_list ); } } // end of function
  • 20. Events (Distributed (well, soon)) ● BU is moving to tri.be's The Event Calendar, which will allow site editors to maintain their own events ● Events may be suggested for promotion by site editors, so that they might appear on the BU Home Page Event listing ● Promoted events must be authorized by a site administrator
  • 21. events.php Assumptions The code that follows is the core of the event promotion system. Several checks have been trimmed for brevity: ● Checking to ensure we're not in the root site (if we are, bail out with a return; ) ● The following must all be true: – tribe_is_event() – event is in the appropriate category in the sub-site – there isn't already a promoted event for the given $id
  • 22. add_action( 'save_post', 'bu_event_promote' ); function bu_event_promote( $id ){ if( ! isset($id) || ! is_numeric($id) ) { return(false); } $from_site = get_bloginfo('name'); $from_site_id = get_current_blog_id(); // setup the required variables BEFORE we switch to the home site $event_title = get_the_title( $id ); $event_url = get_permalink( $id ); $event_start = tribe_get_start_date( $id, false, 'Y-M-d' ); $event_end = tribe_get_end_date( $id, false, 'Y-M-d' ); switch_to_blog( BLOG_ID_CURRENT_SITE ); $args = array( 'post_status' => 'draft', 'post_content' => "This is a promoted post, from the '$from_site' site.nPlease do not edit this post; just publish it if appropriate, or ignore it.", 'post_title' => $event_title, 'EventStartDate' => $event_start, 'EventEndDate' => $event_end, ); $new_event_id = tribe_create_event( $args );
  • 23. // Meta info (redirection) $meta = array( '_pprredirect_active' => 1, '_pprredirect_type' => 301, '_pprredirect_rewritelink' => 1, '_pprredirect_url' => $event_url, ); $meta_unique = true; foreach($meta as $key => $value){ add_post_meta($new_event_id, $key, $value, $meta_unique); } switch_to_blog( $from_site_id ); // back from whence you came // once all that's done, add the _bu_promoted_event meta to the original $event // using the new event's $post->ID so it can be removed later, if necessary add_post_meta($id, '_bu_promoted_event', $new_event_id, true); // All done }
  • 24. Site Parents & Breadcrumbs ● WordPress Multisite does not support nested sub-sites (ie, /arts cannot contain /arts/english) ● /arts and /english are two separate sites ● With a bit of plugin magic, though, we can set /arts as the parent site of /english, so that breadcrumbs look like this:
  • 25. Site Parent ● Arts is interposed in the breadcrumb via an in- house plugin named Site Parent. Site Parent sets an option in the current site with the ID of the selected "Parent".
  • 26. More Site Parent uses ● The Site Parent option is also used by the in-house Contact Info plugin ● If the current site has no contact information set, the plugin will look to the site's Site Parent, using switch_to_blog() ● If there's no contact info there, the plugin ascends level after level, until it gets to the root site ● If the root site's contact info is empty, the plugin displays a default string
  • 27. References ● Codex.WordPress.org – Glossary – Before You Create a Network – Create a Network – Function Reference (x1000) – Plugin API pages (filters, hooks, etc) ● WordPress.org/support ● Tri.be support pages & forums ● WordPress.StackExchange.com
  • 28. You've got questions, I've got answers. ...hopefully.
  • 29. fin.