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?
You want to include
wp-load.php
orwp-blog-header.php
notwp-settings.php
orwp-config.php
directly. If you look at the code inwp-load.php
you will see why.wp-load.php
looks forwp-config.php
in several different places, including one level above the rest of the install. If you includewp-config.php
directly the script will fail ifwp-config.php
has been moved.Now look at
wp-blog-header.php
You will notice it loadswp-load.php
but also does two other things– runswp()
and includestemplate-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 onlywp-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.