Creating a shortcode for attachment

26 August, 2021 16: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.
26 August, 2021 22:59:56
E2Pdf
Support
Topics: 7
Messages: 3176
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!