Certain actions failing when run through cron

I am having a huge argument with WordPress, and this is my last port of call before I throw the PC out of the window.

I have a plugin here that exports an XML feed into WordPress posts. The posts have an image which is saved locally, the HTML to display the image is then inserted at the beginning of the post content, before being inserted into WordPress using wp_insert_post.

Read More

I’m having a slight issue though. The script works fine when it is turned on manually. But as soon as it triggered by cron, the post will import fine, but the image will not save locally, and the HTML for the image is not present in the posts content.

I really am at a loose end. I thought it was to do with permissions, and the fact that the posts were being imported with no author. I then changed it so they were marked as written by an admin, but that made no difference.

What is the problem of running it via cron vs running it manually when logged in?

If anyone can help solve this then I will be eternally grateful!

Related posts

Leave a Reply

1 comment

  1. Ok, so it turns out the solution is slightly embarrassing on my part and I couldn’t see the forest for the trees.

    The code that was executed by the cron job was trying to check the contents of a variable that is set via a radio button on the admin / plugin activation page.

    Thus, the part of the code to save the image (inside an if statement) was not being accessed.

    It just goes to show how much of an issue a small error can become when there’s no access to any error logs or outputs.