Skip to content

Commit

Permalink
[WordAds] Migrate wordads shortcode to WATL (#40599)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alameen688 authored Dec 19, 2024
1 parent 5b622dc commit f9711df
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
1 change: 0 additions & 1 deletion projects/plugins/jetpack/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
Original file line number Diff line number Diff line change
@@ -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

10 changes: 5 additions & 5 deletions projects/plugins/jetpack/extensions/blocks/wordads/wordads.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
Expand Down
17 changes: 15 additions & 2 deletions projects/plugins/jetpack/modules/wordads/class-wordads.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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(
'<div class="jetpack-wordad" itemscope itemtype="https://schema.org/WPAdBlock">%s</div>',
$this->get_ad( 'inline', $ad_type )
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
<?php
/**
* Wordads shortcode.
*
Expand All @@ -9,35 +9,23 @@
*/

/**
* Embed WordAds 'ad' in post
* Class WordAds_Shortcode
*
* Handles the [wordads] shortcode.
*/
class Jetpack_WordAds_Shortcode {

/**
* Used to determine whether scripts and styles have been enqueued already.
*
* @var bool false Should we enqueue scripts and styles.
*/
private $scripts_and_style_included = false;

/**
* Initialize.
*/
public function __construct() {
add_action( 'init', array( $this, 'action_init' ) );
}
class WordAds_Shortcode {

/**
* Register our shortcode and enqueue necessary files.
*/
public function action_init() {
public static function init() {
global $wordads;

if ( empty( $wordads ) ) {
return null;
}

add_shortcode( 'wordads', array( $this, 'wordads_shortcode' ) );
add_shortcode( 'wordads', array( self::class, 'handle_wordads_shortcode' ) );
}

/**
Expand All @@ -49,7 +37,7 @@ public function action_init() {
*
* @return string HTML for WordAds shortcode.
*/
public static function wordads_shortcode( $atts, $content = '' ) {
public static function handle_wordads_shortcode( $atts, $content = '' ) {
$atts = shortcode_atts( array(), $atts, 'wordads' );

return self::wordads_shortcode_html( $atts, $content );
Expand All @@ -70,11 +58,8 @@ private static function wordads_shortcode_html( $atts, $content = '' ) { // phpc
return '<div>' . __( 'The WordAds module is not active', 'jetpack' ) . '</div>';
}

$html = '<div class="jetpack-wordad" itemscope itemtype="https://schema.org/WPAdBlock"></div>';
$html = $wordads->insert_inline_ad( $html );
$html = $wordads->insert_inline_ad( '' );

return $html;
}
}

new Jetpack_WordAds_Shortcode();
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class WordAds_Smart {
'sidebar_widget_wideskyscraper' => array(
'enabled' => false,
),
'shortcode' => array(
'enabled' => false,
),
);

/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f9711df

Please sign in to comment.