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 The Wonders of WordPress Multisite: Setting Up Sites, Users, Events and More

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 The Wonders of WordPress Multisite: Setting Up Sites, Users, Events and More (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

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

The Wonders of WordPress Multisite: Setting Up Sites, Users, Events and More

  • 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.