I had this question recently:
http://www.wpquestions.com/question/showChronoLoggedIn/id/9627
<strong>But it's my mistake I need an URL past inside an URL in a frame: </strong>
In my WP page I've added in the code:
<iframe src="http://mysite.com" width="980" height="600" frameborder="0" scrolling="no" align="middle"></iframe></p>
But I would need:
<iframe src="http://[email protected]" width="980" height="600" frameborder="0" scrolling="no" align="middle"></iframe></p>
Where "[email protected]" is the current user registered email adress.
Any ideas?
Many thanks,
Jonathan
timDesain Nanang answers:
try using shortcode:
put in the theme's functions.php
add_shortcode('wpqiframe', 'wpq_iframe');
function wpq_iframe( $atts ){
$output = '';
$user_email = '';
if ( is_user_logged_in() ) {
global $user_ID;
$user_info = get_userdata($user_ID);
$user_email .= '?email='.$user_info->user_email;
}
$output .= '<iframe src="http://mysite.com'.$user_email.'" width="980" height="600" frameborder="0" scrolling="no" align="middle"></iframe>';
return $output;
}
how to use:
- post content:
[wpqiframe]
- template
<?php echo do_shortcode('[wpqiframe]'); ?>
if you need custom atts, i'll add later
Jonathan Surinx comments:
Hi there,
Smart solution! That's working like a charm!
Thanks a lot,
Jonathan
timDesain Nanang comments:
glad to hear that.
:)
you are welcome.
Jonathan Surinx comments:
Oh I forgot, to make this work for 3 pages / 3 frames (one different for each language).
Any advice?
Many thanks again,
Jonathan
timDesain Nanang comments:
how about this:
add_shortcode('wpqiframe', 'wpq_iframe');
function wpq_iframe( $atts ){
extract(shortcode_atts(array(
'url' => 'http://mysite.com',
'width' => '980',
'height' => '600',
), $atts ));
$output = '';
$user_email = '';
$width= (int) $width> 300 ? $width: 600;
$height = (int) $height > 100 ? $height : 300;
if ( is_user_logged_in() ) {
global $user_ID;
$user_info = get_userdata($user_ID);
$user_email .= '?email='.$user_info->user_email;
}
$output .= '<iframe src="'.esc_url($url).''.$user_email.'" width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" align="middle"></iframe>';
return $output;
}
usage :
[wpqiframe url="http://mysite.com"]
[wpqiframe url="http://mysite.com/en"]
[wpqiframe url="http://en.mysite.com"]
Jonathan Surinx comments:
Sorry for my late reply, this worked perfectly thanks a lot! :)
Remy answers:
<?php
$user_email = '?email=';
if ( is_user_logged_in() ) {
global $user_ID;
$user_info = get_userdata($user_ID);
$user_email .= $user_info->user_email;
} ?>
<iframe src="http://mysite.com<?php echo $user_email; ?>" width="980" height="600" frameborder="0" scrolling="no" align="middle"></iframe></p>
Jonathan Surinx comments:
Yes, but... should I activate http://wordpress.org/plugins/allow-php-in-posts-and-pages/
or something like this first?
Thanks :))
Remy comments:
Are you including the iframe in a post content ? Or is it in a template ?
Jonathan Surinx comments:
post content
Sabby Sam answers:
Hi Jonathan Surinx,
You could do this in this way
<?php global $current_user;
get_currentuserinfo();
<iframe src="http://mysite.com?email=<?php echo $current_user->user_email; ?>" width="980" height="600" frameborder="0" scrolling="no" align="middle"></iframe></p>
I hope that way you are asking.
Jonathan Surinx comments:
Thanks but same question: how to add this code in a normal page? Custom page? PHP plugin?
Sabby Sam comments:
Okay,
In order to run in pages, post content you need to add some other plugin to run the php code.
These plugin can help you to run the php code in post content
1. https://wordpress.org/plugins/wp-exec-php/installation/
2.http://wordpress.org/plugins/shortcode-exec-php/
You can add any of plugin but remember you need to shift to text editor (not visual editor) while pasting the php code. Or else you could do the same using PHP shortcode. I gave the link above and I hope this will work 100%.
Other ways is that provide the login details, any of people can do this in a quick.
Thanks
Hariprasad Vijayan answers:
Hello,
Did you tried like this?
add_action('wp_footer', 'timdesain_var_footer');
function timdesain_var_footer(){
global $user_ID;
if(is_user_logged_in() && is_page( 42 ) ){
$user_info = get_userdata($user_ID);
$user_email = $user_info->user_email;
?>
<script type="text/javascript">
jQuery(document).ready(function(){
var mail = 'email=<?php echo sanitize_email($user_email); ?>';
jQuery('iframe').attr('src', function() {
if(!/email/i.test(this)){
return this.href + '?' + mail;
}
});
});
</script>
<?php
}
}
add_action('init', 'timdesain_var_init');
function timdesain_var_init(){
//get the email here
if(is_user_logged_in() && is_page( 42 ) ){
$email = isset($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '';
//echo $email;
}
}
Regards,
Hariprasad