Created
March 23, 2012 23:31
-
-
Save wycks/2176359 to your computer and use it in GitHub Desktop.
PDF Cross Browser Embed Plugin Wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
your function closes too early...
should read: