Skip to content
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

AMP Support for Cookies and Consent #15722

Merged
merged 4 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 18 additions & 10 deletions modules/widgets/eu-cookie-law.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,19 @@ function __construct() {
*/
function enqueue_frontend_scripts() {
wp_enqueue_style( 'eu-cookie-law-style', plugins_url( 'eu-cookie-law/style.css', __FILE__ ), array(), '20170403' );
jeherve marked this conversation as resolved.
Show resolved Hide resolved
wp_enqueue_script(
'eu-cookie-law-script',
Assets::get_file_url_for_environment(
'_inc/build/widgets/eu-cookie-law/eu-cookie-law.min.js',
'modules/widgets/eu-cookie-law/eu-cookie-law.js'
),
array(),
'20180522',
true
);

if ( ! Jetpack_AMP_Support::is_amp_request() ) {
jeherve marked this conversation as resolved.
Show resolved Hide resolved
wp_enqueue_script(
'eu-cookie-law-script',
Assets::get_file_url_for_environment(
'_inc/build/widgets/eu-cookie-law/eu-cookie-law.min.js',
'modules/widgets/eu-cookie-law/eu-cookie-law.js'
),
array(),
'20180522',
true
);
}
}

/**
Expand Down Expand Up @@ -156,6 +159,11 @@ public function widget( $args, $instance ) {

$instance = wp_parse_args( $instance, $this->defaults() );

if ( Jetpack_AMP_Support::is_amp_request() ) {
jeherve marked this conversation as resolved.
Show resolved Hide resolved
require dirname( __FILE__ ) . '/eu-cookie-law/widget-amp.php';
return;
}

$classes = array();
$classes['hide'] = 'hide-on-' . esc_attr( $instance['hide'] );
if ( 'negative' === $instance['color-scheme'] ) {
Expand Down
10 changes: 10 additions & 0 deletions modules/widgets/eu-cookie-law/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
top: 3em;
}

amp-consent.widget_eu_cookie_law_widget.widget.top {
top: 1em;
margin: 0;
}

.admin-bar amp-consent.widget_eu_cookie_law_widget.widget.top {
top: 0;
margin-top: 5rem;
jeherve marked this conversation as resolved.
Show resolved Hide resolved
}

#eu-cookie-law {
background-color: #fff;
border: 1px solid #dedede;
Expand Down
38 changes: 38 additions & 0 deletions modules/widgets/eu-cookie-law/widget-amp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
/**
* AMP Widget for Cookies and Consent.
*
* @package Jetpack
*/
?>

<amp-consent id="eu-cookie-consent" layout="nodisplay" class="widget widget_eu_cookie_law_widget<?php echo esc_attr( ! empty( $instance['position'] ) && 'top' === $instance['position'] ? ' top' : '' ); ?>">
<script type="application/json">
{
"consentInstanceId": "eu-cookie-consent",
"consentRequired": true,
"promptUI": "eu-cookie-consent-prompt"
}
</script>
<div class="popupOverlay" id="eu-cookie-consent-prompt">
<div class="consentPopup<?php echo esc_attr( ! empty( $instance['color-scheme'] ) && 'negative' === $instance['color-scheme'] ? ' negative' : '' ); ?>" id="eu-cookie-law">
<form>
<input type="button" on="tap:eu-cookie-consent.accept" class="accept" value="<?php echo esc_attr( $instance['button'] ); ?>" />
</form>
<?php
if ( 'default' === $instance['text'] || empty( $instance['customtext'] ) ) {
echo wp_kses_post( nl2br( $instance['default-text'] ) );
} else {
echo esc_html( $instance['customtext'] );
}

$policy_link_text = 'default' === $instance['policy-url'] || empty( $instance['custom-policy-url'] )
? $instance['default-policy-url']
: $instance['custom-policy-url'];
?>
<a href="<?php echo esc_url( $policy_link_text ); ?>">
<?php echo esc_html( $instance['policy-link-text'] ); ?>
</a>
</div>
</div>
</amp-consent>