Headless Support

cpritchett

New member
Our wordpress sites are headless, which was an issue with implementing the offical CF plugins (the backend server just knows cms.domain.com but the pages are served on domain.com). Could this be something the plugin could support?
 
If I'm being honest, I don't have any experience with headless Wordpress, but if it's just a matter of swapping the internal site URL (cms.domain.com) with the frontend URL (domain.com), I don't think it would be particularly difficult.

Specifically, the plugin already makes used of a singular method to get the site's URL (which is really just a wrapper for the WordPress function, get_site_url()). That WordPress core function already has a filter (site_url) that can be used to effectively change the site URL when it's read via that function.

Without having any experience running WordPress headless, I'd *think* that whatever mechanism you are using to do it may already be leveraging that filter... and if it is, that may be all that's needed. I believe that's already how things like WordPress multisite work (it remaps a subdomain to an actual domain that the user sees).

If there's no real connection between the backend and the presentation/front-end and using the site_url filter isn't an option (for whatever reason), it shouldn't be particularly hard to implement something... I'd just need to know *exactly* what needs to happen (like is it *just* the transposing of the site URL in the context of this plugin?).
 
FWIW, it probably does make sense to give people flexibility to remap domains if needed (for anything, not just headless WordPress). So while use of the site_url filter would work already, there may be a situation where you don't want to remap everything.

For that scenario, I added 2 new mechanisms for the next version. You can define a CLOUDFLARE_DOMAIN PHP constant (like in your config.php, or wherever else you see fit). That will remap the site URL just for this plugin:

PHP:
define('CLOUDFLARE_DOMAIN', 'https://domain.com');

...if that constant exists, use that as the site URL, otherwise fall back to the normal site URL.

Additionally, it also checks for a domain_mapping_siteurl() function. If that function exists, it will call that function to remap the domain.

Between those 3 options (site_url filter, a named constant to override the site URL as well as the ability to use a custom remapping function), hopefully that should cover you?
 
Back
Top