簡體   English   中英

無法識別wp_get_current_user()

[英]wp_get_current_user() not recognised

我正在嘗試將來自Wordpress網站的當前用戶ID添加到已設置的表中。 輸入中的所有其他值都可以正常運行,但是嘗試以下代碼時出現PHP錯誤:

$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);

錯誤是:

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

識別我得到此錯誤原因的任何幫助將不勝感激。

添加此工作。 include_once '../../../wp-blog-header.php'; 我知道它很討厭,但是可以滿足我的需要。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM