Esempio n. 1
0
/**
 * Generates HTML for preview of email on edit email screen
 * 
 * @access public
 * @return void
 */
function edd_pup_ajax_preview()
{
    // Nonce security check
    if (empty($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'edd-pup-preview-email')) {
        _e('Nonce failure: error generating preview.', 'edd-pup');
        die;
    }
    // Save the email before generating a preview
    $email_id = edd_pup_sanitize_save($_POST);
    // Instruct browser to redirect for continued editing of email if triggered on Add New Email page
    parse_str($_POST['url'], $url);
    if ($url['view'] == 'add_pup_email') {
        echo absint($email_id);
        die;
    }
    // Necessary for preview HTML
    set_transient('edd_pup_preview_email_' . get_current_user_id(), $email_id, 60);
    if (0 != $email_id) {
        $email = get_post($email_id);
        // Use $template_name = apply_filters( 'edd_email_template', $template_name, $payment_id );
        add_filter('edd_email_template', 'edd_pup_template');
        if (version_compare(get_option('edd_version'), '2.1') >= 0) {
            $edd_emails = new EDD_Emails();
            $preview = $edd_emails->build_email(edd_email_preview_template_tags($email->post_content));
        } else {
            $preview = edd_apply_email_template($email->post_content, null, null);
        }
        // Add max-width for plaintext emails so they don't run off the page
        if ('none' == edd_pup_template()) {
            $preview = '<div style="max-width: 640px;">' . $preview . '</div>';
        }
        echo $preview;
    } else {
        _e('There was an error generating a preview.', 'edd-pup');
    }
    die;
}