← All changes
|
modules/widgets/class-jetpack-eu-cookie-law-widget.php
+25
-12
12.2.3
→
16.3-a.1
View file →
| @@ -10,9 +10,9 @@ | ||
| 10 | 10 | /** |
| 11 | 11 | * Disable direct access/execution to/of the widget code. |
| 12 | 12 | */ |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | - exit; | |
| 14 | + exit( 0 ); | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | if ( ! class_exists( 'Jetpack_EU_Cookie_Law_Widget' ) ) { |
| 18 | 18 | /** |
| @@ -92,12 +92,8 @@ | ||
| 92 | 92 | 'customize_selective_refresh' => true, |
| 93 | 93 | ), |
| 94 | 94 | array() |
| 95 | 95 | ); |
| 96 | - | |
| 97 | - if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) { | |
| 98 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_scripts' ) ); | |
| 99 | - } | |
| 100 | 96 | } |
| 101 | 97 | |
| 102 | 98 | /** |
| 103 | 99 | * Enqueue scripts and styles. |
| @@ -139,9 +135,14 @@ | ||
| 139 | 135 | 'custom-policy-url' => get_option( 'wp_page_for_privacy_policy' ) ? get_permalink( (int) get_option( 'wp_page_for_privacy_policy' ) ) : '', |
| 140 | 136 | 'position' => $this->position_options[0], |
| 141 | 137 | 'policy-link-text' => esc_html__( 'Cookie Policy', 'jetpack' ), |
| 142 | 138 | 'button' => esc_html__( 'Close and accept', 'jetpack' ), |
| 143 | - 'default-text' => esc_html__( "Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use. \r\nTo find out more, including how to control cookies, see here:", 'jetpack' ), | |
| 139 | + 'default-text' => esc_html__( | |
| 140 | + 'Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use. | |
| 141 | + | |
| 142 | +To find out more, including how to control cookies, see here:', | |
| 143 | + 'jetpack' | |
| 144 | + ), | |
| 144 | 145 | ); |
| 145 | 146 | } |
| 146 | 147 | |
| 147 | 148 | /** |
| @@ -146,8 +147,11 @@ | ||
| 146 | 147 | |
| 147 | 148 | /** |
| 148 | 149 | * Front-end display of the widget. |
| 149 | 150 | * |
| 151 | + * @html-template-var array $instance | |
| 152 | + * @html-template-var array<string,string> $classes | |
| 153 | + * | |
| 150 | 154 | * @param array $args Widget arguments. |
| 151 | 155 | * @param array $instance Saved values from database. |
| 152 | 156 | */ |
| 153 | 157 | public function widget( $args, $instance ) { |
| @@ -161,8 +165,11 @@ | ||
| 161 | 165 | if ( apply_filters( 'jetpack_disable_eu_cookie_law_widget', false ) ) { |
| 162 | 166 | return; |
| 163 | 167 | } |
| 164 | 168 | |
| 169 | + // Enqueue front end assets. | |
| 170 | + $this->enqueue_frontend_scripts(); | |
| 171 | + | |
| 165 | 172 | $instance = wp_parse_args( $instance, $this->defaults() ); |
| 166 | 173 | |
| 167 | 174 | if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { |
| 168 | 175 | require __DIR__ . '/eu-cookie-law/widget-amp.php'; |
| @@ -211,9 +218,12 @@ | ||
| 211 | 218 | |
| 212 | 219 | /** |
| 213 | 220 | * Back-end widget form. |
| 214 | 221 | * |
| 222 | + * @html-template-var array $instance | |
| 223 | + * | |
| 215 | 224 | * @param array $instance Previously saved values from database. |
| 225 | + * @return string|void | |
| 216 | 226 | */ |
| 217 | 227 | public function form( $instance ) { |
| 218 | 228 | $instance = wp_parse_args( $instance, $this->defaults() ); |
| 219 | 229 | if ( Jetpack::is_module_active( 'wordads' ) ) { |
| @@ -244,13 +254,13 @@ | ||
| 244 | 254 | public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 245 | 255 | $instance = array(); |
| 246 | 256 | $defaults = $this->defaults(); |
| 247 | 257 | |
| 248 | - $instance['hide'] = $this->filter_value( isset( $new_instance['hide'] ) ? $new_instance['hide'] : '', $this->hide_options ); | |
| 249 | - $instance['text'] = $this->filter_value( isset( $new_instance['text'] ) ? $new_instance['text'] : '', $this->text_options ); | |
| 250 | - $instance['color-scheme'] = $this->filter_value( isset( $new_instance['color-scheme'] ) ? $new_instance['color-scheme'] : '', $this->color_scheme_options ); | |
| 251 | - $instance['policy-url'] = $this->filter_value( isset( $new_instance['policy-url'] ) ? $new_instance['policy-url'] : '', $this->policy_url_options ); | |
| 252 | - $instance['position'] = $this->filter_value( isset( $new_instance['position'] ) ? $new_instance['position'] : '', $this->position_options ); | |
| 258 | + $instance['hide'] = $this->filter_value( $new_instance['hide'] ?? '', $this->hide_options ); | |
| 259 | + $instance['text'] = $this->filter_value( $new_instance['text'] ?? '', $this->text_options ); | |
| 260 | + $instance['color-scheme'] = $this->filter_value( $new_instance['color-scheme'] ?? '', $this->color_scheme_options ); | |
| 261 | + $instance['policy-url'] = $this->filter_value( $new_instance['policy-url'] ?? '', $this->policy_url_options ); | |
| 262 | + $instance['position'] = $this->filter_value( $new_instance['position'] ?? '', $this->position_options ); | |
| 253 | 263 | |
| 254 | 264 | if ( isset( $new_instance['hide-timeout'] ) ) { |
| 255 | 265 | // Time can be a value between 3 and 1000 seconds. |
| 256 | 266 | $instance['hide-timeout'] = min( 1000, max( 3, (int) $new_instance['hide-timeout'] ) ); |
| @@ -303,9 +313,12 @@ | ||
| 303 | 313 | unset( $instance['button'] ); |
| 304 | 314 | } |
| 305 | 315 | |
| 306 | 316 | // Show the banner again if a setting has been changed. |
| 307 | - setcookie( self::$cookie_name, '', time() - 86400, '/', COOKIE_DOMAIN, is_ssl(), false ); // phpcs:ignore Jetpack.Functions.SetCookie -- Fine to have accessible. | |
| 317 | + // Sometimes plugins send headers already, so we can't set a cookie and any attempt will throw a warning. | |
| 318 | + if ( ! headers_sent() ) { | |
| 319 | + setcookie( self::$cookie_name, '', time() - 86400, '/', COOKIE_DOMAIN, is_ssl(), false ); // phpcs:ignore Jetpack.Functions.SetCookie -- Fine to have accessible. | |
| 320 | + } | |
| 308 | 321 | |
| 309 | 322 | return $instance; |
| 310 | 323 | } |
| 311 | 324 | |