Last active
July 20, 2016 18:40
-
-
Save stephenharris/df01b7c471f9c731e50be6b2d9d5d5c3 to your computer and use it in GitHub Desktop.
Can be used to flush the rewrite rules of all sites in a multisite network.
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 | |
# Delete the rewrite_rules of every blog and ping them to recreate the rewrite rules. | |
# | |
# Assumptions: | |
# 1. Your database prefix is wp_ | |
# 2. Your sites are using https:// | |
# 3. The mysql credentials specifed in your .cnf file have the approriate permissions (obviously) | |
# | |
# Usage: ./report-all-blog-themes.sh /path/to/mysql.cnf | |
set -e | |
for DATABASE in $(mysql --defaults-extra-file=$1 --skip-column-names -e "SHOW databases;" --batch); do | |
IS_MULTISITE=$(mysql --defaults-extra-file=$1 --skip-column-names -e "SHOW TABLES FROM $DATABASE LIKE 'wp_site';" --batch) | |
if [ '' == "$IS_MULTISITE" ]; then | |
continue | |
fi | |
for BLOG_ID in $(mysql --defaults-extra-file=$1 -e "SELECT blog_id FROM wp_blogs;" "$DATABASE" --batch --skip-column-names); do | |
URL=$(mysql --defaults-extra-file=$1 -e "SELECT concat( 'https://', domain, path ) AS URL FROM wp_blogs WHERE blog_id = ${BLOG_ID}" $DATABASE) | |
echo $BLOG_ID - $URL; | |
mysql --defaults-extra-file=$1 ${DATABASE} -e "DELETE FROM wp_${BLOG_ID}_options WHERE wp_${BLOG_ID}_options.option_name=\"rewrite_rules\";"; | |
curl -I ${URL} | |
done | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have you used wp-cli ?