Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions source/config-sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ declare -A config=(
# This is set so that these scripts can live outside of the WordPress installation.
[wp_path]='/var/www/public_html/'

# Whether or not to allow root to run wpcli.
#
# By default wpcli will display an error and exit if you run it as root. Set this to 1 to enable
# running wpcli as root.
[allow_root]=0

);
50 changes: 48 additions & 2 deletions source/wp-cli-overrides.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,59 @@

# Usage of the wp command on the main site. Skips themes and plugins.
wp_skip_all () {
wp --skip-themes --skip-plugins --path="${config[wp_path]}" "$@"

# Setup the variable for building a wpcli command.
local -a cmd=( wp )

# Add the wpcli command to run and any additional flags that were used.
cmd+=( "$@" )

# Check if a path to a WP installation was provided. If none was provided, wpcli will default to
# the current directory.
if [[ -n "${config[wp_path]:-}" ]]; then
cmd+=( --path="${config[wp_path]}" )
fi

# Check if allow root was set to 1 and add the flag.
if (( config[allow_root] )); then
cmd+=( --allow-root )
fi

# Add flags to use every time.
cmd+=( '--skip-themes --skip-plugins' )

# Run the command
"${cmd[@]}"

}


# Usage of the wp command for a specific site.
#
# It expects $site_url to be set. This is useful in a for loop of every site.
wp_on_site () {
wp --skip-themes --skip-plugins --path="${config[wp_path]}" --url="${site_url}" "$@"

# Setup the variable for building a wpcli command.
local -a cmd=( wp )

# Add the wpcli command to run and any additional flags that were used.
cmd+=( "$@" )

# Check if a path to a WP installation was provided. If none was provided, wpcli will default to
# the current directory.
if [[ -n "${config[wp_path]:-}" ]]; then
cmd+=( --path="${config[wp_path]}" )
fi

# Check if allow root was set to 1 and add the flag.
if (( config[allow_root] )); then
cmd+=( --allow-root )
fi

# Add flags to use every time.
cmd+=( --skip-themes --skip-plugins --url="${site_url}" )

# Run the command
"${cmd[@]}"

}
14 changes: 7 additions & 7 deletions user-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ source 'source/includes.sh';

fields_to_display='user_login,user_email,roles';

log_file='user-list.txt';
output_file='user-list.txt';

echo '#########################################################' | tee "$log_file";
echo 'Users by WordPress site' | tee -a "$log_file";
echo '#########################################################' | tee -a "$log_file";
echo '#########################################################' | tee "$output_file";
echo 'Users by WordPress site' | tee -a "$output_file";
echo '#########################################################' | tee -a "$output_file";

for site_url in $(wp_skip_all site list --field="url" --archived=0 --deleted=0 --spam=0); do

echo '-------------------------------------------------' | tee -a "$log_file";
echo "Site ${site_url}" | tee -a "$log_file";
wp_on_site user list --fields="${fields_to_display}" | tee -a "$log_file";
echo '-------------------------------------------------' | tee -a "$output_file";
echo "Site ${site_url}" | tee -a "$output_file";
wp_on_site user list --format=csv --fields="${fields_to_display}" | tee -a "$output_file";

done;
Loading