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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?