Last active
September 1, 2021 00:02
-
-
Save gbot/8e646df73e0f49682ea2fd03090dc682 to your computer and use it in GitHub Desktop.
Call wp-cron.php on WP Multisite installations
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
#!/bin/bash | |
# Call wp-cron.php on WP Multisite installations | |
# Requires WP-CLI | |
# Looks for WP_PATH in {user_home}/wp-cli.yml, otherwise must pass in as $1 | |
# Set up cron job with crontab -e | |
# Use MAILTO to send output to email or write to a log file 'bash ~/wp_multisite_cron.sh >> crontab.log' | |
# [email protected] | |
# */1 * * * * bash ~/wp_multisite_cron.sh [WP_PATH] | |
if [[ ! -f /usr/local/bin/wp ]]; then | |
echo 'ERROR: WP-CLI not found!' && exit 1 | |
fi | |
# Use either passed in WP_PATH or fetch from ~/wp-cli.yml | |
if [[ $1 ]]; then | |
wp_path="--path=$1" | |
else | |
if [[ ! -f ~/wp-cli.yml ]]; then | |
echo 'ERROR: wp-cli.yml not found! Exiting ...' && exit 1 | |
fi | |
fi | |
# Get the default site for the network (we don't need this so, commented out) | |
# default_site=$( /usr/local/bin/wp option get siteurl $wp_path ) | |
# fetch the network's site urls | |
site_urls=$( /usr/local/bin/wp site list $wp_path --fields=url --archived=0 --deleted=0 --format=csv | tail -n +2 ) | |
# run the cron tasks | |
if [[ $site_urls != '' ]]; then | |
echo | |
echo "**** Running: WP Cron for ALL sites on Multisite network ****" | |
for site in $site_urls; | |
do | |
/usr/local/bin/wp cron event run --due-now --url="$site" $wp_path && echo -e "\t+ Finished crons for $site" | |
done | |
echo "**** Complete: WP Cron ****" | |
echo | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment