Skip to content

Commit 9189c77

Browse files
committed
refactor(includes): Adds file to source configs and wp-cli overrides.
1 parent d782242 commit 9189c77

8 files changed

Lines changed: 25 additions & 8 deletions

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# WP-CLI scripts
22
This is a collection of miscellaneous scripts that utilize [WP-CLI](https://wp-cli.org/), the command line interface for WordPress.
3+
4+
# Usage
5+
Clone this repo and configure the path in `source/configs.sh`. Make the scripts executable as needed (i.e. `chmod +x wpcli-scripts/*.sh`).

count-plugin.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Set the exact slug of the plugin you want to check
44
plugin_slug='classic-editor';
55

6-
source 'source/wp-cli-override.sh';
6+
source 'source/includes.sh';
77

88
# Requires 'bc' for floating-point percentage calculation
99
if ! command -v bc &> /dev/null; then

count-themes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This script audits all sites in a WordPress Multisite network and provides a count and percentage
44
# for every active theme.
55

6-
source 'source/wp-cli-override.sh';
6+
source 'source/includes.sh';
77

88
# Requires 'bc' for floating-point percentage calculation.
99
if ! command -v bc &> /dev/null; then

replace-gravity-form-contact.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This script loops through each network site and replace an email contact with another for Gravity
44
# Forms notifications.
55

6-
source 'source/wp-cli-override.sh';
6+
source 'source/includes.sh';
77

88
old_contacts=("some-person@somesite.com");
99
new_contact="different-person@anothersite.com";

search-posts-content.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ echo;
1919
echo 'Beginning search...';
2020

2121
# Get every network site.
22-
all_site_ids=$(wp --allow-root --skip-themes --skip-plugins site list --field="blog_id" --archived=0);
22+
all_site_ids=$(wp_skip_all site list --field="blog_id");
2323

2424
# Loop over every network site.
2525
for site_id in $all_site_ids; do
@@ -32,10 +32,10 @@ for site_id in $all_site_ids; do
3232
echo "Results for Site ID ${site_id}" >> $output_file;
3333

3434
# Using WP built in search. But "My favorite book" would turn up pages with "my" or "favorite" or "book".
35-
#wp post list --skip-themes --skip-plugins --post_type='page' --search="${term}" --fields="${fields}" --format=csv --url="${site}" | awk 'NR>1' >> $output_file;
35+
#wp_skip_all post list --post_type='page' --search="${term}" --fields="${fields}" --format=csv --url="${site}" | awk 'NR>1' >> $output_file;
3636

3737
# Search for multi term phrases. Cases sensitive.
38-
wp db query --skip-themes --skip-plugins --skip-column-names "SELECT ${fields} FROM wp_${site_id}_posts WHERE post_content REGEXP '${search_regex}' AND post_status='publish';" >> $output_file;
38+
wp_skip_all db query --skip-column-names "SELECT ${fields} FROM wp_${site_id}_posts WHERE post_content REGEXP '${search_regex}' AND post_status='publish';" >> $output_file;
3939

4040
done;
4141

source/configs.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Global configs for these scripts.
2+
3+
config=(
4+
5+
# The path to the root of your WordPress installation.
6+
#
7+
# This is set so that these scripts can live outside of the WordPress installation.
8+
[wp_path]='/var/www/public_html/'
9+
10+
);

source/includes.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file is source'd / included with every script.
2+
3+
source 'configs.sh';
4+
source 'wp-cli-overrides.sh';

source/wp-cli-override.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

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

99

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

0 commit comments

Comments
 (0)