我正在开发WordPress MU,并试图构建一个插件,将用户添加到多个站点。到目前为止,我们已经尽了一切努力来循环浏览网站。但是,当使用add\\u user\\u to\\u blog将用户分配到以下站点时,出现了错误,请参见下文。
将\\u user\\u添加到\\u blog($blogid、$amsuserid、$urole);
获取以下错误:
致命错误:在wp includes函数中调用未定义的函数get\\u userdata()。php在线181
如果禁用行“add\\u user\\u to\\u blog”,则不会出现错误。
此处的完整功能:
function amsAddUsertoSites()
{
$siteslist=$_POST[\'updatesites\'];
$urole=$_POST[\'setrole\'];
$addtoallblogs=$_POST[\'allsites\'];
$amsuserid=$_POST[\'userid\'];
if($addtoallblogs) {
//add_user_to_blog( $blogid, $user_id, "administrator" );
$blogs = get_blogs();
foreach($blogs as $blog=>$blogid)
{
add_user_to_blog( $blogid, $amsuserid,$urole );
}
}
else {
foreach($siteslist as $blog=>$blogid)
{
add_user_to_blog( $blogid, $amsuserid,$urole );
}
}
}
SO网友:fuxia
get_userdata()
是一个可插入的函数,您可以在wp-includes/pluggable.php
. 这意味着,插件可以在加载插件时更早地声明它,而不会声明它。
当你看到wp-settings.php
, 您可以看到加载顺序:
// Load active plugins.
foreach ( wp_get_active_and_valid_plugins() as $plugin )
include_once( $plugin );
unset( $plugin );
// Load pluggable functions.
require( ABSPATH . WPINC . \'/pluggable.php\' );
require( ABSPATH . WPINC . \'/pluggable-deprecated.php\' );
// Set internal encoding.
wp_set_internal_encoding();
// Run wp_cache_postload() if object cache is enabled and the function exists.
if ( WP_CACHE && function_exists( \'wp_cache_postload\' ) )
wp_cache_postload();
/**
* Fires once activated plugins have loaded.
*
* Pluggable functions are also available at this point in the loading order.
*
* @since 1.5.0
*/
do_action( \'plugins_loaded\' );
至少等待
plugins_loaded
, 在你打电话之前
add_action()
或
add_filter()
.