Skip to content

Instantly share code, notes, and snippets.

@EdwardBock
Created May 16, 2021 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdwardBock/85c971633ea1abf8f248f4fb468344ed to your computer and use it in GitHub Desktop.
Save EdwardBock/85c971633ea1abf8f248f4fb468344ed to your computer and use it in GitHub Desktop.
Example: Upload stuff after post save with schedule
<?php
namespace PublicFunctionOrg/WordPress/UploadStuffViaCron;
// queue for schedule
const POST_META_UPLOAD = "public_function_org_upload";
add_action('save_post', function($post_id){
update_post_meta($post_id, POST_META_UPLOAD, 1);
});
// upload via schedule
const SCHEDULE_ACTION = "public_function_org_upload_stuff";
function init(){
if(!wp_next_scheduled(SCHEDULE_ACTION)){
wp_schedule_event(time(), 'hourly', SCHEDULE_ACTION);
}
}
add_action('admin_init', __NAMESPACE__.'\init');
function run(){
// 1. get all post ids that have post meta value
// 2. upload stuff
// 3. delete post meta value
}
add_action(SCHEDULE_ACTION, __NAMESPACE_.'\run');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment