woocommerce / sensei-certificates

Hi, I'm the Certificates extension for Sensei.
GNU General Public License v2.0
34 stars 23 forks source link

Fix Certificate Image Path to Support Plugins Such as Offload Media #198

Closed robertstaddon closed 4 years ago

robertstaddon commented 4 years ago

Using Delicious Brains Offload Media (https://wordpress.org/plugins/amazon-s3-and-cloudfront/) currently breaks Sensei Certificates. The following error is given: "FPDF error: Missing or incorrect image file: /home/mywebsite/public_html/wp-content/uploads/s3://files.mywebsite.com/wp-content/uploads/2020/01/Certificate.jpg"

I have filed a support request with Delicious Brains. However, this is actually a bug in the Sensei Certificates plugin, which manually grabs the WordPress absolute upload path instead of retrieving using the WordPress get_attached_file() function intended for that purpose (https://developer.wordpress.org/reference/functions/get_attached_file/).

In the "/sensei-certificates/classes/class-woothemes-sensei-certificate-templates.php" file on line 449 we see the following code to create the image's absolute path: $fpdf->Image( $upload_dir['basedir'] . '/' . $image['file'], 0, 0, $image['width'], $image['height'] );

If we re-write this line to use get_attached_file(), this plugin should work nicely with Offload Media or any other plugin that would allow WordPress media library to be stored in the cloud: $fpdf->Image( get_attached_file( $this->get_image_id() ), 0, 0, $image['width'], $image['height'] );

donnapep commented 4 years ago

Closed by #199.