0

I made a custom plugin to get post data from another source, when I save a post, I get all data. and also upload a video from source server to our server.

But it take a while when saving post until uploading the video.

Now, When saving post I need to get all data from source, But schedule uploading video after 1 minute to upload it on background.

The Code Example:

add_action( 'save_post', 'update_from_source');
function update_from_source($post_id)
    {
        // code for getting post data here
    function uploading_video()
        {
            // code for uploading video here
            // I dont need to run this when saving post
            // but add it as cron job for this post
        }
    }

How I can Add uploading_video Function to cron?

1 Answer 1

0

I think the best approach would be to only save a post meta value ( [or use a custom table][1] ) which indicates that a video upload should happen. Also register a schedule that will query for all posts that are marked as "upload needed" and do the upload in the schedule execution.

https://gist.github.com/EdwardBock/85c971633ea1abf8f248f4fb468344ed

You can shorten the schedule timings ( Cron schedule interval through plugin options? ) but make shure to separate your visitors requests from schedule execution by moving it to a real cron job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.