Add/Edit/Delete a Cron Job in WordPress

You are here : Home / Add/Edit/Delete a Cron Job in WordPress

Cron is used when wordpress deals with scheduled activities .The word cron originate from time base work scheduler in Unix .wordpress utilize cron for number of operations.These planned job consist of checking for latest version for wordpress,looking for theme as well as plugins updates and also publishing scheduled article.

One of many typical myths regarding cron in wordpress is usually that cron is consistently functioning searching to get jobs to perform ,this really isn’t the case. Cron is function whenever a front end or admin page is loaded on the website .Each time a page is required, wordpress tests if there are any kind of cron jobs to perform.

Any visit to your website can induce cron, regardless of whether from visitor or even a search engine bot.
For example, you could set a cron job to delete temporary files every week to free up disk space.

In this blog we will discuss about how to add a new cron job by using wp_shedule_event and also to edit and delete this job.

Add a New Cron Job

Schedules a hook which will be executed by the wordpress actions on a specific (Daily,Hourly,twicedaily) interval. The action will activate when somebody visits your wordpress website, if the scheduled time has passed.

Function

$timestamp: The first time that you want the event to occur.
$repetition: It Define the time of next Schedule repetition it may be in hours,twicedaily,daily.
$hook: The name of a hook that we execute.
$args: (optional) Arguments to pass to the hook function(s).

Here we will make a new plugin to create a cron job that help you understand how it works.This plugin is used for sending automatically mail.

Add this code to your plugin folder by making a new corn_job.php file and then activate your corn_job plugin.After activation this plugins look like given below image.

cron job plugin Add/Edit/Delete a Cron Job in WordPress

Edit a Cron Job

You can edit the cron job just by changing the time() of event This must be in a UNIX timestamp format. WP cron uses UTC/GMT time, not local time.
You can change the re-occurrence schedule. Here we are using hourly but you can change it for hourly to daily or twice in a day.
You can also edit function work .Here we are sending automatic email. But you can also assign any other work of our interest.

Delete a cron job

If you using cron jobs in a Plugin, then don’t forget to deactivate or delete the cron if you don’t require it anymore by using delete_aciton

 Add/Edit/Delete a Cron Job in WordPress

Flipper Code

We have been building WordPress Plugins at flipper code since 2008. We follow wordpress coding standard that ensures we deliver the excellent wordpress plugins and services.

More Posts - Website

Follow Me:
twitter Add/Edit/Delete a Cron Job in WordPressfacebook Add/Edit/Delete a Cron Job in WordPressgoogleplus Add/Edit/Delete a Cron Job in WordPress

Customize Product according to your requirements?

We will be glad to discuss any of your needs related to our wordpress plugins . if any of functionality you'd like to see in products, you can reach us by via email hello@flippercode.com.