Created
August 13, 2025 18:11
-
-
Save kpirnie/252f527d49d6baf97c4a6b7cadce24d9 to your computer and use it in GitHub Desktop.
WordPress Server-Side Cron Replacement
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # hold the primary WP CLI command | |
| WP_CLI="wp --allow-root --path=" | |
| # hold the starting path | |
| _PATH=/home/*/htdocs/* | |
| # loop over our home directory for the htdocs folder... | |
| for d in $_PATH; do | |
| # now hold the formatted command | |
| CMD=$WP_CLI$d/; | |
| # check if this site is indeed a wordpress website | |
| if $CMD core is-installed 2>/dev/null; then | |
| # check if the site is a network | |
| if $CMD core is-installed --network 2>/dev/null; then | |
| # get the networks list of uri's | |
| _uris=$( $CMD site list --field=url ) | |
| # loop over the sites | |
| for _uri in $_uris; do | |
| # fire off the sites cron | |
| $CMD cron event run --all --due-now --url="$_uri" & | |
| done; | |
| # otherwise, we aren't in a network | |
| else | |
| # get the site's uri | |
| _uri=$( $CMD option get siteurl ); | |
| # fire off the sites cron | |
| $CMD cron event run --all --due-now --url="$_uri" & | |
| fi; | |
| fi; | |
| done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment