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 42
| <?php
function custom_pdf_attachment_shortcode( $atts ) {
global $post;
extract( shortcode_atts( array(
'file' => '',
'name' => ''
), $atts ) );
if(!$file){
return;
}
if(!get_post_meta($post->ID, 'cpt_pdf_attachment'.$file, true)){
return;
}
if($name){
$url = 'http://facopy.be/v2/wp-content/plugins/pdfjs-viewer-shortcode/web/viewer.php?file=';
$url2 = '&download=false&print=false&openfile=false';
$ret = '<img src="'.plugins_url( 'custom-post-type-pdf-attachment/pdf.png', dirname(__FILE__) ).'"> <a href="'.$url.''.get_post_meta($post->ID, 'cpt_pdf_attachment'.$file, true).''.$url2.'">'.$name.'</a><br />';
}
else {
$ret = '<img src="'.plugins_url( 'custom-post-type-pdf-attachment/pdf.png', dirname(__FILE__) ).'"> <img src=""><a href="'.get_post_meta($post->ID, 'cpt_pdf_attachment'.$file, true).'">PDF Download</a>';
}
return $ret;
}
add_shortcode( 'pdf_attachment', 'custom_pdf_attachment_shortcode' );
function pdf_attachment_file($file,$name){
if(!$file){
return;
}
return do_shortcode('[pdf_attachment file="'.$file.'" name="'.$name.'"]');
}
?> |
Partager