<?php
|
|
|
|
/**
|
|
* Plugin Name: Embed PDFs
|
|
* Plugin URI: https://horizontes.info
|
|
* Description: Allows embedding PDFs via shortcodes using PDF.js
|
|
* Version: 1.0.0
|
|
* Requires at least: 5.2
|
|
* Requires PHP: 7.2
|
|
* Author: Horizontes Coop.
|
|
* Author URI: https://horizontes.info
|
|
* License: GPL v2 or later
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
*/
|
|
|
|
add_shortcode('embed-pdf', function ($atts) {
|
|
$atts = shortcode_atts([
|
|
'url' => '',
|
|
'width' => '100%',
|
|
'height' => '80vh',
|
|
], $atts);
|
|
|
|
if (! $atts['url']) {
|
|
return;
|
|
}
|
|
|
|
$src = plugin_dir_url(__FILE__) . "pdfjs/web/viewer.html?file={$atts['url']}";
|
|
|
|
return <<<HTML
|
|
<iframe src="{$src}" style="width:{$atts['width']}; height: {$atts['height']}"></iframe>
|
|
HTML;
|
|
});
|