How to use functions found inside pluggable.php with my plugin files

No, you shouldn’t explicitly require pluggables.php in your plugin. The whole point of them is that they are overridable by plugins, and if you load them before a plugin which does want to override one then that will fail. The loading sequence is (see wp-settings.php):

  • load active plugins
  • require pluggable.php
  • do_action( 'plugins_loaded' );

so pluggable functions are available from the plugins_loaded action onwards. This will cover almost all WordPress hooks you’re likely to want to use:

  • If you want your plugin to do something at load time that uses a pluggable function then put the logic in a plugins_loaded handler
  • else put the logic in the appropriate action handler or filter

and it’ll work fine.


And for what it’s worth your example does work fine for me. I dropped this script into my mu-plugins folder (which is loaded before plugins) and

  • I don’t get any errors from the get_user_by call
  • Your version doesn’t do anything observable so I’ve added an error_log() call
    error_log( print_r( $user, true ) );
    

    and I do see my user 1 logged to my server error log correctly.