douchao0358 2015-07-28 21:29
浏览 98

wp_get_current_user()无法识别

I'm trying to add the current user id from a Wordpress site to a table I have set up. All other values from inputs are going in fine, but I'm getting a php error when I try this code:

$link = mysqli_connect("localhost", "XXXXXX", "XXXXXX", "XXXXXX");

if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}

$latLng = mysqli_real_escape_string($link, $_POST['latLng']);
$title = mysqli_real_escape_string($link, $_POST['title']);
$type = mysqli_real_escape_string($link, $_POST['type']);

$current_user = wp_get_current_user(); 
$WP_id = $current_user->ID;

$sql = "INSERT INTO  `user_locations` (  `id` ,  `WP_id` , `latLng` ,      `type` ,  `title` ) VALUES ('', '$WP_id', '$latLng',  '$type',  '$title')";

if(mysqli_query($link, $sql)){
header("Location: leaflet-test-page");
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

mysqli_close($link);

The error is:

Fatal error: Call to undefined function wp_get_current_user() in /home/XXXXX/public_html/XXXXXX/insert.php on line 17

Any help identifying the reason I am getting this error would be appreciated.

  • 写回答

1条回答 默认 最新

  • dtstnjl898781429 2015-07-31 21:53
    关注

    Adding this worked. include_once '../../../wp-blog-header.php'; I know its nasty, but does the trick for what I need it for.

    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch