{"id":3501,"date":"2011-12-06T12:50:12","date_gmt":"2011-12-06T19:50:12","guid":{"rendered":"http:\/\/www.ait-pro.com\/aitpro-blog\/?p=3501"},"modified":"2011-12-08T10:19:05","modified_gmt":"2011-12-08T17:19:05","slug":"wordpress-cron-job-change-wordpress-cron-job-schedule-change-wordpress-cron-job-time","status":"publish","type":"post","link":"https:\/\/www.ait-pro.com\/aitpro-blog\/3501\/misc-projects\/wordpress-tips-tricks-fixes\/wordpress-cron-job-change-wordpress-cron-job-schedule-change-wordpress-cron-job-time\/","title":{"rendered":"WordPress Cron Job &#8211; Change WordPress Cron Job Schedule, Change WordPress Cron Job Time"},"content":{"rendered":"<p>I looked around for the best way to quickly change a WordPress Scheduled Cron job and amazingly did not come across an answer right away. \u00a0Maybe changing the WordPress Cron Schedule Time is such a simple thing to do that no one bothered creating a post about it. \u00a0There are \u00a0several different WordPress pre-made functions that could be used to either remove or unschedule a Cron job so I was just looking for the quickest, cleanest, best and \/ or recommended way to to this with the least amount of coding changes to the existing WordPress Scheduled Cron job functions and hooks.<\/p>\n<h2><span style=\"color: #000066;\"><strong>Here is the WordPress Scheduled Cron scenario:<\/strong><\/span><\/h2>\n<p>I had an existing WordPress Scheduled Cron job that was scheduled to run weekly to check for available plugin updates and wanted to change it to daily scheduled cron job. \u00a0Since existing users of the plugin already had scheduled crons jobs set to fire on a weekly basis I needed the old weekly WordPress scheduled cron job to be cleared or unscheduled or replaced with the new daily scheduled cron job. \u00a0Seems simple enough right, but when checking for available ways to do this I came across too many options and did not find &#8220;the best recommended&#8221; way to do this. \u00a0I cannot say with 100% certainty that this is the best way to change or reschedule a WordPress cron job, but it definitely has to be the simplest and easiest way to do this.<\/p>\n<h2><strong><span style=\"color: #000066;\">The old WordPress Weekly Scheduled Cron job code:<\/span><\/strong><\/h2>\n<pre>\/\/ WP weekly scheduled Cron job\r\nfunction bpsPro_add_weekly_cron( $schedules ) {\r\n\t$schedules['weekly'] = array('interval' =&gt; 604800, 'display' =&gt; __('Once Weekly'));\r\n\treturn $schedules;\r\n}\r\nadd_filter('cron_schedules', 'bpsPro_add_weekly_cron');\r\n\r\n\/\/ checking current installed version against currently available version\r\nfunction bpsPro_update_checks() {\r\n\/\/ your code that does your plugin version update checking\r\n}\r\nadd_action('bpsPro_update_check', 'bpsPro_update_checks');\r\n\r\n\/\/ Weekly Cron Job - bpsPro_update_check\r\nfunction bpsPro_schedule_update_checks() {\r\n\tif (!wp_next_scheduled('bpsPro_update_check')) {\r\n\t\twp_schedule_event(time(), 'weekly', 'bpsPro_update_check');\r\n\t}\r\n}\r\nadd_action('init', 'bpsPro_schedule_update_checks');\r\n<\/pre>\n<h2><span style=\"color: #000066;\"><strong>The new WordPress Daily Scheduled Cron job code with the old code commented out and new code has been highlighted:<\/strong><\/span><\/h2>\n<pre>\/\/ Was a WP weekly scheduled Cron job is now a Daily scheduled cron job\r\nfunction bpsPro_add_weekly_cron( $schedules ) {\r\n\t\/\/$schedules['weekly'] = array('interval' =&gt; 604800, 'display' =&gt; __('Once Weekly'));\r\n\t<span style=\"background-color: #ffff99;\">$schedules['daily'] = array('interval' =&gt; 86400, 'display' =&gt; __('Once Daily'));<\/span>\r\n\treturn $schedules;\r\n}\r\nadd_filter('cron_schedules', 'bpsPro_add_weekly_cron');\r\n\r\n\/\/ checking current installed version against currently available version\r\nfunction bpsPro_update_checks() {\r\n\/\/ your code that does your plugin version update checking\r\n}\r\nadd_action('bpsPro_update_check', 'bpsPro_update_checks');\r\n\r\n\/\/ Was a Weekly Cron Job now a Daily Cron - bpsPro_update_check\r\nfunction bpsPro_schedule_update_checks() {\r\n\t<span style=\"background-color: #ffff99;\">$bpsCronCheck = wp_get_schedule('bpsPro_update_check');<\/span>\r\n\r\n\t<span style=\"background-color: #ffff99;\">if ($bpsCronCheck == 'weekly') {<\/span>\r\n\t<span style=\"background-color: #ffff99;\">wp_clear_scheduled_hook('bpsPro_update_check');<\/span>\r\n\t<span style=\"background-color: #ffff99;\">}<\/span>\r\n\tif (!wp_next_scheduled('bpsPro_update_check')) {\r\n\t\t\/\/wp_schedule_event(time(), 'weekly', 'bpsPro_update_check');\r\n\t\t<span style=\"background-color: #ffff99;\">wp_schedule_event(time(), 'daily', 'bpsPro_update_check');<\/span>\r\n\t}\r\n}\r\nadd_action('init', 'bpsPro_schedule_update_checks');\r\n<\/pre>\n<p>So if you are looking for the simplest and quickest way to change a WordPress Scheduled Cron job Time or frequency then this worked well for me without any problems down the road. \u00a0And of course this is something very simple, but like I said I was looking for the recommended best way to do this and did not come across that info. \u00a0If you know of a better recommended way to do this please leave a comment. \u00a0\ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I looked around for the best way to quickly change a WordPress Scheduled Cron job and amazingly did not come across an answer right away. \u00a0Maybe changing the WordPress Cron Schedule Time is such a simple thing to do that no one bothered creating a post about it. \u00a0There are \u00a0several different WordPress pre-made functions [&hellip;]<\/p>\n","protected":false},"author":167,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[13],"tags":[462,460,461,463],"class_list":["post-3501","post","type-post","status-publish","format-standard","hentry","category-wordpress-tips-tricks-fixes","tag-change-wordpress-cron-job-frequency","tag-change-wordpress-cron-job-schedule","tag-change-wordpress-cron-job-time","tag-wordpress-cron-change-weekly-to-daily"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ait-pro.com\/aitpro-blog\/wp-json\/wp\/v2\/posts\/3501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ait-pro.com\/aitpro-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ait-pro.com\/aitpro-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ait-pro.com\/aitpro-blog\/wp-json\/wp\/v2\/users\/167"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ait-pro.com\/aitpro-blog\/wp-json\/wp\/v2\/comments?post=3501"}],"version-history":[{"count":0,"href":"https:\/\/www.ait-pro.com\/aitpro-blog\/wp-json\/wp\/v2\/posts\/3501\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ait-pro.com\/aitpro-blog\/wp-json\/wp\/v2\/media?parent=3501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ait-pro.com\/aitpro-blog\/wp-json\/wp\/v2\/categories?post=3501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ait-pro.com\/aitpro-blog\/wp-json\/wp\/v2\/tags?post=3501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}