From ef248a1b1b33ce9a2f15a5ab56ba717a82af9f5a Mon Sep 17 00:00:00 2001 From: Derek Springer Date: Thu, 24 Oct 2019 15:06:42 -0700 Subject: [PATCH] WordAds: Update Head Loader (#13795) --- modules/wordads/wordads.php | 52 ++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/modules/wordads/wordads.php b/modules/wordads/wordads.php index 02d85f798d05a..3fc03fb103507 100644 --- a/modules/wordads/wordads.php +++ b/modules/wordads/wordads.php @@ -197,6 +197,7 @@ public static function is_infinite_scroll() { * @since 4.5.0 */ private function insert_adcode() { + add_filter( 'wp_resource_hints', array( $this, 'resource_hints' ), 10, 2 ); add_action( 'wp_head', array( $this, 'insert_head_meta' ), 20 ); add_action( 'wp_head', array( $this, 'insert_head_iponweb' ), 30 ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); @@ -264,6 +265,35 @@ function enqueue_scripts() { ); } + /** + * Add the IPW resource hints + * + * @since 7.9 + */ + public function resource_hints( $hints, $relation_type ) { + if ( 'dns-prefetch' === $relation_type ) { + $hints[] = '//s.pubmine.com'; + $hints[] = '//x.bidswitch.net'; + $hints[] = '//static.criteo.net'; + $hints[] = '//ib.adnxs.com'; + $hints[] = '//aax.amazon-adsystem.com'; + $hints[] = '//bidder.criteo.com'; + $hints[] = '//cas.criteo.com'; + $hints[] = '//gum.criteo.com'; + $hints[] = '//ads.pubmatic.com'; + $hints[] = '//gads.pubmatic.com'; + $hints[] = '//tpc.googlesyndication.com'; + $hints[] = '//ad.doubleclick.net'; + $hints[] = '//googleads.g.doubleclick.net'; + $hints[] = '//www.googletagservices.com'; + $hints[] = '//cdn.switchadhub.com'; + $hints[] = '//delivery.g.switchadhub.com'; + $hints[] = '//delivery.swid.switchadhub.com'; + } + + return $hints; + } + /** * IPONWEB metadata used by the various scripts * @@ -300,21 +330,13 @@ function insert_head_iponweb() { } $data_tags = ( $this->params->cloudflare ) ? ' data-cfasync="false"' : ''; echo << - - - - - - - - - - - - - - + + (function(){function g(a,c){a:{for(var b=a.length,d="string"==typeof a?a.split(""):a,e=0;ec?null:"string"==typeof a?a.charAt(c):a[c]};function h(a,c,b){b=null!=b?"="+encodeURIComponent(String(b)):"";if(c+=b){b=a.indexOf("#");0>b&&(b=a.length);var d=a.indexOf("?");if(0>d||d>b){d=b;var e=""}else e=a.substring(d+1,b);a=[a.substr(0,d),e,a.substr(b)];b=a[1];a[1]=c?b?b+"&"+c:c:b;a=a[0]+(a[1]?"?"+a[1]:"")+a[2]}return a};var k=0;function l(a,c){var b=document.createElement("script");b.src=a;b.onload=function(){c&&c(void 0)};b.onerror=function(){c("error")};a=document.getElementsByTagName("head");var d;a&&0!==a.length?d=a[0]:d=document.documentElement;d.appendChild(b)}function m(a){return"string"==typeof a&&0 HTML; }