📦 NEW: Command hidden-plugins

This commit is contained in:
Austin Ginder 2025-07-02 07:37:26 -04:00
parent 59298f5968
commit 21e948788d
2 changed files with 61 additions and 0 deletions

49
commands/hidden-plugins Normal file
View file

@ -0,0 +1,49 @@
# ----------------------------------------------------
# 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

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 Plugins ---"
echo "$hidden_plugins"
echo "--------------------------"
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
}

12
main
View file

@ -730,6 +730,14 @@ function show_command_help() {
echo "Flags:"
echo " --all Convert all images, regardless of size. Defaults to images > 1MB."
;;
hidden-plugins)
echo "Detects active plugins that may be hidden from the standard WordPress admin view."
echo
echo "Usage: _do hidden-plugins"
echo
echo "This command compares the standard plugin list with a 'raw' list generated by skipping theme"
echo "and plugin execution, which can reveal plugins that are intentionally hiding themselves."
;;
install)
echo "Installs helper or premium plugins."
echo
@ -884,6 +892,7 @@ 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 " hidden-plugins Detects plugins that are active but hidden from the standard list."
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."
@ -1144,6 +1153,9 @@ function main() {
fi
run_dump "${positional_args[1]}" "${exclude_patterns[@]}"
;;
hidden-plugins)
hidden_plugins
;;
install)
local subcommand="${positional_args[1]}"
case "$subcommand" in