Skip to content

Commit 10493ef

Browse files
committed
Use text from settings in the Cookie banner
1 parent 9cb9a74 commit 10493ef

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

eu-cookie-law.php

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class EU_Cookie_Law_Widget extends WP_Widget {
1414

15-
public $defaults = array();
15+
public $defaults = array(), $instance;
1616

1717
function __construct() {
1818
parent::__construct(
@@ -30,28 +30,45 @@ function __construct() {
3030
'customtext' => '',
3131
'policyurl' => 'default',
3232
'custompolicyurl' => '',
33+
'policylinktext' => __( 'Our Cookie Policy' ),
34+
'button' => __( 'Close and accept' ),
3335
);
3436
}
3537

3638
public function widget( $args, $instance ) {
37-
$instance = wp_parse_args( $instance, $this->defaults );
39+
$this->instance = wp_parse_args( $instance, $this->defaults );
40+
3841
echo $args['before_widget'];
3942
echo $args['after_widget'];
4043
add_action( 'wp_footer', array( $this, 'footer' ) );
4144
}
4245

4346
public function footer() {
47+
$instance = $this->instance;
48+
?>
49+
<div id="eu-cookie-law" style="position: fixed; bottom: 0; left: 0; right: 0; height: 8em; background-color: #fff; padding: 2em">
50+
<button class="dismiss" style="float: right; margin-right: 3em"><?php echo esc_html( $instance['button'] ); ?></button>
51+
<div style="margin-right: 30%">
52+
<?php
53+
if ( $instance['text'] == 'default' || empty( $instance['customtext'] ) ) {
54+
echo __('Privacy & Cookies: This site uses cookies from WordPress.com and selected partners. By browsing you consent to their use. To find out more, as well as how to remove or block these, see here:' );
4455

45-
echo <<<FOOTER
46-
<div id="eu-cookie-law" style="position: fixed; bottom: 0; left: 0; right: 0; height: 195px; background-color: #fff">
47-
<img src="https://dotcom.files.wordpress.com/2015/06/cookie2.gif?w=520&h=390" align="middle" /> <button class="dismiss">Dismiss</button>
56+
} else {
57+
echo esc_html( $instance['customtext'] );
58+
}
59+
?>
60+
61+
<a href="<?php echo esc_attr( empty( $instance['url'] ) ? 'https://en.support.wordpress.com/cookies' : $instance['url'] ); ?>"><?php
62+
echo esc_html( $instance['policylinktext'] );
63+
?></a>
64+
</div>
4865
</div>
4966
<script type="text/javascript">
5067
jQuery( '#eu-cookie-law button.dismiss').on( 'click', function() {
5168

5269
});
5370
</script>
54-
FOOTER;
71+
<?php
5572
}
5673

5774

@@ -65,7 +82,7 @@ public function form( $instance ) {
6582
<label><input type="radio" name="<?php echo $this->get_field_name( 'hide' ); ?>" value="button" <?php checked( $instance['hide'], 'button' ); ?> /> <?php _e( 'after the user clicks the dismiss button' ); ?></label>
6683
</li>
6784
<li>
68-
<label><input type="radio" name="<?php echo $this->get_field_name( 'hide' ); ?>" value="scroll" <?php checked( $instance['hide'], 'scroll' ); ?> /> <?php _e( 'after the user scrolls the page' ); ?></label><br />
85+
<label><input type="radio" name="<?php echo $this->get_field_name( 'hide' ); ?>" value="scroll" <?php checked( $instance['hide'], 'scroll' ); ?> /> <?php _e( 'after the user scrolls the page' ); ?></label>
6986
</li>
7087
<li>
7188
<label><input type="radio" name="<?php echo $this->get_field_name( 'hide' ); ?>" value="time" <?php checked( $instance['hide'], 'time' ); ?> /> <?php _e( 'after this amount of time:' ); ?></label> <input type="number" name="<?php echo $this->get_field_name( 'hidetime' ); ?>" value="<?php echo esc_attr( $instance['hidetime'] ); ?>" style="width: 3em" /> <?php _e( 'seconds' ); ?>
@@ -80,7 +97,7 @@ public function form( $instance ) {
8097
<label><input type="radio" name="<?php echo $this->get_field_name( 'text' ); ?>" value="default" <?php checked( $instance['text'], 'default' ); ?> /> <?php _e( 'Default' ); ?></label>
8198
</li>
8299
<li>
83-
<label><input type="radio" name="<?php echo $this->get_field_name( 'text' ); ?>" value="custom" <?php checked( $instance['text'], 'custom' ); ?> /> <?php _e( 'Custom:' ); ?></label><br/>
100+
<label><input type="radio" name="<?php echo $this->get_field_name( 'text' ); ?>" value="custom" <?php checked( $instance['text'], 'custom' ); ?> /> <?php _e( 'Custom:' ); ?></label>
84101
</li>
85102
</ul>
86103
<textarea class="widefat" name="<?php echo $this->get_field_name( 'customtext' ); ?>"><?php echo esc_html( $instance['customtext'] ); ?></textarea>
@@ -93,10 +110,17 @@ public function form( $instance ) {
93110
<label><input type="radio" name="<?php echo $this->get_field_name( 'policyurl' ); ?>" value="default" <?php checked( $instance['policyurl'], 'default' ); ?> /> <?php _e( 'Default' ); ?></label>
94111
</li>
95112
<li>
96-
<label><input type="radio" name="<?php echo $this->get_field_name( 'policyurl' ); ?>" value="custom" <?php checked( $instance['policyurl'], 'custom' ); ?> /> <?php _e( 'Custom:' ); ?></label> <input type="text" class="widefat" name="<?php echo $this->get_field_name( 'custompolicyurl' ); ?>" placeholder="http://" style="margin-top: .5em" value="<?php echo esc_attr( $instance['custompolicyurl'] ); ?>" /><br/>
113+
<label><input type="radio" name="<?php echo $this->get_field_name( 'policyurl' ); ?>" value="custom" <?php checked( $instance['policyurl'], 'custom' ); ?> /> <?php _e( 'Custom:' ); ?></label> <input type="text" class="widefat" name="<?php echo $this->get_field_name( 'custompolicyurl' ); ?>" placeholder="http://" style="margin-top: .5em" value="<?php echo esc_attr( $instance['custompolicyurl'] ); ?>" />
97114
</li>
98115
</ul>
99-
116+
</p>
117+
<p>
118+
<strong><?php _e( 'Policy Link Text' ); ?></strong>
119+
<label><input type="text" class="widefat" name="<?php echo $this->get_field_name( 'policylinktext' ); ?>"value="<?php echo esc_attr( $instance['policylinktext'] ); ?>" />
120+
<hr />
121+
<p>
122+
<strong><?php _e( 'Button text' ); ?></strong>
123+
<label><input type="text" class="widefat" name="<?php echo $this->get_field_name( 'button' ); ?>"value="<?php echo esc_attr( $instance['button'] ); ?>" /></label>
100124
</p>
101125

102126
<?php
@@ -137,6 +161,22 @@ public function update( $new_instance, $old_instance ) {
137161
$instance['policyurl'] = 'default';
138162
}
139163

164+
if ( isset( $new_instance['policylinktext'] ) ) {
165+
$instance['policylinktext'] = trim( mb_substr( $new_instance['policylinktext'], 0, 100 ) );
166+
}
167+
168+
if ( empty( $instance['policylinktext'] ) || $instance['button'] == $this->defaults['policylinktext'] ) {
169+
unset( $instance['policylinktext'] );
170+
}
171+
172+
if ( isset( $new_instance['button'] ) ) {
173+
$instance['button'] = trim( mb_substr( $new_instance['button'], 0, 100 ) );
174+
}
175+
176+
if ( empty( $instance['button'] ) || $instance['button'] == $this->defaults['button'] ) {
177+
unset( $instance['button'] );
178+
}
179+
140180
return $instance;
141181
}
142182
}

0 commit comments

Comments
 (0)