mirror of
https://hk.gh-proxy.com/https://github.com/CaptainCore/do.git
synced 2025-10-03 23:34:10 +08:00
👌 IMPROVE: Move hidden-plugins and slow-plugins under find command
This commit is contained in:
parent
33893d4f2e
commit
a6b763cee8
4 changed files with 127 additions and 125 deletions
117
commands/find
117
commands/find
|
@ -31,3 +31,120 @@ function find_recent_files() {
|
|||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Identifies plugins that may be slowing down WP-CLI command execution.
|
||||
# ----------------------------------------------------
|
||||
function find_slow_plugins() {
|
||||
_get_wp_execution_time() { local output; output=$("$WP_CLI_CMD" "$@" --debug 2>&1); echo "$output" | perl -ne '/Debug \(bootstrap\): Running command: .+\(([^s]+s)/ && print $1'; }
|
||||
if ! setup_wp_cli; then echo "❌ Error: WP-CLI (wp command) not found." >&2; return 1; fi
|
||||
if ! "$WP_CLI_CMD" core is-installed --quiet; then echo "❌ Error: This does not appear to be a WordPress installation." >&2; return 1; fi
|
||||
|
||||
echo "🚀 WordPress Plugin Performance Test 🚀"
|
||||
echo "This script measures the execution time of 'wp plugin list --debug' under various conditions."
|
||||
echo ""
|
||||
echo "📋 Initial Baseline Measurements for 'wp plugin list --debug':"
|
||||
|
||||
local time_no_theme_s; printf " ⏳ Measuring time with NO themes loaded (--skip-themes)... "; time_no_theme_s=$(_get_wp_execution_time plugin list --skip-themes); echo "Time: $time_no_theme_s"
|
||||
local time_no_plugins_s; printf " ⏳ Measuring time with NO plugins loaded (--skip-plugins)... "; time_no_plugins_s=$(_get_wp_execution_time plugin list --skip-plugins); echo "Time: $time_no_plugins_s"
|
||||
local base_time_s; printf " ⏳ Measuring base time (ALL plugins & theme active)... "; base_time_s=$(_get_wp_execution_time plugin list)
|
||||
if [[ -z "$base_time_s" ]]; then echo "❌ Error: Could not measure base execution time." >&2; return 1; fi;
|
||||
echo "Base time: $base_time_s"
|
||||
echo ""
|
||||
|
||||
local active_plugins=()
|
||||
while IFS= read -r line; do
|
||||
active_plugins+=("$line")
|
||||
done < <("$WP_CLI_CMD" plugin list --field=name --status=active)
|
||||
|
||||
if [[ ${#active_plugins[@]} -eq 0 ]]; then echo "ℹ️ No active plugins found to test."; return 0; fi
|
||||
|
||||
echo "📊 Measuring impact of individual plugins (compared to '${base_time_s}' base time):"
|
||||
echo "A larger positive 'Impact' suggests the plugin contributes more to the load time of this specific WP-CLI command."
|
||||
|
||||
echo "---------------------------------------------------------------------------------"; printf "%-40s | %-15s | %-15s\n" "Plugin Skipped" "Time w/ Skip" "Impact (Base-Skip)"; echo "---------------------------------------------------------------------------------"
|
||||
local results=(); for plugin in "${active_plugins[@]}"; do
|
||||
local time_with_skip_s; time_with_skip_s=$(_get_wp_execution_time plugin list --skip-plugins="$plugin")
|
||||
if [[ -n "$time_with_skip_s" ]]; then
|
||||
local diff_s; diff_s=$(awk -v base="${base_time_s%s}" -v skip="${time_with_skip_s%s}" 'BEGIN { printf "%.3f", base - skip }')
|
||||
local impact_sign=""
|
||||
if [[ $(awk -v diff="$diff_s" 'BEGIN { print (diff > 0) }') -eq 1 ]]; then
|
||||
impact_sign="+"
|
||||
fi
|
||||
results+=("$(printf "%.3f" "$diff_s")|$plugin|$time_with_skip_s|${impact_sign}${diff_s}s")
|
||||
else results+=("0.000|$plugin|Error|Error measuring"); fi
|
||||
done
|
||||
|
||||
local sorted_results=()
|
||||
while IFS= read -r line; do
|
||||
sorted_results+=("$line")
|
||||
done < <(printf "%s\n" "${results[@]}" | sort -t'|' -k1,1nr)
|
||||
|
||||
for result_line in "${sorted_results[@]}"; do
|
||||
local p_name; p_name=$(echo "$result_line" | cut -d'|' -f2); local t_skip; t_skip=$(echo "$result_line" | cut -d'|' -f3); local i_str; i_str=$(echo "$result_line" | cut -d'|' -f4)
|
||||
printf "%-40s | %-15s | %-15s\n" "$p_name" "$t_skip" "$i_str"
|
||||
done
|
||||
echo "---------------------------------------------------------------------------------"; echo ""; echo "✅ Test Complete"
|
||||
echo "💡 Note: This measures impact on a specific WP-CLI command. For front-end or"; echo " admin profiling, consider using a plugin like Query Monitor or New Relic."; echo ""
|
||||
}
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Detects plugins that are active but hidden from the standard plugin list.
|
||||
# ----------------------------------------------------
|
||||
function find_hidden_plugins() {
|
||||
# --- Pre-flight Checks ---
|
||||
if ! setup_wp_cli; then echo "❌ Error: WP-CLI not found." >&2; return 1; fi
|
||||
if ! "$WP_CLI_CMD" core is-installed --quiet; then echo "❌ Error: This does not appear to be a WordPress installation." >&2; return 1; fi
|
||||
if ! setup_gum; then return 1; fi
|
||||
|
||||
echo "🚀 Checking for hidden WordPress plugins..."
|
||||
|
||||
# Get the standard list of active plugins
|
||||
local active_plugins
|
||||
active_plugins=$("$WP_CLI_CMD" plugin list --field=name --status=active)
|
||||
|
||||
# Get the "raw" list of active plugins by skipping themes and other plugins
|
||||
local active_plugins_raw
|
||||
active_plugins_raw=$("$WP_CLI_CMD" plugin list --field=name --status=active --skip-themes --skip-plugins)
|
||||
|
||||
local regular_count
|
||||
regular_count=$(echo "$active_plugins" | wc -l | xargs)
|
||||
local raw_count
|
||||
raw_count=$(echo "$active_plugins_raw" | wc -l | xargs)
|
||||
|
||||
# Compare the counts of the two lists.
|
||||
if [[ "$regular_count" == "$raw_count" ]]; then
|
||||
echo "✅ No hidden plugins detected. The standard and raw plugin lists match ($regular_count plugins)."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# If the counts differ, find the plugins that are in the raw list but not the standard one.
|
||||
echo "⚠️ Found a discrepancy between plugin lists!"
|
||||
echo " - Standard list shows: $regular_count active plugins."
|
||||
echo " - Raw list shows: $raw_count active plugins."
|
||||
echo
|
||||
|
||||
# Use 'comm' to find lines unique to the raw list.
|
||||
local hidden_plugins
|
||||
hidden_plugins=$(comm -13 <(echo "$active_plugins" | sort) <(echo "$active_plugins_raw" | sort))
|
||||
|
||||
if [ -z "$hidden_plugins" ]; then
|
||||
echo "ℹ️ Could not isolate the specific hidden plugins, but a discrepancy exists."
|
||||
else
|
||||
echo "--- Found Hidden Plugin(s) ---"
|
||||
# Loop through each hidden plugin and get its details
|
||||
while IFS= read -r plugin; do
|
||||
if [ -z "$plugin" ]; then continue; fi
|
||||
|
||||
"$GUM_CMD" log --level warn "Details for: $plugin"
|
||||
|
||||
# Get plugin details in CSV format and pipe to gum for a clean table printout.
|
||||
"$WP_CLI_CMD" plugin get "$plugin" --skip-plugins --skip-themes --format=csv | \
|
||||
"$GUM_CMD" table --separator "," --widths=15,0 --print
|
||||
|
||||
echo
|
||||
done <<< "$hidden_plugins"
|
||||
echo "💡 These plugins are active but may be hidden from the admin view or standard WP-CLI list."
|
||||
echo " Common offenders are management plugins (like ManageWP's 'worker') or potentially malicious code."
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
# ----------------------------------------------------
|
||||
# Detects plugins that are active but hidden from the standard plugin list.
|
||||
# ----------------------------------------------------
|
||||
function hidden_plugins() {
|
||||
# --- Pre-flight Checks ---
|
||||
if ! setup_wp_cli; then echo "❌ Error: WP-CLI not found." >&2; return 1; fi
|
||||
if ! "$WP_CLI_CMD" core is-installed --quiet; then echo "❌ Error: This does not appear to be a WordPress installation." >&2; return 1; fi
|
||||
if ! setup_gum; then return 1; fi
|
||||
|
||||
echo "🚀 Checking for hidden WordPress plugins..."
|
||||
|
||||
# Get the standard list of active plugins
|
||||
local active_plugins
|
||||
active_plugins=$("$WP_CLI_CMD" plugin list --field=name --status=active)
|
||||
|
||||
# Get the "raw" list of active plugins by skipping themes and other plugins
|
||||
local active_plugins_raw
|
||||
active_plugins_raw=$("$WP_CLI_CMD" plugin list --field=name --status=active --skip-themes --skip-plugins)
|
||||
|
||||
local regular_count
|
||||
regular_count=$(echo "$active_plugins" | wc -l | xargs)
|
||||
local raw_count
|
||||
raw_count=$(echo "$active_plugins_raw" | wc -l | xargs)
|
||||
|
||||
# Compare the counts of the two lists.
|
||||
if [[ "$regular_count" == "$raw_count" ]]; then
|
||||
echo "✅ No hidden plugins detected. The standard and raw plugin lists match ($regular_count plugins)."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# If the counts differ, find the plugins that are in the raw list but not the standard one.
|
||||
echo "⚠️ Found a discrepancy between plugin lists!"
|
||||
echo " - Standard list shows: $regular_count active plugins."
|
||||
echo " - Raw list shows: $raw_count active plugins."
|
||||
echo
|
||||
|
||||
# Use 'comm' to find lines unique to the raw list.
|
||||
local hidden_plugins
|
||||
hidden_plugins=$(comm -13 <(echo "$active_plugins" | sort) <(echo "$active_plugins_raw" | sort))
|
||||
|
||||
if [ -z "$hidden_plugins" ]; then
|
||||
echo "ℹ️ Could not isolate the specific hidden plugins, but a discrepancy exists."
|
||||
else
|
||||
echo "--- Found Hidden Plugin(s) ---"
|
||||
# Loop through each hidden plugin and get its details
|
||||
while IFS= read -r plugin; do
|
||||
if [ -z "$plugin" ]; then continue; fi
|
||||
|
||||
"$GUM_CMD" log --level warn "Details for: $plugin"
|
||||
|
||||
# Get plugin details in CSV format and pipe to gum for a clean table printout.
|
||||
"$WP_CLI_CMD" plugin get "$plugin" --skip-plugins --skip-themes --format=csv | \
|
||||
"$GUM_CMD" table --separator "," --widths=15,0 --print
|
||||
|
||||
echo
|
||||
done <<< "$hidden_plugins"
|
||||
echo "💡 These plugins are active but may be hidden from the admin view or standard WP-CLI list."
|
||||
echo " Common offenders are management plugins (like ManageWP's 'worker') or potentially malicious code."
|
||||
fi
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
# ----------------------------------------------------
|
||||
# Identifies plugins that may be slowing down WP-CLI command execution.
|
||||
# ----------------------------------------------------
|
||||
function identify_slow_plugins() {
|
||||
_get_wp_execution_time() { local output; output=$("$WP_CLI_CMD" "$@" --debug 2>&1); echo "$output" | perl -ne '/Debug \(bootstrap\): Running command: .+\(([^s]+s)/ && print $1'; }
|
||||
if ! setup_wp_cli; then echo "❌ Error: WP-CLI (wp command) not found." >&2; return 1; fi
|
||||
if ! "$WP_CLI_CMD" core is-installed --quiet; then echo "❌ Error: This does not appear to be a WordPress installation." >&2; return 1; fi
|
||||
|
||||
echo "🚀 WordPress Plugin Performance Test 🚀"
|
||||
echo "This script measures the execution time of 'wp plugin list --debug' under various conditions."
|
||||
echo ""
|
||||
echo "📋 Initial Baseline Measurements for 'wp plugin list --debug':"
|
||||
|
||||
local time_no_theme_s; printf " ⏳ Measuring time with NO themes loaded (--skip-themes)... "; time_no_theme_s=$(_get_wp_execution_time plugin list --skip-themes); echo "Time: $time_no_theme_s"
|
||||
local time_no_plugins_s; printf " ⏳ Measuring time with NO plugins loaded (--skip-plugins)... "; time_no_plugins_s=$(_get_wp_execution_time plugin list --skip-plugins); echo "Time: $time_no_plugins_s"
|
||||
local base_time_s; printf " ⏳ Measuring base time (ALL plugins & theme active)... "; base_time_s=$(_get_wp_execution_time plugin list)
|
||||
if [[ -z "$base_time_s" ]]; then echo "❌ Error: Could not measure base execution time." >&2; return 1; fi;
|
||||
echo "Base time: $base_time_s"
|
||||
echo ""
|
||||
|
||||
local active_plugins=()
|
||||
while IFS= read -r line; do
|
||||
active_plugins+=("$line")
|
||||
done < <("$WP_CLI_CMD" plugin list --field=name --status=active)
|
||||
|
||||
if [[ ${#active_plugins[@]} -eq 0 ]]; then echo "ℹ️ No active plugins found to test."; return 0; fi
|
||||
|
||||
echo "📊 Measuring impact of individual plugins (compared to '${base_time_s}' base time):"
|
||||
echo "A larger positive 'Impact' suggests the plugin contributes more to the load time of this specific WP-CLI command."
|
||||
|
||||
echo "---------------------------------------------------------------------------------"; printf "%-40s | %-15s | %-15s\n" "Plugin Skipped" "Time w/ Skip" "Impact (Base-Skip)"; echo "---------------------------------------------------------------------------------"
|
||||
local results=(); for plugin in "${active_plugins[@]}"; do
|
||||
local time_with_skip_s; time_with_skip_s=$(_get_wp_execution_time plugin list --skip-plugins="$plugin")
|
||||
if [[ -n "$time_with_skip_s" ]]; then
|
||||
local diff_s; diff_s=$(awk -v base="${base_time_s%s}" -v skip="${time_with_skip_s%s}" 'BEGIN { printf "%.3f", base - skip }')
|
||||
local impact_sign=""
|
||||
if [[ $(awk -v diff="$diff_s" 'BEGIN { print (diff > 0) }') -eq 1 ]]; then
|
||||
impact_sign="+"
|
||||
fi
|
||||
results+=("$(printf "%.3f" "$diff_s")|$plugin|$time_with_skip_s|${impact_sign}${diff_s}s")
|
||||
else results+=("0.000|$plugin|Error|Error measuring"); fi
|
||||
done
|
||||
|
||||
local sorted_results=()
|
||||
while IFS= read -r line; do
|
||||
sorted_results+=("$line")
|
||||
done < <(printf "%s\n" "${results[@]}" | sort -t'|' -k1,1nr)
|
||||
|
||||
for result_line in "${sorted_results[@]}"; do
|
||||
local p_name; p_name=$(echo "$result_line" | cut -d'|' -f2); local t_skip; t_skip=$(echo "$result_line" | cut -d'|' -f3); local i_str; i_str=$(echo "$result_line" | cut -d'|' -f4)
|
||||
printf "%-40s | %-15s | %-15s\n" "$p_name" "$t_skip" "$i_str"
|
||||
done
|
||||
echo "---------------------------------------------------------------------------------"; echo ""; echo "✅ Test Complete"
|
||||
echo "💡 Note: This measures impact on a specific WP-CLI command. For front-end or"; echo " admin profiling, consider using a plugin like Query Monitor or New Relic."; echo ""
|
||||
}
|
20
main
20
main
|
@ -723,12 +723,14 @@ function show_command_help() {
|
|||
echo " _do dump \"*\" -x \"*.log\" -x \"node_modules/\""
|
||||
;;
|
||||
find)
|
||||
echo "Finds files based on specific criteria."
|
||||
echo "Finds files or WordPress components based on specific criteria."
|
||||
echo
|
||||
echo "Usage: _do find <subcommand> [arguments]"
|
||||
echo
|
||||
echo "Subcommands:"
|
||||
echo " recent-files [days] Finds files modified within the last <days>. Defaults to 1 day."
|
||||
echo " slow-plugins Identifies plugins that may be slowing down WP-CLI."
|
||||
echo " hidden-plugins Detects active plugins that may be hidden from the standard list."
|
||||
;;
|
||||
convert-to-webp)
|
||||
echo "Finds and converts large images (JPG, PNG) to WebP format."
|
||||
|
@ -900,15 +902,13 @@ function show_usage() {
|
|||
echo " cron Manages cron jobs and schedules tasks to run at specific times."
|
||||
echo " db Performs various database operations (backup, check-autoload, optimize)."
|
||||
echo " dump Dumps the content of files matching a pattern into a single text file."
|
||||
echo " find Finds files based on specific criteria."
|
||||
echo " hidden-plugins Detects plugins that are active but hidden from the standard list."
|
||||
echo " find Finds files, slow plugins, or hidden plugins."
|
||||
echo " install Installs helper plugins or premium plugins."
|
||||
echo " migrate Migrates a site from a backup URL or local file."
|
||||
echo " monitor Monitors server logs or errors in real-time."
|
||||
echo " php-tags Finds outdated or invalid PHP opening tags."
|
||||
echo " reset-wp Resets the WordPress installation to a default state."
|
||||
echo " reset-permissions Resets file and folder permissions to defaults."
|
||||
echo " slow-plugins Identifies plugins that may be slowing down WP-CLI."
|
||||
echo " suspend Activates or deactivates a suspend message shown to visitors."
|
||||
echo " update Runs WordPress updates and logs the changes."
|
||||
echo " upgrade Upgrades this script to the latest version."
|
||||
|
@ -1168,15 +1168,18 @@ function main() {
|
|||
recent-files)
|
||||
find_recent_files "${positional_args[2]}"
|
||||
;;
|
||||
slow-plugins)
|
||||
find_slow_plugins
|
||||
;;
|
||||
hidden-plugins)
|
||||
find_hidden_plugins
|
||||
;;
|
||||
*)
|
||||
show_command_help "find"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
hidden-plugins)
|
||||
hidden_plugins
|
||||
;;
|
||||
install)
|
||||
local subcommand="${positional_args[1]}"
|
||||
case "$subcommand" in
|
||||
|
@ -1238,9 +1241,6 @@ function main() {
|
|||
reset-permissions)
|
||||
reset_permissions
|
||||
;;
|
||||
slow-plugins)
|
||||
identify_slow_plugins
|
||||
;;
|
||||
suspend)
|
||||
local arg1="${positional_args[1]}"
|
||||
case "$arg1" in
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue