dongruolin5324 2018-09-23 04:00
浏览 37
已采纳

获取Wordpress用户信息[关闭]

Good night guys, I am not very familiar with Wordpress, but I am already completing my task, I can already send email, capture choice via jquery with Ajax processing email sending, but I can not capture the user logged in to Wordpress, I need a light. Thankful, Siro Souza

<html>
<body>
<meta http-equiv="refresh" content="2; url=index.php">
<?php
$location = $_SERVER['DOCUMENT_ROOT'];
include ($location . '/wp-config.php');
include ($location . '/wp-load.php');
include ($location . '/wp-includes/pluggable.php');
global $current_user;
\etorna os dados do usuário logado
$current_user = wp_get_current_user();
\\ passamos o ID do usuário e geramos o array
$user_info = get_userdata($current_user->ID);
$first_name = $user_info->first_name;
$user_email = $user_info->user_email;
if(is_user_logged_in()){
$premium = $_POST['chosen_premium'];
$vnome = $first_name; 
$vemail_origem = $user_email;
$vassunto = "Prêmio Escolhido"; 
$vmensagem = $premium;
$msg="Nome: $vnome
"; 
$msg.="Email: $vemail_origem
"; 
$msg.="Assunto: $vassunto
"; 
$msg.="Mensagem: $vmensagem
";
  • 写回答

1条回答 默认 最新

  • douao1854 2018-09-23 04:36
    关注

    If you are inside your plugin or theme files you should be able to use somewhat similar code to the above...

    if (is_user_logged_in()) {
        $current_user = wp_get_current_user();
        $user_info = get_userdata($current_user->ID);
        echo '<pre>user_info: ' . print_r($user_info, true) . '</pre>';//debug
    }
    

    Are you trying to run this from outside of WordPress? If you are still having issues, perhaps can you provide more details on what file you are using for your code?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法