Skip to content

Relative URLs should be made absolute to promote embeddability #4599

@westonruter

Description

@westonruter

Bug Description

When a stylesheet does not exist on the filesystem but points to an endpoint that returns a stylesheet, a relative path does not work. Relative stylesheet URLs fail to be fetched.

Additionally, links and resources embedded on the page which make use of relative URLs need to also be made absolute so that AMP pages generated by the plugin are suitable to be embedded in cross-domain contexts such as with the AMP Shadow DOM API, such as in a headless context. This is also important for content being served by the REST API. See #1014.

Expected Behaviour

All relative URLs should appear as absolute in AMP pages, whether they be for stylesheets, fonts, images, links, audio, video, iframes, etc.

Steps to reproduce

Plugin code to reproduce this issue:

<?php
/**
 * Plugin Name: add foo/bar/baz stylesheet
 */

add_action( 'parse_request', function( WP $wp ) {
	if ( 'foo/bar/baz' !== $wp->request ) {
		return;
	}

	header( 'content-type: text/css' );
	echo 'body { border: solid 100px red; }';

	exit;
} );

add_action( 'wp_head', function() {
    echo '<link rel="stylesheet" href="/foo/bar/baz/">';
} );

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingGroomedIntegration: PWAP2Low priorityREST APIIssues, features related to REST APIWS:CoreWork stream for Plugin core

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions