Running wp-cron with wp-cli
#!/bin/bash | |
WP_PATH="/path/to/wp" | |
# Check for WP-CLI | |
if ! hash wp 2>/dev/null; then | |
echo "WP-CLI is not available" | |
exit | |
fi | |
# Fall back if no WP. | |
if ! $(wp core is-installed --path="$WP_PATH" --quiet); then | |
echo "Wrong path maybe? No wordpress installtion found: ${WP_PATH}" | |
exit | |
fi | |
# Get a list of site URLs | |
if $(wp core is-installed --path="$WP_PATH" --quiet --network); | |
then | |
SITE_URLS=`wp site list --fields=url --archived=0 --deleted=0 --format=csv --path="$WP_PATH" | sed 1d` | |
else | |
SITE_URLS=(`wp option get siteurl --path="$WP_PATH"`) | |
fi | |
# Loop all sites | |
for SITE_URL in $SITE_URLS | |
do | |
wp cron event run $( wp cron event list --fields=hook,next_run_relative --format=csv --url="$SITE_URL" --path="$WP_PATH" | awk -F, '$2=="now" {print $1}' ) --url="$SITE_URL" --path="$WP_PATH" --quiet | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment