cameronterry / dark-matter

A highly opinionated domain mapping plugin for WordPress Networks
Other
12 stars 2 forks source link

Media domain support #68

Closed cameronterry closed 2 years ago

cameronterry commented 3 years ago

This PR adds support to the domain mapping for "Media domains". When added, these domains will be used to map items which are supported by the Media Library on a given site. This will include:

This will also include support for customisations that are provided through upload_mimes hook (WordPress Developer Reference). A good example of a customisation: websites using the Safe SVG plugin.

Testing check list

CLI changes

wp --url="sites.my.com/sitefifteen" darkmatter domain add fifteen.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 www.secondarydomain.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 www.secondarydomain.com --type=main --secondary

List all domains - of types, "main" and "media".

wp darkmatter domain list

Changelog

Performance Check

Both setups are using Twenty Twenty One with object cache enabled and configured, with both containing 842 posts.

Single site installation image

Multisite installation on a site with domain mapping configured. image

cameronterry commented 3 years ago

Noting, this has only been tested with the Gallery Block on Block Editor. Other image related blocks - i.e. Audio, Cover, Video, etc. - need to be tested.

Classic Editor and shortcodes need tested as well. And logic is needed for Feature Image / attachment related APIs such as wp_get_attachment_image_src().

cameronterry commented 3 years ago

Self note: should provide an ability to set a network-wide CDN domains, which are enforced on all sites. This should be achievable through detecting a constant - such as: DM_NETWORK_CDN - which is an array of domains.

define( 'DM_NETWORK_CDN', [
    'cdn1.mappeddomain1.test',
    'cdn2.mappeddomain1.test',
    'cdn3.mappeddomain1.test',
] );