summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/widgets/eu-cookie-law.php')
-rw-r--r--plugins/jetpack/modules/widgets/eu-cookie-law.php54
1 files changed, 40 insertions, 14 deletions
diff --git a/plugins/jetpack/modules/widgets/eu-cookie-law.php b/plugins/jetpack/modules/widgets/eu-cookie-law.php
index 27ffa9a3..fffc9724 100644
--- a/plugins/jetpack/modules/widgets/eu-cookie-law.php
+++ b/plugins/jetpack/modules/widgets/eu-cookie-law.php
@@ -98,17 +98,20 @@ if ( ! class_exists( 'Jetpack_EU_Cookie_Law_Widget' ) ) {
* Enqueue scripts and styles.
*/
function enqueue_frontend_scripts() {
- wp_enqueue_style( 'eu-cookie-law-style', plugins_url( 'eu-cookie-law/style.css', __FILE__ ), array(), '20170403' );
- 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( 'jquery' ),
- '20180522',
- true
- );
+ wp_enqueue_style( 'eu-cookie-law-style', plugins_url( 'eu-cookie-law/style.css', __FILE__ ), array(), JETPACK__VERSION );
+
+ if ( ! class_exists( 'Jetpack_AMP_Support' ) || ! Jetpack_AMP_Support::is_amp_request() ) {
+ 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
+ );
+ }
}
/**
@@ -156,6 +159,11 @@ if ( ! class_exists( 'Jetpack_EU_Cookie_Law_Widget' ) ) {
$instance = wp_parse_args( $instance, $this->defaults() );
+ if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
+ 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'] ) {
@@ -171,9 +179,27 @@ if ( ! class_exists( 'Jetpack_EU_Cookie_Law_Widget' ) ) {
$classes['hide'] = 'hide-on-button';
}
+ /**
+ * Check if widget is loaded in widgets.php.
+ *
+ * @return string widget Static version of the widget for better preview.
+ */
+ global $pagenow;
+ if ( 'widgets.php' === $pagenow ) {
+ // To prevent the widget from being added as a pop-up
+ // we do not echo the before and after $args. Instead we wrap
+ // it in a dummy `div` and return before the `widget_view` is
+ // added to stats.
+ echo '<div id="eu-cookie-law" style="padding: 0;margin: 5px">';
+ require_once __DIR__ . '/eu-cookie-law/widget.php';
+ echo '</div>';
+ return;
+ }
+
echo $args['before_widget'];
- require( dirname( __FILE__ ) . '/eu-cookie-law/widget.php' );
+ require_once __DIR__ . '/eu-cookie-law/widget.php';
echo $args['after_widget'];
+
/** This action is already documented in modules/widgets/gravatar-profile.php */
do_action( 'jetpack_stats_extra', 'widget_view', 'eu_cookie_law' );
}
@@ -221,12 +247,12 @@ if ( ! class_exists( 'Jetpack_EU_Cookie_Law_Widget' ) ) {
if ( isset( $new_instance['hide-timeout'] ) ) {
// Time can be a value between 3 and 1000 seconds.
- $instance['hide-timeout'] = min( 1000, max( 3, intval( $new_instance['hide-timeout'] ) ) );
+ $instance['hide-timeout'] = min( 1000, max( 3, (int) $new_instance['hide-timeout'] ) );
}
if ( isset( $new_instance['consent-expiration'] ) ) {
// Time can be a value between 1 and 365 days.
- $instance['consent-expiration'] = min( 365, max( 1, intval( $new_instance['consent-expiration'] ) ) );
+ $instance['consent-expiration'] = min( 365, max( 1, (int) $new_instance['consent-expiration'] ) );
}
if ( isset( $new_instance['customtext'] ) ) {