Your own custom maintenance mode for WordPress

The custom maintenance mode message in WordPress, during upgrades and installs, is far from beautiful 🙂 Time to change that! You can do your own page by adding a pure PHP maintenance.php into your /wp-content folder. Now go and build a nice page ! Just remember that during maintenance no WordPress functionality is available! Enjoy coding …

You might not need jQuery or Javascript!

Transition jQuery has provided easy access to complicated core Javascript solutions in the past and has been shielding us from difficult workarounds for legacy browsers. But times have changed and many of those things can be done as easily using Javascript directly. jQuery is a fast, small, and feature-rich JavaScript library. It makes interactions with HTML documents […]

WPML – Going multilingual with WordPress

Getting started “WPML (WordPress Multilingual) makes it easy to build multilingual sites and run them. It’s powerful enough for corporate sites, yet simple for blogs.” – WPML I have been running and setting up multilingual websites for more than 12 years. WordPress and related integrations have gladly come a long way to make our life’s […]

WP REST API rendered output & Visual Composer

Visual Composer shortcodes are normally not converted within the WordPress REST API rendered output. This can be accomplished by calling WPBMap::addAllMappedShortcodes(); add_action( ‘rest_api_init’, function () { register_rest_field( ‘page’, ‘content’, array( ‘get_callback’ => ‘convert_do_shortcodes’, ‘update_callback’ => null, ‘schema’ => null, ) ); }); function convert_do_shortcodes( $object, $field_name, $request ) { WPBMap::addAllMappedShortcodes(); // This does all the work global […]

World Grain / Milling & Grain – vibronet® advertisment 2025

World Grain + Milling & Grain magazine advertisment 2025 World GrainMilling & Grainvibronet® Gräf GmbH & Co. KG

WordPress: Caching MO-files … Does it make any sense!

First a bit of context 🙂 What is Gettext? Translation within WordPress is based of Gettext. Gettext is a software internationalization and localization (i18n) framework used in many programming languages to facilitate the translation of software applications into different languages. It provides a set of tools and libraries for managing multilingual strings and translating them […]

WordPress Plugins & Sessions

START SESSION ON INIT add_action(‘init’, ‘pluginStartSession’, 1); function pluginStartSession() { if(!session_id()) { session_start(); } } NEW SESSION ON LOGIN / LOGOUT add_action(‘wp_logout’, ‘pluginEndSession’); add_action(‘wp_login’, ‘pluginEndSession’); function pluginEndSession() { session_destroy (); } Now go ahead and use $_SESSION freely in your plugin. Here a nice additional class to  encrypt session data. Enjoy coding ….

WordPress + Query_Posts + Sticky + Pagination

We often have some posts that we would like to promote and keep at the first page of the blog. When you are using pagination, the sticky posts will be added to the standard posts, making the post count per page uneven. If you want to keep your posts per page count consistent, there is […]

Willen Logistics | Business Cards

I designed a fresh set of business cards for Willen Logistics last year, this is a small iteration with a QR-Code on the back. The business cards feature a partial varnish on the logo and QR-Code. I updated their different logos last year, to streamline their main corporate colors. “Seit mehr als 50 Jahren ist […]

White Label Dashboards with cubicFUSION Admin Enhancer for WordPress!

cubicFUSION cubicFUSION is my personal development playground. I always planned to make many of my projects public, but time is limited and running customer projects a priority. I am still doing a big cleanup of my toolset and will see what I can actually share or reuse. Some of these might be useful, inspiration or just an […]

WordPress Cron + WP-CLI + Ntfy

4. January 2025
.SHARE

Table of Contents

THE GOAL

Create a system cron for WordPress, that is accessible and can be easily tweaked to provide more details. Here some basic information about crons and the tools I am going to use …

WordPress CRON

In WordPress, the term “cron” refers to the system used for scheduling tasks to be executed at predefined intervals. The WordPress cron system allows various actions to be scheduled, such as publishing scheduled posts, checking for updates, sending email notifications, and running other scheduled tasks.

WordPress includes its own pseudo-cron system, which relies on visitors accessing your site. When a visitor loads a page on your WordPress site, WordPress checks if there are any scheduled tasks that need to be executed. If there are, it runs those tasks. This system works well for most sites, but it has limitations, particularly for low-traffic sites or sites that need precise scheduling.

To overcome these limitations, WordPress also provides the option to use a real cron system. With a real cron system, tasks are scheduled and executed independently of visitor traffic. This can be more reliable and precise than relying on visitors to trigger cron tasks.

To set up a real cron system for WordPress, you typically need to configure your server’s cron job scheduler to trigger the wp-cron.php file at regular intervals. This file handles the execution of scheduled WordPress tasks.

List scheduled WordPress events

WP Crontrol is a solid UI, to list and see whats happening in the background.

  • View all cron events along with their arguments, recurrence, callback functions, and when they are next due.
  • Edit, delete, pause, resume, and immediately run cron events.
  • Add new cron events.
  • Bulk delete cron events.
  • Add and remove custom cron schedules.
  • Export and download cron event lists as a CSV file.

WP-CLI

WP-CLI (WordPress Command Line Interface) is a powerful command-line tool that allows developers and administrators to interact with WordPress websites directly through the command line, without needing to use a web browser.

It provides a wide range of commands for managing various aspects of a WordPress site, such as executing crons / scheduled tasks, installing plugins, updating themes, managing users, and much more.

Most WordPress hosts have it preinstalled. Installation

Test CRON

Run CRON

ntfy.sh

ntfy (pronounced notify) is a simple HTTP-based pub-sub notification service. It allows you to send notifications to your phone or desktop via scripts from any computer, and/or using a REST API.

You can host your own docker instance or use the hosted solution.

The documentation is detailed and offers many ways to tweak the resulting notification.

Server CRON / THE OLD WAY

Server – CRON / THE NEW COMBINED WAY

I am not showing you how to create a system cron, that can vary depending on your hosting provider. Some of you will just setup / modify the crontab themselves. So here an example of how I use it these days …

Lets dissect this 🙂

Execution Timeframe – Minute / Hour / Day (month) / Month / Day (week)

See example usage on crontab.guru.

Capture the output

Im using a variable to capture the output, allowing me to pass it to ntfy.

The command part 1

Use bash to launch wp-cli, passing in required parameters to make sure the right website is targeted.
I am using –due-now to only launch those schedules that are actually pending. >/dev/null 2>&1 prevents any emails to be send for this cron job, it redirects the error stream into the output stream. Always helpful to remove it for the first testdrive.

>/dev/null: redirects standard output (stdout) to /dev/null
2>&1: redirects standard error (2) to standard output (1), which then discards it as well since standard output has already been redirected 🙂

The command part 2

This part sends the output to a ntfy instance / topic.

  1. -u %token% login / auth with your token
  2. -H “Filename: …” this will move the body text into an attachment file. You can remove this and all output will be part of the body text. ntfy has a body message length limit and will shift to an attachment when reached.
  3. -H “Title: …” Title for the message
  4. -d “$Output” Set the body message to the output we captured, using the set variable
  5. Finally the url to post to, the ntfy instance and topic.

You can set many other things as well, like tags, images …. Check the documentation about publishing for more options. You can even redirect to an email account 😉

Detecting WP-CLI execution programmatically

Detecting WP-CRON execution programmatically

Enjoy coding …
Alex

Let’s Talk!

Looking for a reliable partner to bring your project to the next level? Whether it’s development, design, security, or ongoing support—I’d love to chat and see how I can help.

Get in touch,
and let’s create something amazing together!

RELATED POSTS

Pushing the Boundaries – My Journey Through Early CMS and PHP Development

Back in the early 2000s, content management systems (CMS) were still in their infancy. Websites were mostly static, and managing content dynamically required custom scripts or early blogging tools. My journey into CMS development started with Greymatter, took me through PHP-Nuke, PostNuke, and XOOPS, and ultimately shaped my understanding of PHP and modular web development. […]

Enhancing WordPress Development with the Timber Template System

WordPress has long been the go-to CMS for developers and designers, but its traditional PHP-based templating system can sometimes feel outdated and cumbersome. Enter Timber, a powerful templating framework that brings the flexibility and clarity of the Twig templating language to WordPress. With Timber, developers can separate logic from presentation, leading to cleaner, more maintainable code. All my […]

Day 4: Kimai Time Tracking – 7 Days of Docker

Kimai is a powerful open-source time-tracking application that helps businesses and freelancers efficiently manage work hours and billing. It supports multi-user environments, customizable reporting, and integrations with various tools. In this guide, we’ll walk through setting up Kimai using Docker and explore how to use it effectively. Why Use Kimai with Docker? Running Kimai with […]

Alexander

I am a full-stack developer. My expertise include:

  • Server, Network and Hosting Environments
  • Data Modeling / Import / Export
  • Business Logic
  • API Layer / Action layer / MVC
  • User Interfaces
  • User Experience
  • Understand what the customer and the business needs


I have a deep passion for programming, design, and server architecture—each of these fuels my creativity, and I wouldn’t feel complete without them.

With a broad range of interests, I’m always exploring new technologies and expanding my knowledge wherever needed. The tech world evolves rapidly, and I love staying ahead by embracing the latest innovations.

Beyond technology, I value peace and surround myself with like-minded individuals.

I firmly believe in the principle: Help others, and help will find its way back to you when you need it.