Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
51f58cd
Add more error case for addons login
superdav42 Jan 12, 2026
c22e008
fix warnings in php 8.5
superdav42 Jan 12, 2026
e596f44
Fix fatal loading user page
superdav42 Jan 13, 2026
d8c7b27
Actually process site creation immediately and asynchronously
superdav42 Jan 13, 2026
7f90d52
Add configurable password strength settings with Super Strong level
superdav42 Jan 14, 2026
0732a0e
Simplify JS localization by reading i18n object directly
superdav42 Jan 14, 2026
cbe4598
Add opt-in telemetry tracking, WooCommerce Subscriptions compat, and …
superdav42 Jan 16, 2026
d471b2f
Address CodeRabbit review feedback and bump version to 2.4.10
superdav42 Jan 16, 2026
20b56e5
Fix template switching showing too many templates and improve error h…
superdav42 Jan 16, 2026
8e17768
Allow hiding logo in email template
superdav42 Jan 16, 2026
e8bc4ff
fix fatal in blocks
superdav42 Jan 16, 2026
825d250
Fix pre-commit hook to retain PHP checks alongside JS/CSS linting
superdav42 Jan 17, 2026
9164ff1
Add meta key constants to model classes to prevent typo bugs
superdav42 Jan 20, 2026
678d1e7
Add notice to ask nicely for a review
superdav42 Jan 20, 2026
ba70b62
Enable tax rates page if taxes are disabled
superdav42 Jan 20, 2026
24a35c4
Add tracking
superdav42 Jan 20, 2026
e9f8a31
Use the correct path
superdav42 Jan 20, 2026
469e3d9
Fix warnings
superdav42 Jan 20, 2026
3ac470b
Add tracking information
superdav42 Jan 20, 2026
ba9acc6
Allow source files
superdav42 Jan 20, 2026
b53dced
Add new element for createing a magic login link
superdav42 Jan 23, 2026
1ca40bc
Add nav menu subsite links with magic link support
superdav42 Jan 23, 2026
5abab18
Fix WooCommerce Subscriptions compat and username spaces
superdav42 Jan 23, 2026
e70a827
Improve site locking hook timing and REST API support
superdav42 Jan 23, 2026
9711fb2
Add error handling to template switching
superdav42 Jan 23, 2026
4328334
Update translation strings
superdav42 Jan 23, 2026
850efe6
Update inc/class-tracker.php
superdav42 Jan 23, 2026
73c16a9
Update inc/debug/class-debug.php
superdav42 Jan 23, 2026
8b10f68
tweaks
superdav42 Jan 23, 2026
f5f1ba9
Merge remote-tracking branch 'origin/fix/322-change-templates-filter-…
superdav42 Jan 23, 2026
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
175 changes: 107 additions & 68 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

# Pre-commit hook for running phpcs and phpstan on changed files
# This hook runs PHPCS and PHPStan on staged PHP files
# Pre-commit hook for Ultimate Multisite
# Runs PHPCS and PHPStan on staged PHP files
# Runs ESLint and Stylelint on staged JS/CSS files

set -e

Expand All @@ -13,95 +14,133 @@ NC='\033[0m' # No Color

echo -e "${GREEN}Running pre-commit checks...${NC}"

# Get list of staged PHP files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.php$' | grep -v '^vendor/' | grep -v '^tests/' || true)
HAS_ERRORS=0

if [ -z "$STAGED_FILES" ]; then
echo -e "${GREEN}No PHP files to check.${NC}"
exit 0
fi
# =============================================================================
# PHP Checks (PHPCS and PHPStan)
# =============================================================================

echo -e "${YELLOW}Checking PHP files:${NC}"
echo "$STAGED_FILES"
# Get list of staged PHP files
STAGED_PHP_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.php$' | grep -v '^vendor/' | grep -v '^tests/' || true)

Comment on lines +23 to 25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n .githooks/pre-commit

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 6114


🏁 Script executed:

git ls-files | awk '/[[:space:]]/'

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 63


Use quoted variable expansion and bash arrays for safer filename handling.

The unquoted $STAGED_PHP_FILES and $STAGED_JS_CSS_FILES variables in for loops (lines 40, 54, 73, 88, 95) will split on whitespace. While your repository currently has no tracked files with whitespace, this remains a best practice issue for robustness. Consider using NUL-delimited lists with arrays as shown in the proposed fix to handle any filenames safely.

🤖 Prompt for AI Agents
In @.githooks/pre-commit around lines 23 - 25, The for-loops iterate unquoted
STAGED_PHP_FILES and STAGED_JS_CSS_FILES, causing word-splitting on filenames
with whitespace; replace the current pipeline with NUL-delimited output (use git
diff --name-only --diff-filter=ACM -z) and populate bash arrays (e.g., readarray
-d '' STAGED_PHP_FILES_ARRAY or while IFS= read -r -d '' f; do ...; done) then
iterate using quoted array expansion (for f in "${STAGED_PHP_FILES_ARRAY[@]}";
do ...) and ensure all expansions of these variables are quoted to safely handle
filenames with spaces or special characters.

# Check if composer dependencies are installed
if [ ! -f "vendor/bin/phpcs" ] || [ ! -f "vendor/bin/phpstan" ]; then
echo -e "${RED}Error: Please run 'composer install' to install development dependencies.${NC}"
exit 1
fi
if [ -n "$STAGED_PHP_FILES" ]; then
echo -e "${YELLOW}Checking PHP files:${NC}"
echo "$STAGED_PHP_FILES"

# Run PHPCS on staged files
echo -e "${YELLOW}Running PHPCS...${NC}"
HAS_PHPCS_ERRORS=0
PHPCS_FAILED_FILES=""
for FILE in $STAGED_FILES; do
if [ -f "$FILE" ]; then
if ! vendor/bin/phpcs --colors "$FILE"; then
PHPCS_FAILED_FILES="$PHPCS_FAILED_FILES $FILE"
HAS_PHPCS_ERRORS=1
fi
# Check if composer dependencies are installed
if [ ! -f "vendor/bin/phpcs" ] || [ ! -f "vendor/bin/phpstan" ]; then
echo -e "${RED}Error: Please run 'composer install' to install development dependencies.${NC}"
exit 1
fi
done

# If PHPCS found errors, try to auto-fix them with PHPCBF
if [ $HAS_PHPCS_ERRORS -ne 0 ]; then
echo -e "${YELLOW}PHPCS found errors. Running PHPCBF to auto-fix...${NC}"

FIXED_FILES=""
for FILE in $PHPCS_FAILED_FILES; do
# Run PHPCS on staged files
echo -e "${YELLOW}Running PHPCS...${NC}"
HAS_PHPCS_ERRORS=0
PHPCS_FAILED_FILES=""
for FILE in $STAGED_PHP_FILES; do
if [ -f "$FILE" ]; then
# Run phpcbf (it returns 1 if it made changes, 0 if no changes needed)
vendor/bin/phpcbf "$FILE" || true

# Re-run phpcs to check if the file is now clean
if vendor/bin/phpcs --colors "$FILE" 2>&1; then
echo -e "${GREEN}✓ Auto-fixed: $FILE${NC}"
FIXED_FILES="$FIXED_FILES $FILE"
# Stage the fixed file
git add "$FILE"
else
echo -e "${RED}✗ Could not fully fix: $FILE${NC}"
if ! vendor/bin/phpcs --colors "$FILE"; then
PHPCS_FAILED_FILES="$PHPCS_FAILED_FILES $FILE"
HAS_PHPCS_ERRORS=1
fi
fi
done

# Re-check if there are still errors after auto-fixing
HAS_PHPCS_ERRORS=0
for FILE in $STAGED_FILES; do
if [ -f "$FILE" ]; then
vendor/bin/phpcs --colors "$FILE" > /dev/null 2>&1 || HAS_PHPCS_ERRORS=1
# If PHPCS found errors, try to auto-fix them with PHPCBF
if [ $HAS_PHPCS_ERRORS -ne 0 ]; then
echo -e "${YELLOW}PHPCS found errors. Running PHPCBF to auto-fix...${NC}"

FIXED_FILES=""
for FILE in $PHPCS_FAILED_FILES; do
if [ -f "$FILE" ]; then
# Run phpcbf (it returns 1 if it made changes, 0 if no changes needed)
vendor/bin/phpcbf "$FILE" || true

# Re-run phpcs to check if the file is now clean
if vendor/bin/phpcs --colors "$FILE" 2>&1; then
echo -e "${GREEN}✓ Auto-fixed: $FILE${NC}"
FIXED_FILES="$FIXED_FILES $FILE"
# Stage the fixed file
git add "$FILE"
else
echo -e "${RED}✗ Could not fully fix: $FILE${NC}"
fi
fi
done

# Re-check if there are still errors after auto-fixing
HAS_PHPCS_ERRORS=0
for FILE in $STAGED_PHP_FILES; do
if [ -f "$FILE" ]; then
vendor/bin/phpcs --colors "$FILE" > /dev/null 2>&1 || HAS_PHPCS_ERRORS=1
fi
done

if [ $HAS_PHPCS_ERRORS -eq 0 ]; then
echo -e "${GREEN}All PHPCS errors have been auto-fixed!${NC}"
fi
fi

# Run PHPStan on staged files
echo -e "${YELLOW}Running PHPStan...${NC}"
HAS_PHPSTAN_ERRORS=0
PHPSTAN_FILES=""
for FILE in $STAGED_PHP_FILES; do
if [ -f "$FILE" ] && [[ "$FILE" =~ ^inc/ ]]; then
PHPSTAN_FILES="$PHPSTAN_FILES $FILE"
fi
done

if [ $HAS_PHPCS_ERRORS -eq 0 ]; then
echo -e "${GREEN}All PHPCS errors have been auto-fixed!${NC}"
if [ -n "$PHPSTAN_FILES" ]; then
vendor/bin/phpstan analyse --no-progress --error-format=table $PHPSTAN_FILES || HAS_PHPSTAN_ERRORS=1
fi
fi

# Run PHPStan on staged files
echo -e "${YELLOW}Running PHPStan...${NC}"
HAS_PHPSTAN_ERRORS=0
PHPSTAN_FILES=""
for FILE in $STAGED_FILES; do
if [ -f "$FILE" ] && [[ "$FILE" =~ ^inc/ ]]; then
PHPSTAN_FILES="$PHPSTAN_FILES $FILE"
# Track PHP errors
if [ $HAS_PHPCS_ERRORS -ne 0 ] || [ $HAS_PHPSTAN_ERRORS -ne 0 ]; then
HAS_ERRORS=1
if [ $HAS_PHPCS_ERRORS -ne 0 ]; then
echo -e "${YELLOW}Some PHPCS errors could not be auto-fixed. Please fix them manually.${NC}"
echo -e "${YELLOW}Run 'vendor/bin/phpcs' to see remaining errors.${NC}"
fi
fi
done
else
echo -e "${GREEN}No PHP files to check.${NC}"
fi

# =============================================================================
# JS/CSS Checks (ESLint and Stylelint via lint-staged)
# =============================================================================

if [ -n "$PHPSTAN_FILES" ]; then
vendor/bin/phpstan analyse --no-progress --error-format=table $PHPSTAN_FILES || HAS_PHPSTAN_ERRORS=1
# Get list of staged JS/CSS files
STAGED_JS_CSS_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|css)$' | grep -v '\.min\.' || true)

if [ -n "$STAGED_JS_CSS_FILES" ]; then
echo -e "${YELLOW}Checking JS/CSS files:${NC}"
echo "$STAGED_JS_CSS_FILES"

if command -v npx &> /dev/null; then
echo -e "${YELLOW}Running lint-staged...${NC}"
if ! npx lint-staged; then
HAS_ERRORS=1
echo -e "${RED}lint-staged found errors.${NC}"
fi
else
echo -e "${YELLOW}Warning: npx not found. Skipping JS/CSS linting.${NC}"
echo -e "${YELLOW}Run 'npm install' to set up the development environment.${NC}"
fi
else
echo -e "${GREEN}No JS/CSS files to check.${NC}"
fi

# Exit with error if any checks failed
if [ $HAS_PHPCS_ERRORS -ne 0 ] || [ $HAS_PHPSTAN_ERRORS -ne 0 ]; then
# =============================================================================
# Final Result
# =============================================================================

if [ $HAS_ERRORS -ne 0 ]; then
echo -e "${RED}Pre-commit checks failed!${NC}"
if [ $HAS_PHPCS_ERRORS -ne 0 ]; then
echo -e "${YELLOW}Some PHPCS errors could not be auto-fixed. Please fix them manually.${NC}"
echo -e "${YELLOW}Run 'vendor/bin/phpcs' to see remaining errors.${NC}"
fi
echo -e "${YELLOW}To bypass these checks, use: git commit --no-verify${NC}"
exit 1
fi

echo -e "${GREEN}All pre-commit checks passed!${NC}"
exit 0
exit 0
Loading
Loading