Creating a shortcode for attachment

August 26, 2021 23:23:18
Crash
Topics: 4
Messages: 6
Hi there.
I'm using the WP plugin with oxygen builder, which does not render E2PDF shortcodes properly (do not render them at all actually).
I managed to render the shortcode from PHP using the following code:
<?php
$post_id = get_the_ID();
$post_title = get_the_title();
$codigo = get_field('codigo');
$pdf_url = do_shortcode('[e2pdf-download id="1" dataset="'.$post_id.'" output="url" name="'.$post_title.' - ('.$codigo.')"]');

echo '<a id="e2pdf-download" class="e2pdf-download e2pdf-format-pdf" target="_blank" href='.$pdf_url.'><h5 class = "pdf_btn">PDF donwload</h5></a>';

Now I'm trying to do the same with the attachment link. I need to recreate the shortcode [e2pdf-attachment id="1"] using PHP.

Can you please assist me?
Have a great evening.
August 27, 2021 05:59:56
E2Pdf
Topics: 7
Messages: 3614
Support
Hi,

The usage will be pretty the same but it will be need to add "apply" attribute as:

$pdf_path = do_shortcode('[e2pdf-attachment id="1" dataset="'.$post_id.'" name="'.$post_title.' - ('.$codigo.')" apply="true"]');

It will generate temporary file on server and the path will be assigned to $pdf_path, which can be added to "wp_mail" attachments array. After sending email with "wp_mail" the file must be removed. Here is example function to remove temporary created file and folder after mail sent: https://codeshare.io/6pVWeO

We remain at your service.


We would really appreciate your feedback at WordPress.org!
Get News and Updates
Our monthly newsletter keeps you in the loop, so you'll always be up to date with the latest news and updates about E2Pdf.
* You can update your email subscription preferences here.
All trademarks, service marks, trade names, product names, and logos appearing on this website are the property of their respective owners. The use of trademarks such as Formidable Forms®, Forminator Forms®, Gravity Forms®, JetFormBuilder®, WordPress®, WooCommerce®, WPForms® and others is solely for identification purposes (nominative use) and does not imply any affiliation, sponsorship, or endorsement by the respective trademark holders.
© 2017 - 2026, https://e2pdf.com

We use cookies to collect and analyse information on site performance and usage, to provide social media features and to enhance and customise content and advertisements. By clicking "Accept Selected", you consent to use of selected cookies according to our Cookie Policy.