Il tuo sito è raggiungibile via HTTPS ma devi incorporare un iframe che ha una sorgente HTTP: come puoi farlo senza generare errori di contenuto misto (mixed content)?
Grazie a questo codice potrai recuperare i dati dell’iframe lato server.
if ( isset( $_GET['proxy'] ) && isset( $_GET['url'] ) && md5( esc_attr( $_GET['url'] ) ) === $_GET['proxy'] ){
$response = wp_remote_get( esc_url( $_GET['url'] ) );
if( $response ){
echo wp_remote_retrieve_body( $response );
}
exit;
}
Ecco il codice per creare uno shortcode in cui puoi scrivere l’URL dell’iframe.
add_shortcode( 'eos_http_iframe','eos_http_iframe' );
function eos_http_iframe( $atts ){
$atts = shortcode_atts( array(
'url' => '',
'class' => '',
'width' => '100%'
),$atts,'eos_http_iframe' );
if( '' === $atts['url'] ) return;
$class = '' !== $atts['class'] ? ' '.$class : '';
return '<iframe style="width:'.esc_attr( $atts['width'] ).'" class="eos-http-iframe'.esc_attr( $class ).'" src="?proxy='.md5( esc_attr( $atts['url'] ) ).'&url='.esc_url( $atts['url'] ).'"></iframe>';
}
Se preferisci, puoi scaricare direttamente il mini plugin che include questo codice.
Sia che tu abbia aggiunto il codice qui sopra sia che tu abbia installato il plugin, per caricare un iframe HTTP sul tuo sito HTTPS ti basta usare lo shortcode
Dove http://your-external-source.com è la sorgente dell’iframe HTTP.