douzou8074 2014-11-11 03:59
浏览 31
已采纳

Wordpress和PHP - get_currentuserinfo();

I have searched to the end of the internet and can't seem to find anything that helps me with my issue. I have a wordpress site (inherited) and I simply want to be able to obtain a user's information when they're logged in. From the documentation I see to use get_currentuserinfo() but when I try to use it I get nothing.

The file resides in a folder in my main html directory. Here are the contents:

<?php 
include_once("../wp-includes/pluggable.php"); 
  global $current_user;
  get_currentuserinfo();
  echo $current_user->user_login;


?>

I'm literally losing my mind over this. Is there something else I need to include at the top? Do I have to create the page within wordpress?

  • 写回答

2条回答 默认 最新

  • dtvq4978 2014-11-11 04:04
    关注

    you must include wp-load.php to use wordpress function in php file outside wordpress

    require_once("/path/to/wordpress/wp-load.php");
      global $current_user;
      get_currentuserinfo();
      echo $current_user->user_login;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来