Skip to content

Commit b9bb830

Browse files
committed
change some word
1 parent 7f87c66 commit b9bb830

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This is a plugin which sends link headers for HTTP/2 server push.
1515
There is a filter hook for items to send as link header.
1616

1717
```
18-
add_filter( 'http2_server_push_items', function( $items ) {
18+
add_filter( 'http2_server_preload_items', function( $items ) {
1919
$new = array(
2020
'image' => array(
2121
'/wp-content/uploads/favicon.png'

http2-server-push-preload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ function activate_autoupdate() {
3434
add_action( 'send_headers', function() {
3535
if ( ! is_admin() ) {
3636
do_action( 'wp_enqueue_scripts' );
37-
Http2_Server_Push\send_http2_link_header( Http2_Server_Push\get_enqueued_items() );
37+
Http2_Server_Push\send_http2_link_header( Http2_Server_Push\get_preload_items() );
3838
}
3939
} );
4040

4141
add_action( 'admin_enqueue_scripts', function() {
4242
if ( headers_sent() ) {
4343
return;
4444
}
45-
Http2_Server_Push\send_http2_link_header( Http2_Server_Push\get_enqueued_items() );
45+
Http2_Server_Push\send_http2_link_header( Http2_Server_Push\get_preload_items() );
4646
}, 9999 );
4747

4848
add_filter( 'http_request_args', function ( $response, $url ) {

lib/functions.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function send_http2_link_header( $items ) {
1313
foreach ( $urls as $url ) {
1414
$links[] = sprintf(
1515
'<%s>; rel=preload; as=%s',
16-
esc_url_raw( $url ),
16+
$url,
1717
$as
1818
);
1919
}
@@ -29,13 +29,13 @@ function send_http2_link_header( $items ) {
2929
*
3030
* @return array An array of URLs.
3131
*/
32-
function get_enqueued_items() {
32+
function get_preload_items() {
3333
$items = array(
3434
'style' => get_urls( wp_styles() ),
3535
'script' => get_urls( wp_scripts() ),
3636
);
3737

38-
return apply_filters( 'http2_server_push_items', $items );
38+
return apply_filters( 'http2_server_preload_items', $items );
3939
}
4040

4141
/**
@@ -57,8 +57,9 @@ function get_urls( $wp_links ) {
5757

5858
$urls = array();
5959
foreach ( $to_do as $handle ) {
60-
if ( ! empty( $links[ $handle ] ) && $links[ $handle ]->src && is_string( $links[ $handle ]->src ) ) {
61-
$src = $links[ $handle ]->src;
60+
if ( ! empty( $links[ $handle ] ) && ! empty( $links[ $handle ]->src )
61+
&& is_string( $links[ $handle ]->src ) ) {
62+
$src = esc_url_raw( $links[ $handle ]->src );
6263
if ( preg_match( "#^http://#", $src ) ) {
6364
continue;
6465
} elseif ( preg_match( "#^https://#", $src ) ) {

tests/test-http2-server-push.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function setUp()
1616

1717
public function test_get_enqueued_items()
1818
{
19-
$urls = Http2_Server_Push\get_enqueued_items();
19+
$urls = Http2_Server_Push\get_preload_items();
2020

2121
$this->assertTrue( is_array( $urls ) );
2222
$this->assertTrue( is_array( $urls['style'] ) );
@@ -42,7 +42,7 @@ public function test_get_urls()
4242

4343
public function test_filter_http2_server_push_items()
4444
{
45-
add_filter( 'http2_server_push_items', function( $items ) {
45+
add_filter( 'http2_server_preload_items', function( $items ) {
4646
$new = array(
4747
'image' => array(
4848
'/wp-content/uploads/favicon.png'
@@ -52,7 +52,7 @@ public function test_filter_http2_server_push_items()
5252
return array_merge_recursive( $items, $new );
5353
} );
5454

55-
$urls = Http2_Server_Push\get_enqueued_items();
55+
$urls = Http2_Server_Push\get_preload_items();
5656

5757
$this->assertSame( '/wp-content/uploads/favicon.png', $urls['image'][0] );
5858
$this->assertTrue( !! $urls['style'] );

0 commit comments

Comments
 (0)