コード例 #1
0
ファイル: tags.php プロジェクト: CGCookie/edd-product-updates
/**
 * Filters custom email tags from EDD Product Updates to display placeholders
 * when clicking the "Preview" button on the edit email page
 * 
 * @access public
 * @param string $message
 * @return $message - HTML message with template tags replaced
 */
function edd_pup_preview_tags($message)
{
    $email_id = get_transient('edd_pup_preview_email_' . get_current_user_id());
    if (false !== $email_id) {
        $updated_links = 'none' == edd_pup_template() ? edd_pup_products_links_tag_plain('', $email_id) : preg_replace('/<a(.*?)href="(.*?)"(.*?)>/', '<a href="#">', edd_pup_products_links_tag('', $email_id));
        $updated_products = 'none' == edd_pup_template() ? edd_pup_products_tag_plain('', $email_id) : edd_pup_products_tag('', $email_id);
    } else {
        // Outputs previews for tags when an $email_id is unavailable
        if ('none' == edd_pup_template()) {
            // Sample plaintext for {updated_products_links} tag
            $updated_links = __('Sample Product Title A - SKU: 2200 (filename1.jpg: http://www.example.com/download_link/?file=filename1, filename2.jpg: http://www.example.com/download_link/?file=filename2 ) - Product notes, Sample Product Title C - SKU: 2201 (filename1.jpg: http://www.example.com/download_link/?file=filename1), Sample Bundle Product C - SKU: 2202 - Sample Bundle Product 1 (bundle1.jpg: http://www.example.com/download_link/?file=bundle1); Sample Bundle Product 2 (bundle2.jpg: http://www.example.com/download_link/?file=bundle2)', 'edd-pup');
            // Sample plaintext for {updated_products} tag
            $updated_products = __('Sample Product Title A, Sample Product Title B, Sample Bundle Product Title (Sample Bundle Product 1, Sample Bundle Product 2, Sample Bundle Product 3), Sample Product Title C', 'edd-pup');
        } else {
            // Sample HTML for {updated_products_links} tag
            $updated_links = '<ul><li>' . __('Sample Product Title A', 'edd-pup') . ' –</li>';
            $updated_links .= '<ul><li><a href="#">' . __('sample_product_a_file1.pdf', 'edd-pup') . '</a></li>';
            $updated_links .= '<li><a href="#">' . __('sample_product_a_file2.pdf', 'edd-pup') . '</a></li></ul>';
            $updated_links .= '<li>' . __('Sample Product Title B', 'edd-pup') . ' –</li>';
            $updated_links .= '<ul><li><a href="#">' . __('sample_product_b_file1.pdf', 'edd-pup') . '</a></li></ul>';
            $updated_links .= '<li>' . __('Sample Bundle Product Title', 'edd-pup') . ' –</li>';
            $updated_links .= '<ul><li><em>' . __('Sample Bundle Product 1', 'edd-pup') . ' –</em></li>';
            $updated_links .= '<ul><li><a href="#">' . __('sample_bundle_product1.pdf', 'edd-pup') . '</a></li></ul>';
            $updated_links .= '<li><em>' . __('Sample Bundle Product 2', 'edd-pup') . ' –</em></li>';
            $updated_links .= '<ul><li><a href="#">' . __('sample_bundle_product2.pdf', 'edd-pup') . '</a></li></ul>';
            $updated_links .= '<li><em>' . __('Sample Bundle Product 3', 'edd-pup') . ' –</em></li>';
            $updated_links .= '<ul><li><a href="#">' . __('sample_bundle_product2.pdf', 'edd-pup') . '</a></li></ul></ul></ul>';
            // Sample HTML for {updated_products} tag
            $updated_products = '<ul><li>' . __('Sample Product Title A', 'edd-pup') . '</li>';
            $updated_products .= '<li>' . __('Sample Product Title B', 'edd-pup') . '</li>';
            $updated_products .= '<li>' . __('Sample Bundle Product Title', 'edd-pup') . '</li>';
            $updated_products .= '<ul><li><em>' . __('Sample Bundle Product 1', 'edd-pup') . '</em></li>';
            $updated_products .= '<li><em>' . __('Sample Bundle Product 2', 'edd-pup') . '</em></li>';
            $updated_products .= '<li><em>' . __('Sample Bundle Product 3', 'edd-pup') . '</em></li>';
            $updated_products .= '</ul><li>' . __('Sample Product Title C', 'edd-pup') . '</li></ul>';
        }
    }
    // Sample HTML for {unsubscribe_link} tag
    $unsub_link_params = array('order_id' => '0123', 'email' => '*****@*****.**', 'purchase_key' => strtolower(md5(uniqid())), 'edd_action' => 'prod_update_unsub', 'preview' => 1);
    $unsublink = add_query_arg($unsub_link_params, '' . home_url());
    $unsubscribe = 'none' == edd_pup_template() ? $unsublink : '<a href="' . $unsublink . '">' . apply_filters('edd_pup_unsubscribe_text', __('Unsubscribe', 'edd-pup')) . '</a>';
    // Replace tags with sample HTML
    $message = str_replace('{updated_products_links}', $updated_links, $message);
    $message = str_replace('{updated_products}', $updated_products, $message);
    $message = str_replace('{unsubscribe_link}', $unsubscribe, $message);
    // Add div for CSS styling of custom tags
    $message = '<div id="edd-pup-popup-preview">' . $message . '</div>';
    return $message;
}
コード例 #2
0
ファイル: ajax.php プロジェクト: CGCookie/edd-product-updates
/**
 * 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;
}