doudian7996 2016-03-02 21: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-02 21: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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部