doudian7996 2016-03-03 05:10
浏览 69
已采纳

如何从位于我的public_html文件夹中的php脚本中的wp-includes调用函数?

Receiving a "Fatal error: Call to undefined function get_current_user_id()" when I call this function within my script. My script is located in my public_html folder and not any Wordpress folder. I have attempted to require the pluggable.php file and it did not help. This is not a plugin that is trying to call the function, but a script that is executed from a button within my plugin.

$user_ID = get_current_user_id();

$query = "SELECT * FROM wp_users WHERE ID=".$user_ID;
$result = mysql_query($query);
$data = mysql_fetch_object($result);

$query2 = 'UPDATE booking SET source=destination WHERE status=0 AND 
userid=$data->ID ';
$result = mysql_query($query2);
  • 写回答

1条回答 默认 最新

  • doukuangxiu1621 2016-03-03 05:31
    关注

    You have included only pluggable.php file, it is not sufficient for WordPress functions to work. You must have to include wp-load.php to all the functions work for WordPress. Make sure to use proper path for wp-load.php file if you are using somewhere out side of the WordPress.

    Try to change your code like :

    require_once '../wp-load.php'; //Make sure to use correct path of this file
    $user_ID = get_current_user_id();
    $query = "SELECT * FROM wp_users WHERE ID=".$user_ID;
    $result = mysql_query($query);
    $data = mysql_fetch_object($result);
    $query2 = 'UPDATE booking SET source=destination WHERE status=0 AND userid=$data->ID ';
    $result = mysql_query($query2);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog