Add cron schedule to upload video on save_post

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?

Topic cron videos Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.