Skip to content

Instantly share code, notes, and snippets.

View gsarig's full-sized avatar

Giorgos Sarigiannidis gsarig

View GitHub Profile
@gsarig
gsarig / update_sites.sh
Last active December 25, 2023 18:18
Batch update WordPress sites using WP-CLI
#!/bin/bash
# A bash script to batch update a server's WordPress sites with WP-CLI. It requires WP-CLI, obviously (https://wp-cli.org/).
# The script will search for all WordPress installations under a given directory and will update them. You can declare more than one such directories.
# You don't have to modify the script every time you add a new site. As long as the new site is under a declared parent directory, its database will be backed up.
# After creating the file, don't forget to make it executable by doing:
# chmod +x update_sites.sh
# Set PATH environment variable
export PATH="/usr/local/bin:/usr/bin:/bin"
@gsarig
gsarig / superwp.sh
Created December 25, 2023 18:39
Run WP-CLI commands on multiple sites
#!/bin/bash
# A bash script to run WP-CLI commands on multiple sites at once. It requires WP-CLI, obviously (https://wp-cli.org/).
# The script will search for all WordPress installations under a given directory and will run the command. You can declare more than one such directories.
# You don't have to modify the script every time you add a new site. As long as the new site is under a declared parent directory, its database will be backed up.
# After creating the file, don't forget to make it executable by doing: `chmod +x superwp.sh`. Then, include it to `.bashrc` or `.bash_profile` by adding `source path/to/superwp.sh`.
# Then, you can run any `wp` command you like on all the sites of your server, by replacing `wp` with `superwp`.
# Example: `superwp plugin list`.
# We use a function, in order to be able to call it as many times as we want, for as many different directories containing WordPress installations there are on the server
@gsarig
gsarig / localwp-dynamic-db-config.php
Last active January 19, 2025 17:52
Auto-detect MySQL Port for LocalWP Projects in WSL and Windows
<?php
$user = <YOUR_WINDOWS_USERNAME>;
$sites_dir = '/local-sites/'; // The LocalWP sites directory
// Detect environment (Windows vs WSL) and set appropriate path
$is_windows = stripos(PHP_OS, 'WIN') === 0;
$sites_json_path = $is_windows
? "C:/Users/$user/AppData/Roaming/Local/sites.json"
: "/mnt/c/Users/$user/AppData/Roaming/Local/sites.json";