Skip to content

2.2.0

Choose a tag to compare

@cameronterry cameronterry released this 09 Jan 20:59
· 235 commits to develop since this release
11388d8
  • New Features:
    • Say hello to "Media domains"; a new type of domain to Dark Matter that can be used to serve media assets from a different domain name.
      • Useful for separating infrastructure which is used for static assets from servers powering PHP requests.
      • Or powering images through a dedicated / dynamic service such as Tachyon.
      • Can be hard-set using an array of domains in a constant called, DM_NETWORK_MEDIA.
      • Supports all extensions that are supported by the Media Library. So if you add SVG upload support, "Media domains" will support it too.
      • Updating the existing CLIs to support domain types and management of "Media domains".
    • WordPress' plugin screen will now notify you of future releases and to update.
      • Added support for WordPress auto-update functionality.
      • Releases after 2.2.0, you will be able to update Dark Matter through WP CLI or admin interface (depending on your setup / file permissions).
      • Servers are renewable powered!
  • Bug fixes and maintenance:
    • Updated the readme.md file to include CLI examples for Media Domains.
    • Updated the readme.md file to include notes on two constants that can be used with Dark Matter for disabling SSO and configuring Media Domains for an entire Multisite.
    • Improved the domain validation when adding new domains.
    • Added plugin header comment block to the sunrise.php dropin.
      • There is no code and / or logic changes, however you will need to run wp darkmatter dropin update --force.
      • This will provide better information on WordPress plugins screen, clearly identifying Dark Matter's sunrise dropin from others.
      • This also improves diagnostic data for other plugins, such as Redis Cache / wp redis status.
    • Tweaked the release shell script to better support wp-update-server.
    • Updated composer dependencies and support for Composer 2.2.x version.
    • Updated npm dependencies, excluding eslint.

Media Domains

Dark Matter 2.2.0 introduces the concept of "Media Domains" which means that a WordPress Multisite can be configured to change media library files to be on a different domain. Please note: this will not upload your files to a separate service, just altered the URLs when referenced by WordPress.

In effect, this will take media library files that were previously served over the admin domain or the primary domain to be served by a separate, specified, domain. For example: if the admin domain is admin.example.com and the primary domain of one of the sites on the Multisite is mypersonalsite.blog, the Media library files will be a mixture of the following:

https://admin.example.com/mypersonalsite/wp-content/uploads/sites/2/2022/01/executium-2YIwvJx8IWs-unsplash-scaled.jpg
https://mypersonalsite.blog/wp-content/uploads/sites/2/2022/01/pexels-yovan-verma-2082103-scaled.jpg

If a media domain is configured as example.mycdn.com, then those links will change to the following (note the admin domain version has replaced both the domain and the site slug, /mypersonalsite/, as well):

https://example.mycdn.com/wp-content/uploads/sites/2/2022/01/executium-2YIwvJx8IWs-unsplash-scaled.jpg
https://example.mycdn.com/wp-content/uploads/sites/2/2022/01/pexels-yovan-verma-2082103-scaled.jpg

The benefits of serving your media library assets on a separate domain include, but are not limited to, the following:

  • Increase the number of simultaneous connections. For example: Firefox, by default, will limit to 6 connections.
  • Separate domains can be used to either split up bandwidth expenditure as well as reducing it, by removing cookies used by the primary domain - such as the WordPress login cookies, etc.. For example: if you are using a reverse proxy technology that charges by bandwidth, then it may be desirable to separate website requests from media requests by domains to reduce cost.
  • Take advantage of image serving technologies, such as Tachyon or dynamic image processing techniques with technology such as OpenResty.

To configure Media Domains, you can use the CLI or a constant in your wp-config.php, depending on whether you want to have unique media domains for individual sites or one set of media domains for all sites on the WordPress Multisite.

CLI Examples

Set a media domain for a site.

wp --url="sites.my.com/sitefifteen" darkmatter domain add example.mycdn.com --type=media

Convert a secondary domain into a media domain. Useful for when repurposing an old domain for use a CDN for media assets.

wp --url="sites.my.com/siteone" darkmatter domain set example.mycdn.com --type=media

Convert a Media domain to a main domain. This is useful in scenarios when a media domain is redundant and to ensure it redirects to the website.

wp --url="sites.my.com/siteone" darkmatter domain set secondarydomain.com --type=main --secondary

DM_NETWORK_MEDIA

Alternatively, media domains can be set by adding the DM_NETWORK_MEDIA constant to the wp-config.php file. This will override any configured media domains and force all websites within your WordPress Multisite to use the specified media domains instead.

/* That's all, stop editing! Happy publishing. */
define( 'DM_NETWORK_MEDIA', [
    'example.mycdn.com',
    /** Add additional domains here if desired. */
] );

Setup Example

Using the example noted previously, NGINX can be configured in the following manner to server images on example.mycdn.com domain for media library files. This example assumes the media library assets are hosted with a service such as Amazon Web Services S3 storage or Linode Object Storage using a plugin such as S3 Uploads plugin.

A site can be configured on NGINX to respond and server assets from the storage bucket. This can be setup on on a load balancer or entirely separate server.

server {
    server_name example.mycdn.com;
    root /srv/example.mycdn.com;
    index index.html;
    error_page 404 /index.html;

    # Other settings and custom configuration such as SSL certs.

    location ~ /?.*/wp-content(?<img>/uploads/.*) {
        expires 1d;

        log_not_found off;
        access_log off;

        resolver 8.8.8.8;

        proxy_http_version 1.1;
        proxy_cache s3bucket;

        proxy_set_header Host s3bucketurlhere.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_pass https://s3bucketurlhere.com;
    }
}

Side Note: it is worth stating that another option, if you are using Amazon Web Services especially, is to use Dark Matter to change the URLs to one hosted by Cloudfront rather than rolling out an NGINX server. Likewise for DigitalOcean's Spaces Object Storage.

If Media Library files are stored on an NFS or with software such as GlusterFS, a similar setup can be deployed by mounting the shared disk onto a server running NGINX and responding to the example.mycdn.com domain (in this example).