From c05176e428a91dfa156e3d579222d15f7c5f455a Mon Sep 17 00:00:00 2001 From: Jaroslav Polakovic Date: Sat, 22 Feb 2020 14:18:49 +0100 Subject: [PATCH 1/3] Insert the top ad using vanilla JS instead of jQuery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For some(†) legacy themes the top ad is dynamically moved to a better position using JavaScript. This commit rewrites the funcionality to use vanilla JavaScript instead of depending on jQuery. † twentyseventeen, twentyfifteen, twentyfourteen --- modules/wordads/wordads.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/wordads/wordads.php b/modules/wordads/wordads.php index fee0520df18ab..28092776ccc8c 100644 --- a/modules/wordads/wordads.php +++ b/modules/wordads/wordads.php @@ -423,7 +423,7 @@ function insert_header_ad() { } /** - * Special cases for inserting header unit via jQuery + * Special cases for inserting header unit via JS * * @since 4.5.0 */ @@ -459,7 +459,15 @@ function insert_header_ad_special() { if ( ! self::is_amp() ) { echo << - jQuery('.wpcnt-header').insertBefore('$selector'); + (function ( selector ) { + var main = document.querySelector( selector ); + var headerAd = document.querySelector('.wpcnt-header'); + + if ( main ) { + main.parentNode.insertBefore( headerAd, main ); + } + })( '$selector' ); + HTML; } From 96f89131228cd82de6d3f35189190f7e50d533dc Mon Sep 17 00:00:00 2001 From: Jaroslav Polakovic Date: Tue, 25 Feb 2020 10:03:34 +0100 Subject: [PATCH 2/3] Fix the top ad insertion for twentyfourteen --- modules/wordads/wordads.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/wordads/wordads.php b/modules/wordads/wordads.php index 28092776ccc8c..68436d1d1693c 100644 --- a/modules/wordads/wordads.php +++ b/modules/wordads/wordads.php @@ -450,7 +450,7 @@ function insert_header_ad_special() { $selector = '#main'; break; case 'twentyfourteen': - $selector = 'article:first'; + $selector = 'article'; break; } @@ -723,3 +723,5 @@ public static function activate() { global $wordads; $wordads = new WordAds(); + + From 2be199dcfafd470375c5000c0b27f09ec4939e92 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Tue, 25 Feb 2020 08:38:10 -0600 Subject: [PATCH 3/3] Minor CS tweaks while we're in the file --- modules/wordads/wordads.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/wordads/wordads.php b/modules/wordads/wordads.php index 68436d1d1693c..b887b97bdaafd 100644 --- a/modules/wordads/wordads.php +++ b/modules/wordads/wordads.php @@ -70,6 +70,7 @@ class WordAds { /** * Checks for AMP support and returns true iff active & AMP request + * * @return boolean True if supported AMP request * * @since 7.5.0 @@ -108,6 +109,7 @@ function option( $option, $default = false ) { /** * Returns the ad tag property array for supported ad types. + * * @return array array with ad tags * * @since 7.1.0 @@ -118,6 +120,7 @@ function get_ad_tags() { /** * Returns the solo css for unit + * * @return string the special css for solo units * * @since 7.1.0 @@ -596,7 +599,7 @@ public function get_ad_snippet( $section_id, $height, $width, $location = '', $c $ad_number = count( $this->ads ) . '-' . uniqid(); $data_tags = $this->params->cloudflare ? ' data-cfasync="false"' : ''; - $css = esc_attr( $css ); + $css = esc_attr( $css ); $loc_id = 100; if ( ! empty( self::$ad_location_ids[ $location ] ) ) { @@ -625,10 +628,10 @@ public function get_ad_snippet( $section_id, $height, $width, $location = '', $c /** * Returns the complete ad div with snippet to be inserted into the page * - * @param string $spot top, side, inline, or belowpost - * @param string $snippet The snippet to insert into the div - * @param array $css_classes - * @return string The supporting ad unit div + * @param string $spot top, side, inline, or belowpost. + * @param string $snippet The snippet to insert into the div. + * @param array $css_classes CSS classes. + * @return string The supporting ad unit div. * * @since 7.1 */ @@ -642,9 +645,9 @@ function get_ad_div( $spot, $snippet, array $css_classes = array() ) { $css_classes[] = 'wpcnt-header'; } - $spot = esc_attr( $spot ); + $spot = esc_attr( $spot ); $classes = esc_attr( implode( ' ', $css_classes ) ); - $about = esc_html__( 'Advertisements', 'jetpack' ); + $about = esc_html__( 'Advertisements', 'jetpack' ); return <<
@@ -723,5 +726,3 @@ public static function activate() { global $wordads; $wordads = new WordAds(); - -