因此,我正在编写一个插件,用于解析json提要并从提要中以编程方式生成页面。我想以编程方式创建一个将成为页面作者的用户。问题是我打电话username_exists()
这个函数内部调用get_user_by()
最终是未定义的。我的猜测是,我需要采取一些行动,或者需要先完成一些其他事件,但我不知所措。下面的代码,并且错误Apache是抛回:get_user_by()undefined in wordpress
/**
* A simple class for the cron user, ie the 'author' that will
* generate pages from the feed
*/
class PP_CronUser {
private static $cronUserName = 'Cron User';
private static $cronEmail = 'asdf';
private static $cronPW = 'asdf';
private static $ID = null;
public static function getUserID() {
if(!is_null(self::$ID)) return self::$ID;
if(!($id = username_exists(self::$cronUserName))) { //Here's the offending line
self::$ID = $id;
return $id;
}
self::$ID = wp_create_user(self::$cronUserName, self::$cronPW, self::$cronEmail);
return self::$ID;
}
}
错误:
Fatal error: Call to undefined function get_user_by() in
/home/who_cares/wordpress/wp-includes/user.php
on line 1198
所以username_exists
定义,但这在内部调用get_user_by
这是没有定义的。有任何想法吗?
这不是*重复*,但问题是一样的,并可能解决,[wordpress插件 - >调用未定义函数wp_get_current_user()](http://stackoverflow.com/q/6127559/1432801 ) –