I have a few custom tables in the database and I need to clean expired data from time to time.
If I was using WP-Cron, it would be easy, but WP-Cron sucks and is a no-go (especially for what I am doing). Having that in mind, I need to launch some code using crontab. How should I do it in a clean, effective manner that would not require nasty hacks?
I was thinking of creating a REST endpoint, but how to protect it so it could only be opened by the crontab?
The solution should be inside the plugin folder so it could be stored in GIT easily (i.e. nasty workarounds storing files in the main folder (a.k.a public_html) are not welcomed).
Was searching for a good solution for hours with no success… Thanks in advance!
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The solution is as @Tom J Nowell mentioned to launch WP Cron via crontab (and disable it on user visits).
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0