ZiziCache Hooks and Filters Developer Guide

Updated on 12. 6. 2025

Developer Integration Overview

ZiziCache provides a comprehensive collection of hooks and filters that enable developers to customize and extend plugin functionality. This developer guide covers all available integration points, customization examples, and best practices for extending ZiziCache.

Action Hooks

Cache Management Hooks

Cache Purge Actions

// Fired before cache purge
do_action('zizi_cache_before_purge', $type, $urls);
// Fired after cache purge
do_action('zizi_cache_after_purge', $type, $urls, $success);
// Fired before preload starts
do_action('zizi_cache_before_preload', $urls);
// Fired after preload completes
do_action('zizi_cache_after_preload', $urls, $success_count, $failed_count);

Usage Examples

// Custom action after cache purge
add_action('zizi_cache_after_purge', function($type, $urls, $success) {
    if ($success && $type === 'pages') {
        // Send notification to monitoring service
        wp_remote_post('https://monitoring.example.com/cache-purged', [
            'body' => json_encode([
                'site' => home_url(),
                'type' => $type,
                'timestamp' => current_time('mysql')
            ])
        ]);
    }
});
// Custom preload notification
add_action('zizi_cache_after_preload', function($urls, $success_count, $failed_count) {
    error_log(sprintf(
        'Cache preload completed: %d successful, %d failed out of %d total URLs',
        $success_count,
        $failed_count,
        count($urls)
    ));
});

Optimization Hooks

CSS/JS Processing

// Before CSS minification
do_action('zizi_cache_before_css_minify', $css_content, $file_path);
// After CSS minification
do_action('zizi_cache_after_css_minify', $minified_css, $original_css, $file_path);
// Before JS minification
do_action('zizi_cache_before_js_minify', $js_content, $file_path);
// After JS minification
do_action('zizi_cache_after_js_minify', $minified_js, $original_js, $file_path);

Font Optimization Hooks

// Before font optimization
do_action('zizi_cache_before_font_optimize', $font_url, $font_family);
// After font optimization
do_action('zizi_cache_after_font_optimize', $optimized_font, $original_font);
// Font Intelligence analysis complete
do_action('zizi_cache_font_intelligence_complete', $analysis_results);

Image Optimization Hooks

// Before image lazy loading
do_action('zizi_cache_before_image_lazyload', $img_tag, $src);
// After image optimization
do_action('zizi_cache_after_image_optimize', $optimized_img, $original_img);
// LCP detection complete
do_action('zizi_cache_lcp_detected', $lcp_element, $device_type);

Configuration Hooks

Settings Updates

// Before settings save
do_action('zizi_cache_before_save_settings', $new_settings, $old_settings);
// After settings save
do_action('zizi_cache_after_save_settings', $settings, $updated_keys);
// Configuration validation
do_action('zizi_cache_validate_config', $config, $errors);

Filter Hooks

Cache Control Filters

Cache Exclusions

// Modify cache exclusion URLs
apply_filters('zizi_cache_exclude_urls', $exclude_urls);
// Modify cache exclusion cookies
apply_filters('zizi_cache_exclude_cookies', $exclude_cookies);
// Modify cache exclusion user agents
apply_filters('zizi_cache_exclude_user_agents', $exclude_agents);
// Custom cache bypass logic
apply_filters('zizi_cache_should_cache', $should_cache, $url, $request);

Usage Examples

// Exclude WooCommerce cart/checkout from cache
add_filter('zizi_cache_exclude_urls', function($urls) {
    $wc_urls = [
        '/cart/*',
        '/checkout/*',
        '/my-account/*',
        '?add-to-cart=*'
    ];
    return array_merge($urls, $wc_urls);
});
// Exclude logged-in users from cache
add_filter('zizi_cache_should_cache', function($should_cache, $url, $request) {
    if (is_user_logged_in()) {
        return false;
    }
    return $should_cache;
}, 10, 3);

Optimization Filters

CSS/JS Optimization

// Modify CSS before minification
apply_filters('zizi_cache_css_before_minify', $css_content, $file_path);
// Modify minified CSS
apply_filters('zizi_cache_css_after_minify', $minified_css, $original_css);
// Exclude CSS files from minification
apply_filters('zizi_cache_css_minify_excludes', $exclude_files);
// Modify JS before minification
apply_filters('zizi_cache_js_before_minify', $js_content, $file_path);
// Exclude JS files from processing
apply_filters('zizi_cache_js_exclude_files', $exclude_files);

Advanced CSS Filters

// Remove unused CSS selectors filter
apply_filters('zizi_cache_rucss_selectors', $selectors, $url);
// Critical CSS generation
apply_filters('zizi_cache_critical_css', $critical_css, $url, $device);
// CSS loading method
apply_filters('zizi_cache_css_loading_method', $method, $file_path);

Usage Examples

// Add custom CSS optimization
add_filter('zizi_cache_css_after_minify', function($css, $original) {
    // Add custom CSS variables
    $custom_vars = ':root { --brand-color: #007cba; }';
    return $custom_vars . $css;
}, 10, 2);
// Exclude theme CSS from minification
add_filter('zizi_cache_css_minify_excludes', function($excludes) {
    $excludes[] = 'my-theme-style.css';
    $excludes[] = 'custom-styles.css';
    return $excludes;
});

Font Optimization Filters

Font Processing

// Modify font URLs before optimization
apply_filters('zizi_cache_font_urls', $font_urls);
// Customize font display values
apply_filters('zizi_cache_font_display', $display_value, $font_family);
// Font preload priority
apply_filters('zizi_cache_font_preload_priority', $priority, $font_url);
// Font Intelligence exclusions
apply_filters('zizi_cache_font_intelligence_exclude', $exclude_patterns);

Usage Examples

// Prioritize brand fonts for preload
add_filter('zizi_cache_font_preload_priority', function($priority, $font_url) {
    if (strpos($font_url, 'brand-font') !== false) {
        return 'high';
    }
    return $priority;
}, 10, 2);
// Custom font display strategy
add_filter('zizi_cache_font_display', function($display, $family) {
    $critical_fonts = ['Open Sans', 'Roboto'];
    if (in_array($family, $critical_fonts)) {
        return 'swap';
    }
    return 'optional';
}, 10, 2);

Image Optimization Filters

Image Processing

// Modify lazy loading threshold
apply_filters('zizi_cache_lazyload_threshold', $threshold);
// Exclude images from lazy loading
apply_filters('zizi_cache_lazyload_exclude', $exclude_patterns);
// Responsive image breakpoints
apply_filters('zizi_cache_responsive_breakpoints', $breakpoints);
// LCP element detection
apply_filters('zizi_cache_lcp_selectors', $selectors, $device_type);

Usage Examples

// Exclude hero images from lazy loading
add_filter('zizi_cache_lazyload_exclude', function($excludes) {
    $excludes[] = '.hero-image';
    $excludes[] = '.header-logo';
    $excludes[] = '.above-fold';
    return $excludes;
});
// Custom responsive breakpoints
add_filter('zizi_cache_responsive_breakpoints', function($breakpoints) {
    return [
        320,   // Mobile
        768,   // Tablet
        1024,  // Desktop
        1440,  // Large Desktop
        1920   // Extra Large
    ];
});

Database Optimization Hooks

Database Cleanup Filters

// Customize cleanup intervals
apply_filters('zizi_cache_db_cleanup_intervals', $intervals);
// Exclude tables from optimization
apply_filters('zizi_cache_db_exclude_tables', $exclude_tables);
// Custom cleanup actions
apply_filters('zizi_cache_db_cleanup_actions', $actions);

Index Recommendations

// Filter index recommendations
apply_filters('zizi_cache_db_index_recommendations', $recommendations);
// Custom index creation
do_action('zizi_cache_db_before_index_creation', $table, $index_name);
do_action('zizi_cache_db_after_index_creation', $table, $index_name, $success);

Performance Monitoring Hooks

Metrics Collection

// Filter performance metrics
apply_filters('zizi_cache_performance_metrics', $metrics);
// Custom metric calculation
apply_filters('zizi_cache_calculate_metric', $value, $metric_name, $data);
// Performance thresholds
apply_filters('zizi_cache_performance_thresholds', $thresholds);

Usage Examples

// Add custom performance metric
add_filter('zizi_cache_performance_metrics', function($metrics) {
    $metrics['custom_load_time'] = [
        'value' => microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'],
        'unit' => 'seconds',
        'threshold' => 2.0
    ];
    return $metrics;
});
// Custom performance analysis
add_filter('zizi_cache_calculate_metric', function($value, $metric_name, $data) {
    if ($metric_name === 'database_efficiency') {
        // Custom database efficiency calculation
        $queries = $data['query_count'] ?? 0;
        $time = $data['query_time'] ?? 0;
        return $queries > 0 ? ($time / $queries) : 0;
    }
    return $value;
}, 10, 3);

CDN Integration Hooks

CDN URL Rewriting

// Modify CDN URL
apply_filters('zizi_cache_cdn_url', $cdn_url, $original_url, $file_type);
// CDN exclusions
apply_filters('zizi_cache_cdn_excludes', $exclude_patterns);
// CDN headers
apply_filters('zizi_cache_cdn_headers', $headers, $file_type);

Usage Examples

// Use different CDN for images
add_filter('zizi_cache_cdn_url', function($cdn_url, $original_url, $file_type) {
    if (in_array($file_type, ['jpg', 'jpeg', 'png', 'gif', 'webp'])) {
        return 'https://images-cdn.example.com';
    }
    return $cdn_url;
}, 10, 3);
// Exclude admin assets from CDN
add_filter('zizi_cache_cdn_excludes', function($excludes) {
    $excludes[] = '/wp-admin/*';
    $excludes[] = '/wp-includes/js/*';
    return $excludes;
});

REST API Hooks

API Response Filters

// Filter API responses
apply_filters('zizi_cache_api_response', $response, $endpoint, $request);
// API authentication
apply_filters('zizi_cache_api_auth', $is_authenticated, $request);
// API rate limiting
apply_filters('zizi_cache_api_rate_limit', $limit, $endpoint, $user);

Custom API Endpoints

// Register custom API endpoints
do_action('zizi_cache_register_api_endpoints', $namespace);
// API endpoint validation
apply_filters('zizi_cache_validate_api_request', $is_valid, $request, $endpoint);

Advanced Customization Examples

Custom Cache Implementation

class CustomCacheHandler {
    public function __construct() {
        add_filter('zizi_cache_should_cache', [$this, 'customCacheLogic'], 10, 3);
        add_action('zizi_cache_after_purge', [$this, 'onCachePurge'], 10, 3);
    }
    public function customCacheLogic($should_cache, $url, $request) {
        // Custom caching logic based on user role
        $user = wp_get_current_user();
        if (in_array('premium_member', $user->roles)) {
            // Cache longer for premium members
            add_filter('zizi_cache_lifetime', function($lifetime) {
                return $lifetime * 2;
            });
        }
        return $should_cache;
    }
    public function onCachePurge($type, $urls, $success) {
        if ($success && $type === 'everything') {
            // Warm critical pages immediately
            $critical_pages = [
                home_url(),
                home_url('/products/'),
                home_url('/contact/')
            ];
            foreach ($critical_pages as $page) {
                wp_remote_get($page);
            }
        }
    }
}
new CustomCacheHandler();

Performance Monitoring Integration

class PerformanceMonitor {
    public function __construct() {
        add_filter('zizi_cache_performance_metrics', [$this, 'addCustomMetrics']);
        add_action('zizi_cache_after_preload', [$this, 'trackPreloadPerformance'], 10, 3);
    }
    public function addCustomMetrics($metrics) {
        // Add custom business metrics
        $metrics['conversion_rate'] = $this->calculateConversionRate();
        $metrics['user_engagement'] = $this->calculateEngagement();
        return $metrics;
    }
    public function trackPreloadPerformance($urls, $success_count, $failed_count) {
        $performance_data = [
            'total_urls' => count($urls),
            'success_rate' => ($success_count / count($urls)) * 100,
            'completion_time' => current_time('mysql'),
            'site_url' => home_url()
        ];
        // Send to external monitoring service
        wp_remote_post('https://monitoring.example.com/performance', [
            'body' => json_encode($performance_data),
            'headers' => ['Content-Type' => 'application/json']
        ]);
    }
    private function calculateConversionRate() {
        // Custom conversion rate calculation
        return 3.2; // Example value
    }
    private function calculateEngagement() {
        // Custom engagement calculation
        return 85.5; // Example value
    }
}
new PerformanceMonitor();

Dynamic Configuration

class DynamicConfiguration {
    public function __construct() {
        add_filter('zizi_cache_config', [$this, 'modifyConfig'], 10, 2);
        add_filter('zizi_cache_exclude_urls', [$this, 'dynamicExclusions']);
    }
    public function modifyConfig($config, $context) {
        // Adjust configuration based on server load
        $load = sys_getloadavg()[0];
        if ($load > 5.0) {
            // High load: reduce optimization intensity
            $config['css_minify'] = false;
            $config['js_minify'] = false;
            $config['img_preload'] = false;
        }
        // Adjust based on time of day
        $hour = (int) current_time('H');
        if ($hour >= 9 && $hour <= 17) {
            // Business hours: aggressive caching
            $config['cacheLifetimeHours'] = 6;
        } else {
            // Off-hours: shorter cache for fresh content
            $config['cacheLifetimeHours'] = 2;
        }
        return $config;
    }
    public function dynamicExclusions($excludes) {
        // Exclude URLs based on current promotions
        $active_promotions = get_option('active_promotions', []);
        foreach ($active_promotions as $promo) {
            $excludes[] = '/promo/' . $promo['slug'] . '/*';
        }
        return $excludes;
    }
}
new DynamicConfiguration();

Hook Reference Quick Guide

Most Commonly Used Hooks

Hook Type Description
zizi_cache_exclude_urls Filter Modify cache exclusion URLs
zizi_cache_should_cache Filter Control caching decisions
zizi_cache_after_purge Action Execute after cache purge
zizi_cache_css_minify_excludes Filter Exclude CSS from minification
zizi_cache_js_exclude_files Filter Exclude JS from processing
zizi_cache_lazyload_exclude Filter Exclude images from lazy loading
zizi_cache_performance_metrics Filter Add custom performance metrics

Best Practices

Performance Considerations

  • Efficient Filtering: Use specific conditions to avoid unnecessary processing
  • Caching Integration: Ensure custom code doesn't break caching
  • Error Handling: Always include proper error handling in custom code
  • Testing: Thoroughly test custom implementations

Code Quality

  • Follow WordPress Standards: Use WordPress coding standards
  • Namespace Functions: Prevent naming conflicts
  • Documentation: Document custom implementations
  • Version Compatibility: Ensure compatibility with plugin updates

Security

  • Validate Input: Always validate and sanitize input data
  • Capability Checks: Verify user permissions
  • Escape Output: Properly escape output data
  • Nonce Verification: Use nonces for form submissions

ZiziCache's extensive hook system provides powerful customization capabilities for developers. These hooks enable seamless integration with existing workflows, custom functionality implementation, and advanced performance optimization strategies tailored to specific requirements.

What are your feelings