get_userdata()
is a pluggable function, you can find its declaration in wp-includes/pluggable.php
. That means, plugins can declare it earlier, and it is not declared, when a plugin is loaded.
When you look at wp-settings.php
, you can see the load order:
// 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' );
Wait at least for plugins_loaded
, before you do more than calling add_action()
or add_filter()
.