public
Last active

PDF Cross Browser Embed Plugin Wordpress

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
<?php
/*
Plugin Name: PDF Cross Browser Embed
Plugin URI: http://#
Description: Embeds PDf into a post/page using default media uploader using a cross browser freindly iframe
Version: 1.0
Author: Wycks
License: GPL2
 
 
/*
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
 
add_filter('media_send_to_editor', 'my_filter_pdf', 20, 3);
 
function my_filter_pdf($html, $id) {
$attachment = get_post($id); //fetching attachment by $id passed through
 
$mime_type = $attachment->post_mime_type; //getting the mime-type
if ($mime_type == 'application/pdf') { //checking mime-type
$src = wp_get_attachment_url( $id );
 
$html = '<iframe width="500" height="500" src="'.$src.'"></iframe>';
return $html; // return new $html
}
return $html;
}
?>

your function closes too early...

    }
    return $html; // return new $html

should read:

    return $html; // return new $html
 }

Thanks, had not noticed.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.