Skip to content

Commit

Permalink
Merge pull request #36 from samperrow/dev-1.6.45
Browse files Browse the repository at this point in the history
Dev 1.6.45
  • Loading branch information
samperrow authored Feb 2, 2020
2 parents bced770 + 7050686 commit 6b59fe6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 22 deletions.
6 changes: 3 additions & 3 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Pre* Party Resource Hints
* Plugin URI: https://wordpress.org/plugins/pre-party-browser-hints/
* Description: Take advantage of the browser resource hints DNS-Prefetch, Prerender, Preconnect, Prefetch, and Preload to improve page load time.
* Version: 1.6.43
* Version: 1.6.45
* Requires at least: 4.4
* Requires PHP: 5.3
* Author: Sam Perrow
Expand Down Expand Up @@ -85,7 +85,7 @@ public function load_admin_page() {

public function create_constants() {
if ( ! defined( 'PPRH_VERSION' ) ) {
define( 'PPRH_VERSION', '1.6.4' );
define( 'PPRH_VERSION', '1.6.45' );
}
if ( ! defined( 'PPRH_PLUGIN_FILENAME' ) ) {
define( 'PPRH_PLUGIN_FILENAME', '/pre-party-browser-hints' );
Expand Down Expand Up @@ -224,7 +224,7 @@ public function install_db_table() {

foreach ( $pprh_tables as $pprh_table ) {

$sql = "CREATE TABLE IF NOT EXISTS $pprh_table (
$sql = "CREATE TABLE $pprh_table (
id INT(9) NOT NULL AUTO_INCREMENT,
url VARCHAR(255) DEFAULT '' NOT NULL,
hint_type VARCHAR(55) DEFAULT '' NOT NULL,
Expand Down
25 changes: 17 additions & 8 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,27 @@ div.pprh-code-block {
max-width: 95%;
}



/* table#pprh-post-table input {
display: none;
} */


div.row-actions span input {
display: none;
}


#pprhContactAuthor {
text-align: center;
}

span#pprhCachePlugins {
display: none;
}

p#pprhBox {
display: none;
margin: 20px auto;
background-color: #ff8080;
border: 1px solid #ff4d4d;
border-radius: 5px;
-webkit-border-radius: 5px;
max-width: 400px;
padding: 8px 25px;
transition: 0.3s;
-webkit-transition: 0.3s;
}
10 changes: 5 additions & 5 deletions includes/class-pprh-send-hints.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function get_resource_hints () {
return;
}

('true' === $opt)
? add_action('wp_head', array($this, 'send_to_html_head'), 1, 0)
: add_action('send_headers', array($this, 'send_in_http_header'), 1, 0);
('false' === $opt && ! headers_sent() )
? add_action('send_headers', array($this, 'send_in_http_header'), 1, 0)
: add_action('wp_head', array($this, 'send_to_html_head'), 1, 0);
}

// need to sanitize by removing anything other than link elems.
Expand All @@ -37,7 +37,7 @@ public function send_to_html_head() {
$attrs = '';
$attrs .= $this->add_html_attr( 'as', $val->as_attr );
$attrs .= $this->add_html_attr( 'type', $val->type_attr );
$attrs .= $this->add_html_attr( 'crossorigin', $val->crossorigin );
$attrs .= $this->add_html_attr( 'crossorigin', trim($val->crossorigin) );
echo sprintf('<link href="%s" rel="%s"%s>', $val->url, $val->hint_type, $attrs);
}
}
Expand All @@ -49,7 +49,7 @@ public function send_in_http_header() {
$attrs = '';
$attrs .= $this->add_header_attr( 'as', $val->as_attr );
$attrs .= $this->add_header_attr( 'type', $val->type_attr );
$attrs .= $this->add_header_attr( 'crossorigin', $val->crossorigin );
$attrs .= $this->add_header_attr( 'crossorigin', trim($val->crossorigin) );
$str = sprintf('<%s>; rel=%s;%s', $val->url, $val->hint_type, $attrs );
$str = rtrim( $str, ';' );
$output .= $str . ', ';
Expand Down
33 changes: 32 additions & 1 deletion includes/tabs/class-pprh-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ public function reset_preconnects() {
}

public function set_hint_destination() {
$active_cache_plugin = $this->get_cache_info();

?>
<tr>
<th>
Expand All @@ -187,14 +189,21 @@ public function set_hint_destination() {
</td>

<td>
<select name="pprh_html_head">
<select id="pprhHintLocation" name="pprh_html_head">
<option value="true" <?php $this->get_option_status( 'pprh_html_head', 'true' ); ?>>
<?php esc_html_e( 'HTML <head>', 'pprh' ); ?>
</option>
<option value="false" <?php $this->get_option_status( 'pprh_html_head', 'false' ); ?>>
<?php esc_html_e( 'HTTP Header', 'pprh' ); ?>
</option>
</select>

<?php
if (strlen($active_cache_plugin) > 0) {
echo "<span id='pprhCachePlugins'>$active_cache_plugin</span>";
echo "<p id='pprhBox'></p>";
}
?>
</td>
</tr>

Expand All @@ -205,6 +214,28 @@ public function get_option_status( $option_name, $val ) {
echo esc_html( ( get_option( $option_name ) === $val ? 'selected=selected' : '' ) );
}

private function get_cache_info() {

$cache_plugins = array(
'cache-control/cache-control.php' => 'Cache Control',
'cache-enabler/cache-enabler.php' => 'Cache Enabler',
'comet-cache/comet-cache.php' => 'Comet Cache',
'hyper-cache/plugin.php' => 'Hyper Cache',
'litespeed-cache/litespeed-cache.php' => 'LiteSpeed Cache',
'redis-cache/redis-cache.php' => 'Redis Cache',
'w3-total-cache/w3-total-cache.php' => 'W3 Total Cache',
'wp-fastest-cache/wpFastestCache.php' => 'WP Fastest Cache',
'wp-rocket/wp-rocket.php' => 'WP Rocket',
'wp-super-cache/wp-cache.php' => 'WP Super Cache',
);

foreach ($cache_plugins as $cache_plugin => $name) {
if (is_plugin_active($cache_plugin)) {
return $name;
}
}
}

}

if ( is_admin() ) {
Expand Down
12 changes: 12 additions & 0 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ jQuery(document).ready(function($) {

var currentURL = document.location.href;
var URLElem = document.getElementById('pprhURL');
var location = document.getElementById('pprhHintLocation');

if (/admin.php\?page=pprh-plugin-settings&tab=settings/ig.test(currentURL)) {
verifyPreconnectResets();
location.addEventListener('change', showCacheWarning);
}

function showCacheWarning() {
var plugins = document.getElementById('pprhCachePlugins');
var warning = document.getElementById('pprhBox');

if (plugins && plugins.innerHTML.length > 0) {
warning.innerHTML = 'The plugin ' + plugins.innerHTML + ' caches HTTP headers, <br/> it is advised that you load resource hints in your websites\'s HTML &lt;head&gt; instead, and then refresh your cache!';
warning.style.display = (location.value === 'false') ? 'block' : 'none';
}
}


Expand Down
14 changes: 9 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: samperrow
Donate link: https://www.paypal.me/samperrow
Tags: W3C, DNS prefetch, prerender, preconnect, prefetch, preload, web perf, performance, speed, resource hints
Requires at least: 4.4
Tested up to: 5.3.0
Stable tag: 1.6.43
Tested up to: 5.3.2
Stable tag: 1.6.45
Requires PHP: 5.6.30
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -82,12 +82,16 @@ To activate the preloaded resource, you must call that file in HTML as you would

== Changelog ==

1. Most recent update: December 8, 2019.
2. Version 1.6.43
1. Most recent update: February 2, 2020.
2. Version 1.6.45

February 2, 2020:
1) added warning when a cache plugin is active and users choose HTTP header option to let them know to clear cache.
2) Ensured compat w/ WP 5.3.2

December 8, 2019:
1) Re-added option to allow resource hints to be sent in the HTTP header.
2)
2) Small bug fixes

November 4, 2019:
1) Ensured compatibility with WP 5.3
Expand Down

0 comments on commit 6b59fe6

Please sign in to comment.