Skip to content

Commit ae5ba49

Browse files
authored
Merge pull request #40 from samperrow/1.7.3
1.7.3
2 parents c5e277a + 8ed2834 commit ae5ba49

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

includes/class-pprh-send-hints.php

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ class Send_Hints {
1010

1111
protected $hints = array();
1212

13-
protected $hint_location = '';
13+
protected $send_hints_in_html = '';
1414

1515
public function __construct() {
1616
add_action( 'wp_loaded', array( $this, 'get_resource_hints' ) );
1717
}
1818

1919
public function get_resource_hints() {
20-
$this->hint_location = get_option('pprh_html_head');
20+
$this->send_hints_in_html = get_option('pprh_html_head');
2121

2222
$this->hints = $this->get_hints();
2323

2424
if ( ( ! is_array( $this->hints ) ) || count( $this->hints ) < 1 ) {
2525
return;
2626
}
2727

28-
( 'false' === $this->hint_location && ! headers_sent() )
28+
( 'false' === $this->send_hints_in_html && ! headers_sent() )
2929
? add_action('send_headers', array($this, 'send_in_http_header'), 1, 0)
3030
: add_action('wp_head', array($this, 'send_to_html_head'), 1, 0);
3131
}
@@ -42,9 +42,9 @@ public function get_hints() {
4242
public function send_to_html_head() {
4343
foreach ( $this->hints as $key => $val ) {
4444
$attrs = '';
45-
$attrs .= $this->add_html_attr( 'as', $val->as_attr );
46-
$attrs .= $this->add_html_attr( 'type', $val->type_attr );
47-
$attrs .= $this->add_html_attr( 'crossorigin', trim( $val->crossorigin ) );
45+
$attrs .= $this->add_attr( 'as', $val->as_attr );
46+
$attrs .= $this->add_attr( 'type', $val->type_attr );
47+
$attrs .= $this->add_attr( 'crossorigin', trim( $val->crossorigin ) );
4848
echo sprintf( '<link href="%s" rel="%s"%s>', $val->url, $val->hint_type, $attrs );
4949
}
5050
}
@@ -54,9 +54,9 @@ public function send_in_http_header() {
5454

5555
foreach ( $this->hints as $key => $val ) {
5656
$attrs = '';
57-
$attrs .= $this->add_header_attr( 'as', $val->as_attr );
58-
$attrs .= $this->add_header_attr( 'type', $val->type_attr );
59-
$attrs .= $this->add_header_attr( 'crossorigin', trim( $val->crossorigin ) );
57+
$attrs .= $this->add_attr( 'as', $val->as_attr );
58+
$attrs .= $this->add_attr( 'type', $val->type_attr );
59+
$attrs .= $this->add_attr( 'crossorigin', trim( $val->crossorigin ) );
6060
$str = sprintf( '<%s>; rel=%s;%s', $val->url, $val->hint_type, $attrs );
6161
$str = rtrim( $str, ';' );
6262
$output .= $str . ', ';
@@ -66,22 +66,13 @@ public function send_in_http_header() {
6666
header( $header_str );
6767
}
6868

69-
private function add_header_attr( $name, $val ) {
69+
private function add_attr( $name, $val ) {
7070
if ( ! empty( $val ) ) {
7171
$attr = Utils::clean_hint_attr( $val );
72-
return " $name=$attr;";
73-
} else {
74-
return '';
75-
}
76-
}
77-
78-
private function add_html_attr( $name, $val ) {
79-
if ( ! empty( $val ) ) {
80-
$attr = Utils::clean_hint_attr( $val );
81-
return " $name=\"$attr\"";
82-
} else {
83-
return '';
72+
$attr = ( 'true' === $this->send_hints_in_html ) ? "\"$attr\"" : "$attr;";
73+
return ' ' . ( ( 'crossorigin' === $name ) ? $name : "$name=" . $attr );
8474
}
75+
return '';
8576
}
8677

8778
}

js/admin.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jQuery(document).ready(function($) {
108108
return {
109109
url: hint_url,
110110
hint_type: hintType,
111-
crossorigin: elems.crossorigin.attr('checked') ? 'crossorigin' : '',
111+
crossorigin: elems.crossorigin.is(':checked') ? 'crossorigin' : '',
112112
as_attr: elems.as_attr.val(),
113113
type_attr: elems.type_attr.val(),
114114
action: op,
@@ -144,7 +144,6 @@ jQuery(document).ready(function($) {
144144
}
145145

146146
function createAjaxReq(dataObj) {
147-
var host = document.location.origin;
148147
var xhr = new XMLHttpRequest();
149148
var url = pprh_nonce.admin_url + 'admin-ajax.php';
150149
xhr.open('POST', url, true);
@@ -260,7 +259,7 @@ jQuery(document).ready(function($) {
260259
var checkboxes = $('table.pprh-post-table tbody th.check-column input:checkbox');
261260

262261
$.each(checkboxes, function() {
263-
if ($(this).attr('checked')) {
262+
if ($(this).is(':checked')) {
264263
return idArr.push($(this).val());
265264
}
266265
});

pre-party-browser-hints.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Pre* Party Resource Hints
44
* Plugin URI: https://wordpress.org/plugins/pre-party-browser-hints/
55
* Description: Take advantage of the browser resource hints DNS-Prefetch, Prerender, Preconnect, Prefetch, and Preload to improve page load time.
6-
* Version: 1.7.2.2
6+
* Version: 1.7.3
77
* Requires at least: 4.4
88
* Requires PHP: 5.6.30
99
* Author: Sam Perrow
@@ -13,7 +13,7 @@
1313
* Text Domain: pprh
1414
* Domain Path: /languages
1515
*
16-
* last edited July 7, 2020
16+
* last edited August 2, 2020
1717
*
1818
* Copyright 2016 Sam Perrow (email : sam.perrow399@gmail.com)
1919
*
@@ -48,6 +48,7 @@ public function initialize() {
4848
include_once PPRH_ABS_DIR . '/includes/class-pprh-ajax-ops.php';
4949
add_action( 'admin_menu', array( $this, 'load_admin_page' ) );
5050
} else {
51+
$this->pprh_disable_wp_hints();
5152
include_once PPRH_ABS_DIR . '/includes/class-pprh-send-hints.php';
5253
}
5354

@@ -81,7 +82,7 @@ public function create_constants() {
8182
$abs_dir = untrailingslashit( __DIR__ );
8283
$rel_dir = plugins_url() . '/pre-party-browser-hints/';
8384

84-
define( 'PPRH_VERSION', '2.0.2' );
85+
define( 'PPRH_VERSION', '1.7.3' );
8586
define( 'PPRH_DB_TABLE', $table );
8687
define( 'PPRH_ABS_DIR', $abs_dir );
8788
define( 'PPRH_REL_DIR', $rel_dir );
@@ -95,7 +96,7 @@ public function register_admin_files( $hook ) {
9596
'admin_url' => admin_url()
9697
);
9798

98-
wp_register_script( 'pprh_admin_js', plugin_dir_url( __FILE__ ) . 'js/admin.js', null, PPRH_VERSION, true );
99+
wp_register_script( 'pprh_admin_js', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery' ), PPRH_VERSION, true );
99100
wp_localize_script( 'pprh_admin_js', 'pprh_nonce', $ajax_data );
100101
wp_register_style( 'pprh_styles_css', plugin_dir_url( __FILE__ ) . '/css/styles.css', null, PPRH_VERSION, 'all' );
101102

@@ -189,4 +190,10 @@ private function create_table( $table_name ) {
189190
dbDelta( $sql, true );
190191
}
191192

193+
public function pprh_disable_wp_hints() {
194+
if ( 'true' === get_option( 'pprh_disable_wp_hints' ) ) {
195+
return remove_action( 'wp_head', 'wp_resource_hints', 2 );
196+
}
197+
}
198+
192199
}

readme.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Contributors: samperrow
33
Donate link: https://www.paypal.me/samperrow
44
Tags: W3C, DNS prefetch, prerender, preconnect, prefetch, preload, web perf, performance, speed, resource hints
55
Requires at least: 4.4
6-
Tested up to: 5.4.2
7-
Stable tag: 1.7.2.2
6+
Tested up to: 5.5
7+
Stable tag: 1.7.3
88
Requires PHP: 5.6.30
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -80,8 +80,13 @@ To activate the preloaded resource, you must call that file in HTML as you would
8080

8181
== Changelog ==
8282

83-
1. Most recent update: July 7, 2020.
84-
2. Version 1.7.2.2
83+
1. Most recent update: August 2, 2020.
84+
2. Version 1.7.3
85+
86+
August 2, 2020:
87+
1) tested WP 5.5 compatbility
88+
2) corrected bug with updating hints
89+
3) simplified the sending of and creation of frontend hints
8590

8691
July 7, 2020:
8792
1) Replaced hardcoded "wp-admin" URL's with dynamic ones.

0 commit comments

Comments
 (0)