From f9711df9026405fefd90aa697beaf0d1ad0138ac Mon Sep 17 00:00:00 2001 From: Al-Ameen Ogundiran Date: Thu, 19 Dec 2024 21:42:58 +0000 Subject: [PATCH] [WordAds] Migrate wordads shortcode to WATL (#40599) --- projects/plugins/jetpack/.phan/baseline.php | 1 - .../update-iponweb-to-watl-migration | 4 +-- .../extensions/blocks/wordads/wordads.php | 10 +++--- .../jetpack/modules/wordads/class-wordads.php | 17 ++++++++-- .../php/class-wordads-shortcode.php} | 33 +++++-------------- .../wordads/php/class-wordads-smart.php | 4 +++ 6 files changed, 35 insertions(+), 34 deletions(-) rename projects/plugins/jetpack/modules/{shortcodes/wordads.php => wordads/php/class-wordads-shortcode.php} (57%) diff --git a/projects/plugins/jetpack/.phan/baseline.php b/projects/plugins/jetpack/.phan/baseline.php index d3614e00bc549..88c94fddb7e8e 100644 --- a/projects/plugins/jetpack/.phan/baseline.php +++ b/projects/plugins/jetpack/.phan/baseline.php @@ -381,7 +381,6 @@ 'modules/shortcodes/ustream.php' => ['PhanTypeMismatchArgument'], 'modules/shortcodes/vimeo.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument'], 'modules/shortcodes/vr.php' => ['PhanPluginDuplicateConditionalNullCoalescing'], - 'modules/shortcodes/wordads.php' => ['PhanNoopNew'], 'modules/shortcodes/youtube.php' => ['PhanRedefineFunction'], 'modules/shortlinks.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal'], 'modules/simple-payments/simple-payments.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturn'], diff --git a/projects/plugins/jetpack/changelog/update-iponweb-to-watl-migration b/projects/plugins/jetpack/changelog/update-iponweb-to-watl-migration index 57bf248955ab6..c66b2abb063ef 100644 --- a/projects/plugins/jetpack/changelog/update-iponweb-to-watl-migration +++ b/projects/plugins/jetpack/changelog/update-iponweb-to-watl-migration @@ -1,5 +1,5 @@ Significance: patch Type: other -Migration from IPONWEB to WATL -* Render legacy sidebar widget with the WATL +Migration of ad formats from IPONWEB to WATL + diff --git a/projects/plugins/jetpack/extensions/blocks/wordads/wordads.php b/projects/plugins/jetpack/extensions/blocks/wordads/wordads.php index 9107adf5cd600..e1d4b6ce3b8cc 100644 --- a/projects/plugins/jetpack/extensions/blocks/wordads/wordads.php +++ b/projects/plugins/jetpack/extensions/blocks/wordads/wordads.php @@ -139,12 +139,12 @@ public static function gutenblock_render( $attr ) { $format = $attr['format']; } - $height = $ad_tag_ids[ $format ]['height']; - $width = $ad_tag_ids[ $format ]['width']; - $gutenberg_location = 'gutenberg'; - $snippet = $wordads->get_ad_snippet( $section_id, $height, $width, $gutenberg_location, $wordads->get_solo_unit_css() ); + $height = $ad_tag_ids[ $format ]['height']; + $width = $ad_tag_ids[ $format ]['width']; + $location = 'gutenberg'; + $snippet = $wordads->get_ad_snippet( $section_id, $height, $width, $location, $wordads->get_solo_unit_css() ); - $key = "{$gutenberg_location}_{$width}x{$height}"; + $key = "{$location}_{$width}x{$height}"; $smart_format = self::$gutenberg_ad_snippet_x_smart_format[ $key ] ?? null; // phpcs:disable WordPress.Security.NonceVerification.Recommended $is_watl_enabled = $smart_format && ( isset( $_GET[ $smart_format ] ) && 'true' === $_GET[ $smart_format ] ); diff --git a/projects/plugins/jetpack/modules/wordads/class-wordads.php b/projects/plugins/jetpack/modules/wordads/class-wordads.php index 9d796910a78aa..81e0ed53afd3e 100644 --- a/projects/plugins/jetpack/modules/wordads/class-wordads.php +++ b/projects/plugins/jetpack/modules/wordads/class-wordads.php @@ -21,6 +21,7 @@ require_once WORDADS_ROOT . '/php/class-wordads-ccpa-do-not-sell-link-widget.php'; require_once WORDADS_ROOT . '/php/class-wordads-consent-management-provider.php'; require_once WORDADS_ROOT . '/php/class-wordads-smart.php'; +require_once WORDADS_ROOT . '/php/class-wordads-shortcode.php'; /** * Primary WordAds class. @@ -215,6 +216,9 @@ public function init() { WordAds_Consent_Management_Provider::init(); } + // Initialize [wordads] shortcode. + WordAds_Shortcode::init(); + // Initialize Smart. WordAds_Smart::instance()->init( $this->params ); @@ -527,8 +531,17 @@ public function insert_inline_ad( $content ) { } $ad_type = $this->option( 'wordads_house' ) ? 'house' : 'iponweb'; - $content .= $this->get_ad( 'inline', $ad_type ); - return $content; + $location = 'shortcode'; + // not house ad and watl enabled + // phpcs:disable WordPress.Security.NonceVerification.Recommended + if ( 'house' !== $ad_type && ( isset( $_GET['wordads-logging'] ) && isset( $_GET[ $location ] ) && 'true' === $_GET[ $location ] ) ) { + return $content . $this->get_watl_ad_html_tag( $location ); + } + + return $content .= sprintf( + '
%s
', + $this->get_ad( 'inline', $ad_type ) + ); } /** diff --git a/projects/plugins/jetpack/modules/shortcodes/wordads.php b/projects/plugins/jetpack/modules/wordads/php/class-wordads-shortcode.php similarity index 57% rename from projects/plugins/jetpack/modules/shortcodes/wordads.php rename to projects/plugins/jetpack/modules/wordads/php/class-wordads-shortcode.php index 5f91213e3a241..8a291771da916 100644 --- a/projects/plugins/jetpack/modules/shortcodes/wordads.php +++ b/projects/plugins/jetpack/modules/wordads/php/class-wordads-shortcode.php @@ -1,4 +1,4 @@ -' . __( 'The WordAds module is not active', 'jetpack' ) . ''; } - $html = '
'; - $html = $wordads->insert_inline_ad( $html ); + $html = $wordads->insert_inline_ad( '' ); return $html; } } - -new Jetpack_WordAds_Shortcode(); diff --git a/projects/plugins/jetpack/modules/wordads/php/class-wordads-smart.php b/projects/plugins/jetpack/modules/wordads/php/class-wordads-smart.php index 281b57cc6b3bc..3d1be487365d2 100644 --- a/projects/plugins/jetpack/modules/wordads/php/class-wordads-smart.php +++ b/projects/plugins/jetpack/modules/wordads/php/class-wordads-smart.php @@ -80,6 +80,9 @@ class WordAds_Smart { 'sidebar_widget_wideskyscraper' => array( 'enabled' => false, ), + 'shortcode' => array( + 'enabled' => false, + ), ); /** @@ -210,6 +213,7 @@ public function insert_config() { $config = array( 'post_id' => ( $post instanceof WP_Post ) && is_singular( 'post' ) ? $post->ID : null, + 'origin' => 'jetpack', 'theme' => get_stylesheet(), 'target' => $this->target_keywords(), ) + $this->formats;