From 8ed2834c27f3a3c535e6ed56fedfa4d3af7413da Mon Sep 17 00:00:00 2001 From: sam perrow Date: Sun, 2 Aug 2020 20:04:04 -0600 Subject: [PATCH] 1.7.3 --- includes/class-pprh-send-hints.php | 35 +++++++++++------------------- js/admin.js | 5 ++--- pre-party-browser-hints.php | 15 +++++++++---- readme.txt | 13 +++++++---- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/includes/class-pprh-send-hints.php b/includes/class-pprh-send-hints.php index 5f5704f..3992de5 100644 --- a/includes/class-pprh-send-hints.php +++ b/includes/class-pprh-send-hints.php @@ -10,14 +10,14 @@ class Send_Hints { protected $hints = array(); - protected $hint_location = ''; + protected $send_hints_in_html = ''; public function __construct() { add_action( 'wp_loaded', array( $this, 'get_resource_hints' ) ); } public function get_resource_hints() { - $this->hint_location = get_option('pprh_html_head'); + $this->send_hints_in_html = get_option('pprh_html_head'); $this->hints = $this->get_hints(); @@ -25,7 +25,7 @@ public function get_resource_hints() { return; } - ( 'false' === $this->hint_location && ! headers_sent() ) + ( 'false' === $this->send_hints_in_html && ! 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); } @@ -42,9 +42,9 @@ public function get_hints() { public function send_to_html_head() { foreach ( $this->hints as $key => $val ) { $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', trim( $val->crossorigin ) ); + $attrs .= $this->add_attr( 'as', $val->as_attr ); + $attrs .= $this->add_attr( 'type', $val->type_attr ); + $attrs .= $this->add_attr( 'crossorigin', trim( $val->crossorigin ) ); echo sprintf( '', $val->url, $val->hint_type, $attrs ); } } @@ -54,9 +54,9 @@ public function send_in_http_header() { foreach ( $this->hints as $key => $val ) { $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', trim( $val->crossorigin ) ); + $attrs .= $this->add_attr( 'as', $val->as_attr ); + $attrs .= $this->add_attr( 'type', $val->type_attr ); + $attrs .= $this->add_attr( 'crossorigin', trim( $val->crossorigin ) ); $str = sprintf( '<%s>; rel=%s;%s', $val->url, $val->hint_type, $attrs ); $str = rtrim( $str, ';' ); $output .= $str . ', '; @@ -66,22 +66,13 @@ public function send_in_http_header() { header( $header_str ); } - private function add_header_attr( $name, $val ) { + private function add_attr( $name, $val ) { if ( ! empty( $val ) ) { $attr = Utils::clean_hint_attr( $val ); - return " $name=$attr;"; - } else { - return ''; - } - } - - private function add_html_attr( $name, $val ) { - if ( ! empty( $val ) ) { - $attr = Utils::clean_hint_attr( $val ); - return " $name=\"$attr\""; - } else { - return ''; + $attr = ( 'true' === $this->send_hints_in_html ) ? "\"$attr\"" : "$attr;"; + return ' ' . ( ( 'crossorigin' === $name ) ? $name : "$name=" . $attr ); } + return ''; } } diff --git a/js/admin.js b/js/admin.js index b33bba0..4372ea8 100644 --- a/js/admin.js +++ b/js/admin.js @@ -108,7 +108,7 @@ jQuery(document).ready(function($) { return { url: hint_url, hint_type: hintType, - crossorigin: elems.crossorigin.attr('checked') ? 'crossorigin' : '', + crossorigin: elems.crossorigin.is(':checked') ? 'crossorigin' : '', as_attr: elems.as_attr.val(), type_attr: elems.type_attr.val(), action: op, @@ -144,7 +144,6 @@ jQuery(document).ready(function($) { } function createAjaxReq(dataObj) { - var host = document.location.origin; var xhr = new XMLHttpRequest(); var url = pprh_nonce.admin_url + 'admin-ajax.php'; xhr.open('POST', url, true); @@ -260,7 +259,7 @@ jQuery(document).ready(function($) { var checkboxes = $('table.pprh-post-table tbody th.check-column input:checkbox'); $.each(checkboxes, function() { - if ($(this).attr('checked')) { + if ($(this).is(':checked')) { return idArr.push($(this).val()); } }); diff --git a/pre-party-browser-hints.php b/pre-party-browser-hints.php index 71c3d31..b664c2a 100644 --- a/pre-party-browser-hints.php +++ b/pre-party-browser-hints.php @@ -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.7.2.2 + * Version: 1.7.3 * Requires at least: 4.4 * Requires PHP: 5.6.30 * Author: Sam Perrow @@ -13,7 +13,7 @@ * Text Domain: pprh * Domain Path: /languages * - * last edited July 7, 2020 + * last edited August 2, 2020 * * Copyright 2016 Sam Perrow (email : sam.perrow399@gmail.com) * @@ -48,6 +48,7 @@ public function initialize() { include_once PPRH_ABS_DIR . '/includes/class-pprh-ajax-ops.php'; add_action( 'admin_menu', array( $this, 'load_admin_page' ) ); } else { + $this->pprh_disable_wp_hints(); include_once PPRH_ABS_DIR . '/includes/class-pprh-send-hints.php'; } @@ -81,7 +82,7 @@ public function create_constants() { $abs_dir = untrailingslashit( __DIR__ ); $rel_dir = plugins_url() . '/pre-party-browser-hints/'; - define( 'PPRH_VERSION', '2.0.2' ); + define( 'PPRH_VERSION', '1.7.3' ); define( 'PPRH_DB_TABLE', $table ); define( 'PPRH_ABS_DIR', $abs_dir ); define( 'PPRH_REL_DIR', $rel_dir ); @@ -95,7 +96,7 @@ public function register_admin_files( $hook ) { 'admin_url' => admin_url() ); - wp_register_script( 'pprh_admin_js', plugin_dir_url( __FILE__ ) . 'js/admin.js', null, PPRH_VERSION, true ); + wp_register_script( 'pprh_admin_js', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery' ), PPRH_VERSION, true ); wp_localize_script( 'pprh_admin_js', 'pprh_nonce', $ajax_data ); wp_register_style( 'pprh_styles_css', plugin_dir_url( __FILE__ ) . '/css/styles.css', null, PPRH_VERSION, 'all' ); @@ -189,4 +190,10 @@ private function create_table( $table_name ) { dbDelta( $sql, true ); } + public function pprh_disable_wp_hints() { + if ( 'true' === get_option( 'pprh_disable_wp_hints' ) ) { + return remove_action( 'wp_head', 'wp_resource_hints', 2 ); + } + } + } diff --git a/readme.txt b/readme.txt index fbf51c5..d55f89b 100644 --- a/readme.txt +++ b/readme.txt @@ -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.4.2 -Stable tag: 1.7.2.2 +Tested up to: 5.5 +Stable tag: 1.7.3 Requires PHP: 5.6.30 License: GPLv2 or later 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 == Changelog == -1. Most recent update: July 7, 2020. -2. Version 1.7.2.2 +1. Most recent update: August 2, 2020. +2. Version 1.7.3 + +August 2, 2020: +1) tested WP 5.5 compatbility +2) corrected bug with updating hints +3) simplified the sending of and creation of frontend hints July 7, 2020: 1) Replaced hardcoded "wp-admin" URL's with dynamic ones.