2

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?

  • @CaptSaltyJack I'm curious, are you just new to using the framework and don't want to figure out how to deal with the actions/hooks system (don't mean this negatively, I threw my hands up with Magento) or do you have a specific reason to want to use native WP functions outside of WP? – Andrew Bartel Apr 30 '13 at 3:19
  • @AndrewBartel MailChimp wants to do an HTTP POST to a URL, when a user subscribes/unsubscribes/etc. So I'm making a PHP file to do some WP user-related stuff on the backend. I'm not sure if hooks really apply in this case. – CaptSaltyJack Apr 30 '13 at 3:31
  • Ah, yea you could use templates, but if that's all you need to do, no reason to mess with it. – Andrew Bartel Apr 30 '13 at 6:01
7

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.

  • Thanks. Defining SHORTINIT as true actually makes my code break. Functions like get_post_meta stop working. But requiring wp-load.php works. – CaptSaltyJack Apr 30 '13 at 3:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.