I built a plugin for my company, which basically goes to tube sites, scrapes them for content, and posts them automatically in whatever state is defined (publish, draft, future, etc).
Now, everything goes well when I manually add a post through the plugin:
it opens a cURL to the sites, grabs the videos and embeds, takes thumbnails, posts titles, flawless.
however, when I try to run it from the cron job using
add_action('timelyTube', 'timelyPost');
and on the activation hook:
wp_schedule_event(time(), 'hourly', 'timelyTube');
it works in the sense that it fires the function timelyPost()
, but when it goes to grab the video, it’s not able to do so, it grabs the thumbnails & titles, but not the embeds, meaning that the cURL is working, but something gets messed up in the process.
if anyone has any idea about what to do, I’ll be grateful,
Thanks, Itai.
I just encountered this very same problem. I was trying to do
wp_insert_post()
from within a cron action, and the script would apparently just die during somesave_post
action handler. I tracked down my problem, which turned out to be asave_post
handler which is used to save the POST data from a custom metabox. Within this handler, it callscheck_admin_referer( 'myplugin_save', 'myplugin_nonce')
as a security check. This function very annoyingly callswp_die()
if the security check fails, and as a result the execution just stops. So by adding a check to short-circuit the function ifDOING_CRON
then everything started working as expected. See:Well, I’ve found my own solution, thanks weston, but I believe mine is a bit easier 🙂
from the function which calls to insert post, you do the following for simplicity’s sake:
And voila! there’s a new post.