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.
You just need to include the file wp-load. php in your external file. The wp-load. php file is located in root of your WordPress installation.
Go to Appearance > Editor. On the right-hand side of the screen, you can see a list of all files contained in the theme. These differ depending on which theme you use, but one of the top options should be Theme Functions (functions. php).
Look for the file functions. php, which appears under the name of Theme Functions. By clicking it, you will be redirected to functions. php code editor, where you can manually enter the commands you want.
To do this, call add_action() in the global execution space of your plugin file: add_action ( 'hook_name', 'your_function_name', [priority], [accepted_args] ); where: hook_name The name of an action hook provided by WordPress, that tells what event your function should be associated with.
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
I've got a universal solution that will work in any PHP file inside the wp-content
folder without any adjustments or needing to know what is mysterious 'path/to/wordpress'
require_once(explode("wp-content", __FILE__)[0] . "wp-load.php");
It just automatically goes up to root of WordPress and loads wp-load.php.
You can just paste it anywhere, no matter if it's a plugin or theme file, and it will work.
I think stuff like ../../../..
looks extremely bad and when you modify the structure of your folders of a theme or plugin you can get crazy.
Note: This solution assumes you didn't rename your wp-content
folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With