-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60c75be
commit 297cef1
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
plugin-developer-learning-pathway/12-Cron/01-Introduction-to-WP-Cron.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Introduction to WP Cron | ||
|
||
On some occasions, we need to have some actions that need to be executed periodically instead of executing when a user has an interaction. | ||
|
||
A good example of this would be a subscription. | ||
|
||
First, we would need some logic to proceed with the registration from the customer to the subscription with some usual logic. | ||
|
||
Then we would have to bill the user monthly, and for this part of the logic we would need a Cron. This is due to the fact we don't want the customer to pay manually each month, but instead we want the payment to proceed automatically. | ||
|
||
## Understanding how Cron works | ||
|
||
A Cron is always based on two parts: | ||
- A recurrence that will define the time when the Cron are executed. | ||
- A task that will be executed when the Cron is fired. | ||
|
||
## WP Cron | ||
|
||
Real crons needs to be settled up by the WordPress user to be able to run, which is not something straightforward nor an easy process. | ||
|
||
That is why WordPress introduced WP Crons, they are emulated crons that run by default on a WordPress website when real crons are not configured. | ||
|
||
That way, users are not left with a broken website if they forgot to set up the crons. | ||
|
||
However, WP Cron also have their own drawbacks compared to crons. | ||
|
||
They rely on a user to load the page to run, and so they can be unreliable if you have little traffic on your website. | ||
|
||
## Switching from WP Cron to Cron | ||
|
||
At the level of the plugin, it is not possible to know of we are using WP Crons or Crons as it will be handled inside WordPress configuration. | ||
|
||
This, even if it can seem like a problem, is in fact good news for us plugin developers. | ||
This due to the fact there will be one syntax to register Crons and WordPress will handle us which one from WP Crons or Crons will be used. |