-
-
Save EdwardBock/85c971633ea1abf8f248f4fb468344ed to your computer and use it in GitHub Desktop.
Example: Upload stuff after post save with schedule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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