Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Created September 17, 2025 12:20
Show Gist options
  • Save goranefbl/df10b1325e09b5f93d06ecae64658c32 to your computer and use it in GitHub Desktop.
Save goranefbl/df10b1325e09b5f93d06ecae64658c32 to your computer and use it in GitHub Desktop.
GDPR Compliant template
<?php
/**
* Points Page Template
*/
if (!defined('ABSPATH')) {
exit;
}
// Handle GDPR consent form submission
if (isset($_POST['gdpr_consent_submit']) && wp_verify_nonce($_POST['gdpr_consent_nonce'], 'gdpr_consent_action')) {
$user_id = get_current_user_id();
if ($user_id && isset($_POST['gdpr_consent']) && $_POST['gdpr_consent'] === 'yes') {
update_user_meta($user_id, 'gdpr_points_consent', 'yes');
update_user_meta($user_id, 'gdpr_consent_date', current_time('mysql'));
// Force redirect to clear POST data
wp_safe_redirect(get_permalink(get_queried_object_id()), 303);
exit;
}
}
// Check if user has given GDPR consent for points
$user_id = get_current_user_id();
$has_consent = false;
if ($user_id) {
$consent = get_user_meta($user_id, 'gdpr_points_consent', true);
$has_consent = ($consent === 'yes');
}
// Get block attributes
$block_attributes = isset($block_attributes) ? $block_attributes : array(
'showPointsBalance' => true,
'showEarningActions' => true,
'showRedemption' => true
);
// Get branding settings
$branding = WPGL_Points_Core::get_branding();
// Get redeem actions and check if any are enabled
$redeem_actions = WPGL_Points_Core::get_redeem_actions();
$has_enabled_redeems = !empty(array_filter($redeem_actions, function ($action) {
return isset($action['enabled']) && $action['enabled'];
}));
// Check if refer a friend earning is active
$earning_actions = WPGL_Points_Core::get_earning_actions();
$has_refer_friend_earning = !empty(array_filter($earning_actions, function ($action) {
return isset($action['type']) && $action['type'] === WPGL_Points_Source_Type::REFER_FRIEND && isset($action['enabled']) && $action['enabled'];
}));
// Get user's redeemed coupons
$points_redeem = new WPGL_Points_Redeem();
$user = wp_get_current_user();
$redeemed_coupons = $user->ID ? $points_redeem->get_user_redeemed_coupons() : array();
// Dynamic CSS based on branding settings
?>
<style>
.wpgens-loyalty-button,
.wpgens-loyalty-tabs span.tab-active,
.wpgens-loyalty-tabs span:hover,
.wpgens-loyalty-section-hero svg {
color: <?php echo esc_attr($branding['primary_color']);
?>;
}
.wpgens-loyalty-button {
background-color: <?php echo esc_attr($branding['primary_color']);
?>;
color: #fff;
}
.wpgens-loyalty-consent-form {
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 30px;
margin: 20px 0;
text-align: center;
}
.wpgens-loyalty-consent-form h3 {
margin-top: 0;
color: #333;
}
.wpgens-loyalty-consent-form p {
margin-bottom: 20px;
color: #666;
line-height: 1.6;
}
.wpgens-loyalty-consent-form .consent-options {
display: flex;
gap: 20px;
justify-content: center;
margin: 20px 0;
}
.wpgens-loyalty-consent-form .consent-option {
display: flex;
align-items: center;
gap: 8px;
}
.wpgens-loyalty-consent-form input[type="checkbox"] {
margin: 0;
}
.wpgens-loyalty-consent-form .consent-button {
background-color: <?php echo esc_attr($branding['primary_color']);
?>;
color: #fff;
border: none;
padding: 12px 24px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: opacity 0.3s;
}
.wpgens-loyalty-consent-form .consent-button:hover {
opacity: 0.9;
}
.wpgens-loyalty-consent-form .consent-button:disabled {
opacity: 0.6;
cursor: not-allowed;
}
</style>
<?php if (!$has_consent): ?>
<div class="wpgens-loyalty-consent-form">
<h3><?php echo esc_html__('Data Processing Consent', 'wpgens-points-and-rewards-program'); ?></h3>
<p><?php echo esc_html__('To participate in our loyalty points program, we need your consent to process your personal data for the purpose of tracking and managing your points balance, reward history, and related activities.', 'wpgens-points-and-rewards-program'); ?>
</p>
<form method="post" id="gdpr-consent-form">
<?php wp_nonce_field('gdpr_consent_action', 'gdpr_consent_nonce'); ?>
<div class="consent-options">
<div class="consent-option">
<input type="checkbox" id="gdpr_consent" name="gdpr_consent" value="yes" required>
<label
for="gdpr_consent"><?php echo esc_html__('I consent to the processing of my personal data for the loyalty points program', 'wpgens-points-and-rewards-program'); ?></label>
</div>
</div>
<button type="submit" name="gdpr_consent_submit" class="consent-button">
<?php echo esc_html__('Submit Consent', 'wpgens-points-and-rewards-program'); ?>
</button>
</form>
</div>
<script>
document.getElementById('gdpr-consent-form').addEventListener('submit', function(e) {
const consentCheckbox = document.querySelector('input[name="gdpr_consent"]');
if (!consentCheckbox || !consentCheckbox.checked) {
e.preventDefault();
alert(
'<?php echo esc_js(__('Please check the consent checkbox to proceed.', 'wpgens-points-and-rewards-program')); ?>'
);
return false;
}
});
</script>
<?php else: ?>
<div class="wpgens-loyalty-landing">
<section id="lgPoints" class="wpgens-loyalty-section">
<div class="wpgens-loyalty-container">
<section class="wpgens-loyalty-section-hero">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1"
stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round"
d="M16.5 6v.75m0 3v.75m0 3v.75m0 3V18m-9-5.25h5.25M7.5 15h3M3.375 5.25c-.621 0-1.125.504-1.125 1.125v3.026a2.999 2.999 0 010 5.198v3.026c0 .621.504 1.125 1.125 1.125h17.25c.621 0 1.125-.504 1.125-1.125v-3.026a2.999 2.999 0 010-5.198V6.375c0-.621-.504-1.125-1.125-1.125H3.375z" />
</svg>
<h2 class="wpgens-loyalty-section-title">
<?php echo esc_html(WPGL_Points_Core::parse_branding_placeholders($branding['title'])); ?></h2>
<div class="wpgens-loyalty-section-description">
<p><?php echo esc_html($branding['subtitle']); ?></p>
</div>
</section>
<div class="wpgens-loyalty-listing">
<div class="wpgens-loyalty-tabs">
<?php if ($block_attributes['showEarningActions']): ?>
<span tabindex="0" class="tab-active" role="button"
data-tab="earn"><?php echo esc_html__('Earn Points', 'wpgens-points-and-rewards-program'); ?></span>
<?php endif; ?>
<?php if ($block_attributes['showRedemption'] && $has_enabled_redeems): ?>
<span tabindex="0"
class="<?php echo !$block_attributes['showEarningActions'] ? 'tab-active' : ''; ?>"
role="button"
data-tab="redeem"><?php echo esc_html__('Redeem Points', 'wpgens-points-and-rewards-program'); ?></span>
<?php endif; ?>
<?php if (!empty($redeemed_coupons)): ?>
<span tabindex="0"
class="<?php echo (!$block_attributes['showEarningActions'] && !($block_attributes['showRedemption'] && $has_enabled_redeems)) ? 'tab-active' : ''; ?>"
role="button"
data-tab="rewards"><?php echo esc_html__('My Rewards', 'wpgens-points-and-rewards-program'); ?></span>
<?php endif; ?>
<?php if ($has_refer_friend_earning): ?>
<span tabindex="0"
class="<?php echo (!$block_attributes['showEarningActions'] && !($block_attributes['showRedemption'] && $has_enabled_redeems) && empty($redeemed_coupons) && !$block_attributes['showPointsBalance']) ? 'tab-active' : ''; ?>"
role="button"
data-tab="refer-a-friend"><?php echo esc_html__('Refer a Friend', 'wpgens-points-and-rewards-program'); ?></span>
<?php endif; ?>
<?php if ($block_attributes['showPointsBalance']): ?>
<span tabindex="0"
class="<?php echo (!$block_attributes['showEarningActions'] && !($block_attributes['showRedemption'] && $has_enabled_redeems) && empty($redeemed_coupons)) ? 'tab-active' : ''; ?>"
role="button"
data-tab="stats"><?php echo esc_html__('My Points', 'wpgens-points-and-rewards-program'); ?></span>
<?php endif; ?>
</div>
<?php
// Get plugin template directory
$plugin_template_dir = WP_PLUGIN_DIR . '/wpgens-points-and-rewards-program/templates/';
if ($block_attributes['showEarningActions']) {
include $plugin_template_dir . 'points-earn.php';
}
if ($block_attributes['showRedemption'] && $has_enabled_redeems) {
include $plugin_template_dir . 'points-redeem.php';
}
if (!empty($redeemed_coupons)) {
echo '<div data-tab-content="rewards">';
include $plugin_template_dir . 'points-rewards.php';
echo '</div>';
}
if ($has_refer_friend_earning) {
include $plugin_template_dir . 'refer-a-friend.php';
}
if ($block_attributes['showPointsBalance']) {
include $plugin_template_dir . 'points-stats.php';
}
?>
</div>
</div>
</section>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment