<?php
/**
 * FormShield Badge Customization Examples
 * 
 * This file shows how to customize the protected badge functionality
 * using WordPress filters.
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Example 1: Change allowed roles for badge visibility
 * 
 * By default: administrator, editor, shop_manager
 * This example adds 'author' role and removes 'shop_manager'
 */
add_filter('formshield_badge_allowed_roles', function($roles) {
    // Remove shop_manager
    $roles = array_diff($roles, array('shop_manager'));
    
    // Add author
    $roles[] = 'author';
    
    return $roles;
});

/**
 * Example 2: Change badge text
 * 
 * By default: "🔒 Protected by FormShield"
 * This example changes it to a custom message
 */
add_filter('formshield_badge_text', function($text) {
    return '🛡️ Secured with FormShield';
});

/**
 * Example 3: Add custom role-based badge text
 * 
 * Different text for different user roles
 */
add_filter('formshield_badge_text', function($text) {
    if (current_user_can('administrator')) {
        return '🔒 Admin: Protected by FormShield';
    } elseif (current_user_can('editor')) {
        return '🔒 Editor: Protected by FormShield';
    } elseif (current_user_can('author')) {
        return '🔒 Author: Protected by FormShield';
    }
    
    return $text; // Default text for other roles
});

/**
 * Example 4: Completely disable badges for specific conditions
 * 
 * Hide badges on mobile devices or specific pages
 */
add_filter('formshield_badge_allowed_roles', function($roles) {
    // Disable badges on mobile
    if (wp_is_mobile()) {
        return array(); // Empty array = no roles can see badges
    }
    
    // Disable badges on specific pages
    if (is_page('contact') || is_page('about')) {
        return array(); // Empty array = no roles can see badges
    }
    
    return $roles;
});

/**
 * Example 5: Add custom CSS classes to badges
 * 
 * This requires modifying the badge_html method in formshield.php
 * to accept additional CSS classes via filter
 */
add_filter('formshield_badge_css_classes', function($classes) {
    $classes[] = 'custom-badge-class';
    $classes[] = 'my-theme-badge';
    
    return $classes;
});

/**
 * Example 6: Conditional badge display based on form type
 * 
 * Different badges for different form types
 */
add_filter('formshield_badge_text', function($text, $form_name) {
    switch ($form_name) {
        case 'Contact Form 7':
            return '📧 Contact Form Protected';
        case 'Divi Contact Form':
            return '🎨 Divi Form Protected';
        case 'WordPress Comments':
            return '💬 Comments Protected';
        default:
            return $text;
    }
}, 10, 2);

/**
 * Example 7: Add badge only for premium users
 * 
 * Show badges only to users with specific capabilities
 */
add_filter('formshield_badge_allowed_roles', function($roles) {
    // Only show to users who can manage options (usually admins)
    if (!current_user_can('manage_options')) {
        return array(); // No roles can see badges
    }
    
    return $roles;
});

/**
 * Example 8: Custom badge styling via CSS
 * 
 * Add this to your theme's style.css or via wp_add_inline_style
 */
function custom_formshield_badge_styles() {
    if (FormShield::should_show_badge()) {
        $css = '
        .formshield-protected-badge {
            background: linear-gradient(45deg, #667eea 0%, #764ba2 100%) !important;
            color: white !important;
            font-weight: bold !important;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.3) !important;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
        }
        ';
        
        wp_add_inline_style('wp-block-library', $css);
    }
}
add_action('wp_enqueue_scripts', 'custom_formshield_badge_styles');
