Add consent reopener: floating widget + anchor link trigger

Allow visitors to reopen the cookie preferences modal after making
their choice via a configurable floating button (bottom-right or
right-side vertical) or any anchor link with href="#att-cc-preferences".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-16 06:13:55 +00:00
parent 6bf9f553de
commit 4adda0ded7
6 changed files with 174 additions and 48 deletions

View File

@@ -164,6 +164,12 @@ class ATT_Consent_Admin {
$settings['consent_mode'] = in_array( $_POST['consent_mode'] ?? '', array( 'advanced', 'basic' ), true ) ? $_POST['consent_mode'] : 'advanced';
$settings['banner_position'] = in_array( $_POST['banner_position'] ?? '', array( 'bottom', 'top', 'center' ), true ) ? $_POST['banner_position'] : 'bottom';
$settings['consent_expiry'] = absint( $_POST['consent_expiry'] ?? 365 );
$settings['floating_widget'] = in_array(
$_POST['floating_widget'] ?? '',
array( 'bottom-right', 'right', 'none' ),
true
) ? $_POST['floating_widget'] : 'bottom-right';
$settings['floating_widget_label'] = sanitize_text_field( $_POST['floating_widget_label'] ?? '' );
break;
case 'appearance':

View File

@@ -29,8 +29,10 @@ class ATT_Consent {
'ga4_measurement_id' => '',
'gtm_container_id' => '',
'consent_mode' => 'advanced',
'banner_position' => 'bottom',
'consent_expiry' => 365,
'banner_position' => 'bottom',
'consent_expiry' => 365,
'floating_widget' => 'bottom-right',
'floating_widget_label' => 'Cookie Settings',
// Appearance.
'banner_bg_color' => '#1a1a2e',

View File

@@ -284,7 +284,14 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
</div>
</div>';
$html = apply_filters( 'att_consent_banner_html', $banner_html . $modal_html, $s );
$widget_html = '';
if ( 'none' !== $s['floating_widget'] ) {
$widget_position = 'right' === $s['floating_widget'] ? 'att-cc-widget--right' : 'att-cc-widget--bottom-right';
$widget_label = ! empty( $s['floating_widget_label'] ) ? $s['floating_widget_label'] : 'Cookie Settings';
$widget_html = '<button type="button" id="att-cc-widget" class="att-cc-widget ' . esc_attr( $widget_position ) . '" aria-label="' . esc_attr( $widget_label ) . '" style="display:none;' . $style_vars . '"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2zm0 18a8 8 0 1 1 8-8 8 8 0 0 1-8 8zm-1-13a1.5 1.5 0 1 1-1.5-1.5A1.5 1.5 0 0 1 11 7zm4 2a1 1 0 1 1-1-1 1 1 0 0 1 1 1zm-7 3a1 1 0 1 1-1-1 1 1 0 0 1 1 1zm3 4a1.5 1.5 0 1 1-1.5-1.5A1.5 1.5 0 0 1 11 16zm5-1a1 1 0 1 1-1-1 1 1 0 0 1 1 1z"/></svg> ' . esc_html( $widget_label ) . '</button>';
}
$html = apply_filters( 'att_consent_banner_html', $banner_html . $modal_html . $widget_html, $s );
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped above.
do_action( 'att_consent_after_banner' );