How to call WordPress functions in a custom PHP script

sid.sri picture sid.sri · Jan 19, 2010 · Viewed 55.3k times · Source

I have a PHP script I want to use for creating a new blog in WPMU. I am having trouble calling WordPress functions like wpmu_create_user and wpmu_create_blog.

My hope is to get this script running as a cron job from the command line and pick up new blog creation requests from an external db, create a new blog using the WordPress functions and update the database with the new blog information.

Answer

Pragati Sureka picture Pragati Sureka · Jan 19, 2010

include wp-load.php file (in the root of your wordpress installation) in your php script file like so,

require_once("/path/to/wordpress/wp-load.php");

you will have to provide the abspath of the wp-load file, now you can use all the functions of wordpress in your php script