admin管理员组文章数量:1277901
if(strpos($query, '%get_email%') !== false){
$query = str_replace('%get_email%', get_the_author_meta( 'user_email' ), $query);
}
Okay so am trying to make a MySQL query and in the plugin I am trying to add a shortcode %get_email%
but anyway its not returning any email in the actual query.
Like
select* from tablename where email='%get_email%';
Any idea on how to do that?
Here what is working for id -
if(strpos($query, '%CURRENT_USER_ID%') !== false){
$query = str_replace('%CURRENT_USER_ID%', get_current_user_id(), $query);
}
if(strpos($query, '%get_email%') !== false){
$query = str_replace('%get_email%', get_the_author_meta( 'user_email' ), $query);
}
Okay so am trying to make a MySQL query and in the plugin I am trying to add a shortcode %get_email%
but anyway its not returning any email in the actual query.
Like
select* from tablename where email='%get_email%';
Any idea on how to do that?
Here what is working for id -
if(strpos($query, '%CURRENT_USER_ID%') !== false){
$query = str_replace('%CURRENT_USER_ID%', get_current_user_id(), $query);
}
Share
Improve this question
edited Jun 2, 2021 at 16:53
Viktor Borítás
3042 silver badges11 bronze badges
asked May 22, 2015 at 20:22
RoyRoy
311 gold badge1 silver badge2 bronze badges
1
|
4 Answers
Reset to default 5I will approach like this:
global $current_user;
get_currentuserinfo();
$email = (string) $current_user->user_email;
var_dump($email);
You just called got the email from the current_user array and cast it into string :) that's it
Download/Install the PHPCode Snippets WordPress Plugin, Then just create a shortcode with this content (exactly as follows);
<?php
$current_user = wp_get_current_user();
echo $current_user->user_email;
If you just need to "Get Current user email as a return string value" then you can simply do this by using following function
// Add this function in your functions.php or in your plugin
function mm_get_current_user_email(){
global $current_user;
get_currentuserinfo();
$email = $current_user->user_email;
return $email;
}
add_shortcode( 'get_email', 'mm_get_current_user_email');
Then you can get current user email as string where ever you want by simply using [get_email]
or <?php echo do_shortcode( '[get_email]' ); ?>
For more on get_currentuserinfo() visit WordPress Codex.
Mile response is ok but there is no need to call an extra function. you can just use like this :
global $current_user;
$email = $current_user->user_email;
本文标签: pluginsGet Current user email as a return string value
版权声明:本文标题:plugins - Get Current user email as a return string value 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741275894a2369726.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$query
? What is the context? I am unsure what you are doing. – s_ha_dum Commented May 22, 2015 at 21:52