Home / Admin / Charitable Email Preview Test – PHP 8.2
Duplicate Snippet

Embed Snippet on Your Site

Charitable Email Preview Test – PHP 8.2

Code Preview
php
<?php
<?php
/**
 * Charitable Email Preview Test - PHP 8.2
 *
 * Use this ONLY if email preview redirects to homepage on PHP 8.2
 *
 * WPCODE INSTRUCTIONS:
 * - Type: PHP Snippet
 * - Location: Run Everywhere
 * - Title: Charitable Preview Test - PHP 8.2
 */
// Fix 1: Force early email registration to prevent timing issues
add_action('init', function() {
    if (function_exists('charitable_get_helper')) {
        $emails_helper = charitable_get_helper('emails');
        if ($emails_helper && method_exists($emails_helper, 'register_emails')) {
            $emails_helper->register_emails();
        }
    }
}, 1); // Very early priority
// Fix 2: Override email preview handling completely
add_action('template_redirect', function() {
    // Only intercept email preview requests
    if (isset($_GET['charitable_action']) && $_GET['charitable_action'] === 'preview_email') {
        if (!isset($_GET['email_id'])) {
            wp_die('Missing email ID for preview.');
        }
        // Clean the email ID parameter
        $email_id = sanitize_key($_GET['email_id']);
        if (empty($email_id)) {
            wp_die('Invalid email ID provided.');
        }
        // Get the email system
        if (function_exists('charitable_get_helper')) {
            $emails_helper = charitable_get_helper('emails');
            if ($emails_helper) {
                // Force email registration if not already done
                if (method_exists($emails_helper, 'register_emails')) {
                    $emails_helper->register_emails();
                }
                // Get the email class
                $email_class = $emails_helper->get_email($email_id);
                if ($email_class && class_exists($email_class)) {
                    // Create email object and show preview
                    $email_object = new $email_class();
                    echo $email_object->preview();
                    exit; // Stop all other processing
                }
                wp_die('Email class not found: ' . esc_html($email_id));
            }
        }
        wp_die('Email preview system unavailable.');
    }
}, 1); // Very high priority to run before other plugins

Comments

Add a Comment