Ga naar inhoud

Bedrock multisite

Bedrock heeft een fix nodig om het /wp/wp-admin/network/ pad te ondersteunen. Implementeer deze mu-plugin van GitHub in this PR.

Gebruik dit als een must-use plugin om je netwerkbeheerpaden te repareren.

Je kunt ook composer gebruiken om dit via hun repo te installeren:

Terminal window
composer require roots/multisite-url-fixer

Gebruik het volgende script:

<?php
/**
* Plugin Name: Multisite URL Fixer
* Plugin URI: https://github.com/roots/bedrock/
* Description: Fixes WordPress issues with home and site URL on multisite.
* Version: 1.0.0
* Author: Roots
* Author URI: https://roots.io/
* License: MIT License
*/
namespace Roots\Bedrock;
if ( ! is_multisite() ) {
return;
}
/**
* Class URLFixer
* @package Roots\Bedrock
* @author Roots
* @link https://roots.io/
*/
class URLFixer {
/** @var Roots\Bedrock\URLFixer Singleton instance */
private static $instance = null;
/**
* Singleton.
*
* @return Roots\Bedrock\URLFixer
*/
public static function instance() {
if ( null === self::$instance )
self::$instance = new self();
return self::$instance;
}
/**
* Add filters to verify / fix URLs.
*/
public function add_filters() {
add_filter( 'option_home', array( $this, 'fix_home_url' ) );
add_filter( 'option_siteurl', array( $this, 'fix_site_url' ) );
add_filter( 'network_site_url', array( $this, 'fix_network_site_url' ), 10, 3 );
}
/**
* Ensure that home URL does not contain the /wp subdirectory.
*
* @param string $value the unchecked home URL
* @return string the verified home URL
*/
public function fix_home_url( $value ) {
if ( '/wp' === substr( $value, -3 ) ) {
$value = substr( $value, 0, -3 );
}
return $value;
}
/**
* Ensure that site URL contains the /wp subdirectory.
*
* @param string $value the unchecked site URL
* @return string the verified site URL
*/
public function fix_site_url( $value ) {
if ( '/wp' !== substr( $value, -3 ) ) {
$value .= '/wp';
}
return $value;
}
/**
* Ensure that the network site URL contains the /wp subdirectory.
*
* @param string $url the unchecked network site URL with path appended
* @param string $path the path for the URL
* @param string $scheme the URL scheme
* @return string the verified network site URL
*/
public function fix_network_site_url( $url, $path, $scheme ) {
$path = ltrim( $path, '/' );
$url = substr( $url, 0, strlen( $url ) - strlen( $path ) );
if ( 'wp/' !== substr( $url, -3 ) ) {
$url .= 'wp/';
}
return $url . $path;
}
}
URLFixer::instance()->add_filters();

Deploy site naar test environment

Bedrock multisites geven wat problemen bij het implementeren via Trellis. Hier is een stappenplan om je te helpen dit op te lossen:

  1. Schakel alle multisite ENV vars uit in application.php. Of indien ingesteld in omgevingsspecifieke configuraties, doe het daar.
/**
* Multi site
*/
#Config::define('WP_ALLOW_MULTISITE', true);
#Config::define('MULTISITE', true);
#Config::define('SUBDOMAIN_INSTALL', false); // Set to true if using subdomains
#Config::define('DOMAIN_CURRENT_SITE', env('DOMAIN_CURRENT_SITE'));
#Config::define('PATH_CURRENT_SITE', env('PATH_CURRENT_SITE') ?: '/');
#Config::define('SITE_ID_CURRENT_SITE', env('SITE_ID_CURRENT_SITE') ?: 1);
#Config::define('BLOG_ID_CURRENT_SITE', env('BLOG_ID_CURRENT_SITE') ?: 1);
  1. Installeer WordPress via de browser.
  2. Schakel de WP_ALLOW_MULTISITE variabele in.
  3. Log in op het CMS en ga naar Extra -> Netwerk instellen. Nadat je subdomeinen of subdirectories hebt geselecteerd, druk je op installeren.
  4. Verwijder het commentaar van alle overige ENV vars.