Bare minimum to include in PHP file to use WP functions? [duplicate]

I’m finding the documentation on coding WP stuff to be very lacking and can’t figure out which files I need to include in my PHP script to get a bare minimum working code environment?

Example: I want to call wp_insert_user() to add a user to my site. How do I know which files in wp-includes/ I need to include in my PHP script?

1 Answer
1

You want to include wp-load.php or wp-blog-header.php not wp-settings.php or wp-config.php directly. If you look at the code in wp-load.php you will see why. wp-load.php looks for wp-config.php in several different places, including one level above the rest of the install. If you include wp-config.php directly the script will fail if wp-config.php has been moved.

Now look at wp-blog-header.php You will notice it loads wp-load.php but also does two other things– runs wp() and includes template-loader.php.

Officially, it is wp-blog-header.php that you want to load to include WordPress in a external file, but if you are aware of what is and isn’t happening you may get away with only wp-load.php and you did ask for “bare minimum”.

You should be able to define( 'SHORTINIT', TRUE ); and limit the files that load.

If you want to get any more “minimum” you will need to start loading files piecemeal and that will become very painful very fast, not to mention be prone to error.

Leave a Comment