This repository was archived by the owner on Jan 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Add support for sticky ad #62
Open
deepaklalwani97
wants to merge
16
commits into
develop
Choose a base branch
from
feature/add-sticky-ad-support
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
265b0dc
Add support for sticky ad
deepaklalwani97 2833e93
Add size for all devices
deepaklalwani97 61e98f3
Fix phpcs
deepaklalwani97 88428a5
Fix phpcs ignore comment
deepaklalwani97 6dc8bd3
Fix phpcs ignore comment
deepaklalwani97 3d699d5
Update sizes for devices
deepaklalwani97 11a3f8f
Move sticky ad script to amp-resources template
deepaklalwani97 abc1f34
Add get_sticky_ad method and code optimizations
deepaklalwani97 fbcdbaf
Add doc block for get_sticky_ad method
deepaklalwani97 5692787
Add script only if sticky ads enabled
deepaklalwani97 0b0d106
Remove extra new line
deepaklalwani97 a01995b
Merge branch 'develop' of github.com:rtCamp/amp-admanager into featur…
deepaklalwani97 f581041
Fix amp validation error for amp-ad layout attribute
deepaklalwani97 656ba7b
Modify get_sticky_ad function to use height and width attributes
deepaklalwani97 b58e586
Add setting fields for height and width for sticky ad
deepaklalwani97 bf6a6b1
Use height and width setting fields to apply height and width to ad
deepaklalwani97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,8 @@ public function __construct() { | |
| */ | ||
| add_action( 'wp_head', [ $this, 'load_amp_resources' ], 0 ); | ||
|
|
||
| add_action( 'wp_footer', [ $this, 'add_sticky_amp_ad' ] ); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -183,21 +185,38 @@ private static function get_amp_ad( $attr ) { | |
| */ | ||
| $ad_arefresh_rate = ( isset( $attr['ad-refresh'] ) && (int) $attr['ad-refresh'] >= 30 ) ? (int) $attr['ad-refresh'] : false; | ||
|
|
||
| /** | ||
| * amp-ad markup. | ||
| */ | ||
| $ad_html = sprintf( | ||
| '<amp-ad width="%s" height="%s" media="%s" type="doubleclick" data-slot="%s" json=\'%s\' data-multi-size="%s" data-multi-size-validation="false" layout="%s" data-loading-strategy="%s" data-enable-refresh=%s></amp-ad>', | ||
| esc_attr( $attr['width'] ), | ||
| esc_attr( $attr['height'] ), | ||
| esc_attr( $media_query ), | ||
| esc_attr( $data_slot ), | ||
| esc_attr( $targeting_data_json ), | ||
| esc_attr( $attr['sizes'] ), | ||
| esc_attr( $layout ), | ||
| esc_attr( $data_loading_strategy ), | ||
| esc_attr( $ad_arefresh_rate ) | ||
| ); | ||
| if ( ! empty( $attr['sticky'] ) && true === $attr['sticky'] ) { | ||
|
deepaklalwani97 marked this conversation as resolved.
|
||
| /** | ||
| * Amp-sticky-ad markup. | ||
| */ | ||
| $ad_html = sprintf( | ||
| '<amp-sticky-ad layout="nodisplay"> <amp-ad width="%s" height="%s" media="%s" type="doubleclick" data-slot="%s" json=\'%s\' data-multi-size="%s" data-multi-size-validation="false" data-loading-strategy="%s" data-enable-refresh=%s></amp-ad> </amp-sticky-ad>', | ||
| esc_attr( $attr['width'] ), | ||
| esc_attr( $attr['height'] ), | ||
| esc_attr( $media_query ), | ||
| esc_attr( $data_slot ), | ||
| esc_attr( $targeting_data_json ), | ||
| esc_attr( $attr['sizes'] ), | ||
| esc_attr( $data_loading_strategy ), | ||
| esc_attr( $ad_arefresh_rate ) | ||
| ); | ||
| } else { | ||
| /** | ||
| * Amp-ad markup. | ||
| */ | ||
| $ad_html = sprintf( | ||
| '<amp-ad width="%s" height="%s" media="%s" type="doubleclick" data-slot="%s" json=\'%s\' data-multi-size="%s" data-multi-size-validation="false" layout="%s" data-loading-strategy="%s" data-enable-refresh=%s></amp-ad>', | ||
| esc_attr( $attr['width'] ), | ||
| esc_attr( $attr['height'] ), | ||
| esc_attr( $media_query ), | ||
| esc_attr( $data_slot ), | ||
| esc_attr( $targeting_data_json ), | ||
| esc_attr( $attr['sizes'] ), | ||
| esc_attr( $layout ), | ||
| esc_attr( $data_loading_strategy ), | ||
| esc_attr( $ad_arefresh_rate ) | ||
| ); | ||
| } | ||
|
|
||
| return $ad_html; | ||
| } | ||
|
|
@@ -430,4 +449,30 @@ public function load_amp_resources() { | |
|
|
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Add amp sticky ad to the footer. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function add_sticky_amp_ad() { | ||
|
|
||
| if ( empty( self::$amp_settings['amp_admanager_enable_sticky_ads'] ) || '1' !== self::$amp_settings['amp_admanager_enable_sticky_ads'] ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( empty( self::$amp_settings['amp_admanager_sticky_ad_unit'] ) ) { | ||
| return; | ||
| } | ||
|
|
||
| $ad_attr = [ | ||
| 'ad-unit' => self::$amp_settings['amp_admanager_sticky_ad_unit'], | ||
| 'desktop-sizes' => '600x90,728x90', | ||
| 'tablet-sizes' => '320x50,468x60', | ||
| 'mobile-sizes' => '320x50,468x60', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sizes should be dynamic instead of static, right? I see the discussion is going on #59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes sizes should be dynamic, and override with these |
||
| 'sticky' => true, | ||
| ]; | ||
|
|
||
| self::get_ads( $ad_attr, true ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,8 @@ | |
| </style> | ||
| </noscript> | ||
| <link rel="preload" as="script" href="https://cdn.ampproject.org/v0.js"> | ||
|
|
||
| <?php //phpcs:disable ?> | ||
| <script type="text/javascript" src="https://cdn.ampproject.org/v0.js" async></script> | ||
|
deepaklalwani97 marked this conversation as resolved.
|
||
| <script async custom-element="amp-sticky-ad" src="https://cdn.ampproject.org/v0/amp-sticky-ad-1.0.js"></script> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a check here if sticky ad is enabled, then only include this script. |
||
| <?php //phpcs:enable ?> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.