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 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线