Last active
April 27, 2023 17:25
-
-
Save dantetesta/0d36d659829cc16c7172d73025d15174 to your computer and use it in GitHub Desktop.
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
/* Mostra um PDF do google Drive embedado no Front via URL salva no Metabox do User Corrente | |
USO MANUAL: | |
<iframe src="LINK" width="100%" height="600px" class="pdf_gdrive" style="border:0;"> | |
EXEMPLO: Crie um campo chamado _pdf no metabox do user OU no CPT desejado. | |
Adicione o trecho de código abaixo no functions.php do seu tema | |
Adicione o shortcode [pdf_gdrive_user field="_pdf" size="600px"] | |
Adicione o shortcode [pdf_gdrive_cpt field="_pdf" size="600px"] | |
*/ | |
/* PARA USERS METABOX */ | |
function user_pdf_google_drive_shortcode($atts) { | |
$atts = shortcode_atts( array( | |
'field' => '', | |
'size' => '' | |
), $atts, 'pdf_gdrive_user' ); | |
$user_id = get_current_user_id(); | |
$pdf = get_user_meta($user_id, $atts['field'], true); | |
$new_link = str_replace('/view?usp=share_link', '/preview', $pdf); | |
return '<iframe src="' . $new_link . '" width="100%" height="'.$atts['size'].'" class="pdf_gdrive" style="border:0;">'; | |
} | |
add_shortcode('pdf_gdrive_user', 'user_pdf_google_drive_shortcode'); | |
/* PARA METAFIELD DE CPTS */ | |
function cpt_pdf_google_drive_shortcode($atts) { | |
$atts = shortcode_atts( array( | |
'post_id' => get_the_ID(), | |
'field' => '', | |
'size' => '' | |
), $atts, 'pdf_gdrive_cpt' ); | |
$pdf = get_post_meta( $atts['post_id'], $atts['field'], true ); | |
$new_link = str_replace('/view?usp=share_link', '/preview', $pdf); | |
return '<iframe src="' . $new_link . '" width="100%" height="'.$atts['size'].'" class="pdf_gdrive" style="border:0;">'; | |
} | |
add_shortcode('pdf_gdrive_cpt', 'cpt_pdf_google_drive_shortcode'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment