Skip to content

Support Gutenberg Ad block for Aditude #43476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions projects/plugins/jetpack/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
// PhanTypeArraySuspicious : 20+ occurrences
// PhanTypeMismatchDimFetch : 20+ occurrences
// PhanSuspiciousMagicConstant : 15+ occurrences
// PhanTypeExpectedObjectPropAccessButGotNull : 15+ occurrences
// PhanTypeMismatchPropertyDefault : 15+ occurrences
// PhanTypeSuspiciousNonTraversableForeach : 15+ occurrences
// PhanPluginDuplicateExpressionAssignmentOperation : 10+ occurrences
Expand All @@ -56,7 +55,6 @@
// PhanCommentAbstractOnInheritedMethod : 6 occurrences
// PhanDeprecatedClass : 5 occurrences
// PhanImpossibleCondition : 5 occurrences
// PhanNonClassMethodCall : 5 occurrences
// PhanTypeMismatchDimAssignment : 5 occurrences
// PhanAccessMethodInternal : 4 occurrences
// PhanTypeInvalidLeftOperandOfAdd : 4 occurrences
Expand All @@ -72,6 +70,7 @@
// PhanTypeObjectUnsetDeclaredProperty : 3 occurrences
// PhanUndeclaredMethodInCallable : 3 occurrences
// PhanImpossibleConditionInLoop : 2 occurrences
// PhanNonClassMethodCall : 2 occurrences
// PhanParamTooMany : 2 occurrences
// PhanParamTooManyCallable : 2 occurrences
// PhanPluginDuplicateSwitchCaseLooseEquality : 2 occurrences
Expand Down Expand Up @@ -192,7 +191,7 @@
'extensions/blocks/story/story.php' => ['PhanImpossibleCondition', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable'],
'extensions/blocks/subscriptions/subscriptions.php' => ['PhanPluginDuplicateConditionalNullCoalescing'],
'extensions/blocks/top-posts/top-posts.php' => ['PhanTypeMismatchReturnProbablyReal'],
'extensions/blocks/wordads/wordads.php' => ['PhanNonClassMethodCall', 'PhanTypeExpectedObjectPropAccessButGotNull', 'PhanTypeMismatchArgument'],
'extensions/blocks/wordads/wordads.php' => ['PhanTypeMismatchArgument'],
'extensions/plugins/sharing/sharing.php' => ['PhanRedundantCondition'],
'functions.compat.php' => ['PhanRedefineFunction'],
'functions.global.php' => ['PhanRedefineFunction', 'PhanRedundantCondition', 'PhanSuspiciousMagicConstant', 'PhanTypeMismatchArgument'],
Expand Down Expand Up @@ -447,11 +446,11 @@
'modules/woocommerce-analytics/classes/class-jetpack-woocommerce-analytics-my-account.php' => ['PhanDeprecatedFunction', 'PhanDeprecatedTrait'],
'modules/woocommerce-analytics/classes/class-jetpack-woocommerce-analytics-trait.php' => ['PhanDeprecatedFunction', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanUndeclaredMethod'],
'modules/woocommerce-analytics/classes/class-jetpack-woocommerce-analytics-universal.php' => ['PhanDeprecatedFunction', 'PhanDeprecatedTrait', 'PhanPluginRedundantAssignment'],
'modules/wordads/class-wordads.php' => ['PhanNonClassMethodCall', 'PhanPluginRedundantAssignment', 'PhanTypeExpectedObjectPropAccessButGotNull', 'PhanTypeMismatchArgument', 'PhanTypeMismatchPropertyProbablyReal'],
'modules/wordads/class-wordads.php' => ['PhanPluginRedundantAssignment', 'PhanTypeMismatchArgument'],
'modules/wordads/php/class-wordads-admin.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'modules/wordads/php/class-wordads-api.php' => ['PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'],
'modules/wordads/php/class-wordads-params.php' => ['PhanTypeMismatchReturn'],
'modules/wordads/php/class-wordads-sidebar-widget.php' => ['PhanTypeExpectedObjectPropAccessButGotNull', 'PhanTypeMismatchArgument'],
'modules/wordads/php/class-wordads-sidebar-widget.php' => ['PhanTypeMismatchArgument'],
'sal/class.json-api-date.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanRedundantCondition', 'PhanTypeMismatchArgumentInternalProbablyReal'],
'sal/class.json-api-links.php' => ['PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'],
'sal/class.json-api-post-base.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanRedundantCondition', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturnNullable', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypePossiblyInvalidDimOffset', 'PhanTypeSuspiciousNonTraversableForeach'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

WordAds: Support Gutenberg Ad block for Aditude
49 changes: 48 additions & 1 deletion projects/plugins/jetpack/modules/wordads/class-wordads.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WordAds {
/**
* Ads parameters.
*
* @var null
* @var WordAds_Params
*/
public $params = null;

Expand Down Expand Up @@ -269,8 +269,12 @@ public static function is_infinite_scroll() {
*/
private function insert_adcode() {
add_filter( 'wp_resource_hints', array( $this, 'resource_hints' ), 10, 2 );

// These 'wp_head' actions add the IPONWEB JavaScript snippets to the page.
// We need to remove them whenever
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' ) );
add_filter( 'wordads_ads_txt', array( $this, 'insert_custom_adstxt' ) );

Expand Down Expand Up @@ -738,6 +742,12 @@ public function get_ad_snippet( $section_id, $height, $width, $location = '', $c
}

$loc_id = esc_js( $loc_id );

$format = $this->get_wordads_format( (int) $width, (int) $height );
if ( $format === '' ) {
return '';
}

return <<<HTML
<div style="padding-bottom:15px;width:{$width}px;height:{$height}px;$css">
<div id="atatags-{$ad_number}">
Expand All @@ -751,6 +761,15 @@ public function get_ad_snippet( $section_id, $height, $width, $location = '', $c
height: {$height}
});
});
if ( '{$format}' !== '' ) {
window.tudeMappings = window.tudeMappings || [];
window.tudeMappings.push( {
divId: 'atatags-{$ad_number}',
format: '{$format}',
width: {$width},
height: {$height},
} );
}
</script>
</div>
</div>
Expand All @@ -767,6 +786,34 @@ public function get_ad_snippet( $section_id, $height, $width, $location = '', $c
return $this->get_dynamic_ad_snippet( $section_id, $form_factor, $location );
}

/**
* Determine the WordAds format based on the ad dimensions.
*
* @param int $width The width of the ad slot.
* @param int $height The height of the ad slot.
*
* @return string WordAds Format enum.
*/
private function get_wordads_format( int $width, int $height ): string {
if ( $width === 300 && $height === 250 ) {
return 'gutenberg_rectangle';
}

if ( $width === 728 && $height === 90 ) {
return 'gutenberg_leaderboard';
}

if ( $width === 320 && $height === 50 ) {
return 'gutenberg_mobile_leaderboard';
}

if ( $width === 160 && $height === 600 ) {
return 'gutenberg_skyscraper';
}

return '';
}

/**
* Returns the dynamic snippet to be inserted into the ad unit
*
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/unauth-file-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function handle_file_download() {

// Output file content and exit
echo $file['content']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Binary file data
exit;
exit( 0 );
}

/**
Expand Down
Loading