WP Cron doesn’t save or in post body

Instead of manually removing the safety filters like this, you should simply set the correct user for these processes to be running as.

When you are logged in and running a process manually, you are logged in and thus you have your credentials being used, and your permissions being used. I’m betting you’re an administrator on the site. You have permission to post unfiltered_html, meaning that you can post iframes and objects and whatever you like.

When your cron job runs, it doesn’t have your credentials. So, it doesn’t get those same permissions. Thus, the safety filters get turned on, and things like iframes and such get blocked.

To fix it, you need to change your process not to disable the filters, but to run as you. So find your user ID number in the database, and just before your process to do the import runs, add this code:

wp_set_current_user( 123 );

Where “123” is whatever your user ID number is. Then the code will now be “you” and can do things just like you would do them. Those filters won’t take effect because the permissions are correct for the current user.

Note: This isn’t any safer, BTW. You’re still allowing some remote website to insert possibly dangerous things onto yours. So you’re trusting them not to screw you over here. Just bear that in mind. This method is just simpler than manually fiddling around with filters.

Leave a Comment