572 pointsLike some sort of WPMU DEV God"I'm helpful
David
Member
—
7th January 2012 (4 months ago)
I want to be able to launch a script in one of my plug-ins from the Linux cron. Linux' cron gives me a lot more granular control over cron activities than the internal WP cron.
I know I can call wget with a URL to my php file, and I'm guessing I need to include wp-config.php to load most of the WP environment, but what do I really need to include, load, and set to get the WordPress environment loaded in advance of running my script?
I want to be able to launch a script in one of my plug-ins from the Linux cron. Linux' cron gives me a lot more granular control over cron activities than the internal WP cron.
I know I can call wget with a URL to my php file, and I'm guessing I need to include wp-config.php to load most of the WP environment, but what do I really need to include, load, and set to get the WordPress environment loaded in advance of running my script?
It depends on where you place your php script - but assuming you place it in wp-content then you can use this as the first line:
require_once('../wp-load.php');
which is what we use in the recent global posts feed plugin (and a few others). You'll need to modify the number of ../ you use the further up the directories you go.
So I got this to work, but just ran into a new snag. I need to invoke this for different blogs. When I run it, it doesn't know which blog it's managing, so it doesn't know which options to pull, etc.
How can I tell the script which blog is the current blog and make that invocation of the WP code treat everything as if a given blog is active?
It's tricky, you could fudge something to go before you hit the load, but i've not tried it so can't comment on whether it'd work. But basically you want to set the $_SERVER host global to the domain / address of the blog you want it to be run for, then WP *should* use that setting to set the blog / site and set the relevant variables accordingly.
7249 pointsLike some sort of WPMU DEV GodMindblowingly helpful memberLifetime member
Support Chimp
—
29th January 2012 (3 months ago)
#
Hey there! :-)
Just checking in to see how things are going with this one and if you need any further help. :-)
We haven't heard from you on this thread for a while, perhaps you got help over our email. I'm going to presume your all fixed up now and don't need any further assistance.
However if you have more questions or need some more help then please feel free to respond in this thread or create a new one and we will be more than happy to offer assistance. :-)
Responses (6)
Developer — 7th January 2012 (4 months ago) #
It depends on where you place your php script - but assuming you place it in wp-content then you can use this as the first line:
require_once('../wp-load.php');which is what we use in the recent global posts feed plugin (and a few others). You'll need to modify the number of ../ you use the further up the directories you go.
Member — 7th January 2012 (4 months ago) #
Cool. Thanks! Do I also need to require wp-config, or just wp-load?
Developer — 7th January 2012 (4 months ago) #
Just the wp-load, it takes care of pulling in the config files.
Member — 19th January 2012 (4 months ago) #
So I got this to work, but just ran into a new snag. I need to invoke this for different blogs. When I run it, it doesn't know which blog it's managing, so it doesn't know which options to pull, etc.
How can I tell the script which blog is the current blog and make that invocation of the WP code treat everything as if a given blog is active?
Thanks!
Developer — 19th January 2012 (4 months ago) #
It's tricky, you could fudge something to go before you hit the load, but i've not tried it so can't comment on whether it'd work. But basically you want to set the $_SERVER host global to the domain / address of the blog you want it to be run for, then WP *should* use that setting to set the blog / site and set the relevant variables accordingly.
Support Chimp — 29th January 2012 (3 months ago) #
Hey there! :-)
Just checking in to see how things are going with this one and if you need any further help. :-)
We haven't heard from you on this thread for a while, perhaps you got help over our email. I'm going to presume your all fixed up now and don't need any further assistance.
However if you have more questions or need some more help then please feel free to respond in this thread or create a new one and we will be more than happy to offer assistance. :-)
Take care.
Become a member