如何从位于我的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);

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