diff --git a/projects/plugins/jetpack/changelog/update-iponweb-to-watl-migration b/projects/plugins/jetpack/changelog/update-iponweb-to-watl-migration index bd85e9ccf4478..57bf248955ab6 100644 --- a/projects/plugins/jetpack/changelog/update-iponweb-to-watl-migration +++ b/projects/plugins/jetpack/changelog/update-iponweb-to-watl-migration @@ -2,3 +2,4 @@ Significance: patch Type: other Migration from IPONWEB to WATL +* Render legacy sidebar widget with the WATL diff --git a/projects/plugins/jetpack/modules/wordads/class-wordads.php b/projects/plugins/jetpack/modules/wordads/class-wordads.php index 0d389e87c806e..9d796910a78aa 100644 --- a/projects/plugins/jetpack/modules/wordads/class-wordads.php +++ b/projects/plugins/jetpack/modules/wordads/class-wordads.php @@ -774,7 +774,7 @@ public function get_dynamic_ad_snippet( $section_id, $form_factor = 'square', $l // Allow overriding and printing of the tag parsed by the WATL. // phpcs:disable WordPress.Security.NonceVerification.Recommended - $is_location_enabled = ( isset( $_GET[ $location ] ) && 'true' === $_GET[ $location ] ); + $is_location_enabled = isset( $_GET['wordads-logging'] ) && isset( $_GET[ $location ] ) && 'true' === $_GET[ $location ]; if ( ( 'top' === $location || 'belowpost' === $location ) && $is_location_enabled ) { // TODO: Confirm if it's best here or there is a way to get it via the adflow config endpoint diff --git a/projects/plugins/jetpack/modules/wordads/php/class-wordads-sidebar-widget.php b/projects/plugins/jetpack/modules/wordads/php/class-wordads-sidebar-widget.php index 7b1b7b5f6de77..63cb75ceebe3b 100644 --- a/projects/plugins/jetpack/modules/wordads/php/class-wordads-sidebar-widget.php +++ b/projects/plugins/jetpack/modules/wordads/php/class-wordads-sidebar-widget.php @@ -19,6 +19,17 @@ class WordAds_Sidebar_Widget extends WP_Widget { */ private static $allowed_tags = array( 'mrec', 'wideskyscraper', 'leaderboard' ); + /** + * Mapping array of widget sizes with the WordAds_Smart formats. + * + * @var string[] + */ + private static $sizes_x_smart_format = array( + '300x250' => 'sidebar_widget_mediumrectangle', + '728x90' => 'sidebar_widget_leaderboard', + '160x600' => 'sidebar_widget_wideskyscraper', + ); + /** * Number of widgets. * @@ -74,7 +85,6 @@ public function widget( $args, $instance ) { } ++self::$num_widgets; - $about = __( 'Advertisements', 'jetpack' ); $width = WordAds::$ad_tag_ids[ $instance['unit'] ]['width']; $height = WordAds::$ad_tag_ids[ $instance['unit'] ]['height']; $unit_id = 1 === self::$num_widgets ? 3 : self::$num_widgets + 3; // 2nd belowpost is '4' @@ -82,7 +92,50 @@ public function widget( $args, $instance ) { WORDADS_API_TEST_ID : $wordads->params->blog_id . $unit_id; - $snippet = ''; + $smart_format = self::$sizes_x_smart_format[ "{$width}x{$height}" ]; + // phpcs:disable WordPress.Security.NonceVerification.Recommended + $is_watl_enabled = isset( $_GET['wordads-logging'] ) && isset( $_GET[ $smart_format ] ) && 'true' === $_GET[ $smart_format ]; + + // Get the widget snippet. + $widget_snippet = $this->get_widget_snippet( $instance, $section_id, $height, $width ); + + // Render the IPW or house ad if WATL is disabled. + if ( ! $is_watl_enabled ) { + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo $widget_snippet; + return; + } + + // Remove linebreaks and sanitize. + $tag = esc_js( str_replace( array( "\n", "\t", "\r" ), '', $widget_snippet ) ); + + // Add the fallback to be processed by WATL. + $fallback_snippet = << + var sas_fallback = sas_fallback || []; + sas_fallback.push( + { tag: "$tag", type: '$smart_format' } + ); + +HTML; + + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo $fallback_snippet . $wordads::get_watl_ad_html_tag( $smart_format ); + } + + /** + * The widget snippet. + * + * @param array $instance The widget instance. + * @param string $section_id The section id. + * @param int $height The ad height. + * @param int $width The ad width. + * + * @return string + */ + private function get_widget_snippet( $instance, $section_id, $height, $width ) { + global $wordads; + if ( $wordads->option( 'wordads_house', true ) ) { $unit = 'mrec'; if ( 'leaderboard' === $instance['unit'] && ! $this->params->mobile_device ) { @@ -93,21 +146,22 @@ public function widget( $args, $instance ) { $snippet = $wordads->get_house_ad( $unit ); } else { - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - echo $wordads->get_ad_snippet( $section_id, $height, $width, 'widget' ); - return; + return $wordads->get_ad_snippet( $section_id, $height, $width, 'widget' ); } - ?> + $about = __( 'Advertisements', 'jetpack' ); + $unit = esc_attr( $instance['unit'] ); + + return <<
- -
- + $about +
+ $snippet
- array( + 'top' => array( 'enabled' => false, ), - 'inline' => array( + 'inline' => array( 'enabled' => false, ), - 'belowpost' => array( + 'belowpost' => array( 'enabled' => false, ), - 'bottom_sticky' => array( + 'bottom_sticky' => array( 'enabled' => false, ), - 'sidebar_sticky_right' => array( + 'sidebar_sticky_right' => array( 'enabled' => false, ), - 'gutenberg_rectangle' => array( + 'gutenberg_rectangle' => array( 'enabled' => false, ), - 'gutenberg_leaderboard' => array( + 'gutenberg_leaderboard' => array( 'enabled' => false, ), - 'gutenberg_mobile_leaderboard' => array( + 'gutenberg_mobile_leaderboard' => array( 'enabled' => false, ), - 'gutenberg_skyscraper' => array( + 'gutenberg_skyscraper' => array( + 'enabled' => false, + ), + 'sidebar_widget_mediumrectangle' => array( + 'enabled' => false, + ), + 'sidebar_widget_leaderboard' => array( + 'enabled' => false, + ), + 'sidebar_widget_wideskyscraper' => array( 'enabled' => false, ), );