WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#20915 closed defect (bug) (duplicate)

Support for protocol-less URLs in wp_enqueue_*

Reported by: batmoo Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: Cc:

Description

The wp_enqueue_* functions should support protocol-less URLs. Currently they're handled as if they were absolute URLs.

For example:

wp_enqueue_script( 'js-no-proto', '//example.com/js/js.js' );

Gets output as:

<script type='text/javascript' src='http://example.com/js/js-proto.js?ver=3.4-RC3'></script>

It should look like:

<script type='text/javascript' src='//example.com/js/js.js?ver=3.4-RC3'></script>

Attachments (1)

20915.diff (1.1 KB) - added by batmoo 3 years ago.

Download all attachments as: .zip

Change History (4)

@batmoo3 years ago

comment:1 @batmoo3 years ago

  • Keywords has-patch added

Patch makes the protocol optional in the regex check in WP_(Scripts|Styles).

comment:2 @batmoo3 years ago

Some test cases:

add_action( 'wp_enqueue_scripts', function() {
	wp_enqueue_script( 'jquery' );
	wp_enqueue_script( 'js-no-proto', '//example.com/js/js.js' );
	wp_enqueue_script( 'js-proto', 'http://example.com/js/js-proto.js' );
	wp_enqueue_script( 'js-absolute', '/js/js-proto.js' );
	wp_enqueue_script( 'js-relative', 'js/js-proto.js' );
	wp_enqueue_script( 'js-invalid-proto', 'xyz://example.com/js/js-proto.js' );
} );

Returns:

<script type='text/javascript' src='http://localhost/wp/wp-includes/js/jquery/jquery.js?ver=1.7.2'></script>
<script type='text/javascript' src='//example.com/js/js.js?ver=3.4-RC3'></script>
<script type='text/javascript' src='http://example.com/js/js-proto.js?ver=3.4-RC3'></script>
<script type='text/javascript' src='http://localhost/wp/js/js-proto.js?ver=3.4-RC3'></script>
<script type='text/javascript' src='http://localhost/wpjs/js-proto.js?ver=3.4-RC3'></script>
<script type='text/javascript' src='http://localhost/wpxyz://example.com/js/js-proto.js?ver=3.4-RC3'></script>

comment:3 @duck_3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #16560 with the same patch too.

Note: See TracTickets for help on using tickets.