You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if [ $flagged_calls -eq 0 ]; then
echo -e "${GREEN}✓ All calls appear to have timeout arguments!${NC}"
exit 0
else
echo -e "${YELLOW}⚠️$flagged_calls call(s) flagged for manual review${NC}"
echo ""
echo "Note: These may be false positives if:"
echo " - Timeout is defined in a constant/method"
echo " - Timeout is set via apply_filters()"
echo " - $args is defined more than $CONTEXT_LINES lines before"
exit 1
fi
Activity
noelsaw1 commentedon Jan 17, 2026
`#!/bin/bash
check-wp-remote-timeout.sh
Detects wp_remote_* calls without timeout arguments
Reduces false positives by checking context (20 lines before call)
Usage: ./check-wp-remote-timeout.sh [directory]
Example: ./check-wp-remote-timeout.sh src/
set -e
Configuration
CONTEXT_LINES=20
TARGET_DIR="${1:-src}"
Colors
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo "🔍 Checking for wp_remote_* calls without timeout..."
echo "Target: $TARGET_DIR"
echo "Context: $CONTEXT_LINES lines before each call"
echo ""
Counters
total_calls=0
flagged_calls=0
Find all PHP files
while IFS= read -r file; do
# Get line numbers of wp_remote_* calls
while IFS=: read -r linenum content; do
[ -z "$linenum" ] && continue
done < <(find "$TARGET_DIR" -name "*.php" -type f 2>/dev/null)
Summary
echo "================================================"
echo "Summary:"
echo " Total wp_remote_* calls found: $total_calls"
echo " Flagged (possible missing timeout): $flagged_calls"
echo ""
if [ $flagged_calls -eq 0 ]; then⚠️ $flagged_calls call(s) flagged for manual review$ {NC}"
echo -e "${GREEN}✓ All calls appear to have timeout arguments!${NC}"
exit 0
else
echo -e "${YELLOW}
echo ""
echo "Note: These may be false positives if:"
echo " - Timeout is defined in a constant/method"
echo " - Timeout is set via apply_filters()"
echo " - $args is defined more than $CONTEXT_LINES lines before"
exit 1
fi
`
noelsaw1 commentedon Jan 17, 2026
GREP Solution for Timeout Detection - Summary
Question: How to reduce false positives when detecting missing
timeoutarguments inwp_remote_*calls where$argsis defined separately?Answer: Use context-aware grep with a 20-line backward window.
The Problem
Simple Grep (Too Many False Positives)
Result: Flags valid code like:
The Solution
Context-Aware Grep (20-line window)
Result: Finds timeout even when defined separately:
Recommended Grep Pattern
One-Liner for Quick Check
Production-Ready Script
See:
PROJECT/4-MISC/check-wp-remote-timeout.shFeatures:
$argsdefinitionsTest Results on This Codebase
Before (Simple Grep)
After (Context-Aware Grep)
Improvement: Reduced false positives by ~30%
Key Patterns Detected
✅ Pattern 1: Inline timeout (Correctly passes)
✅ Pattern 2: Separate $args within 20 lines (Correctly passes)
Detection: Script marks as "Likely OK - uses constant/method"
Detection: Script marks as "Likely OK - uses constant/method"
❌ Pattern 5: Genuinely missing (Correctly flagged)
Integration with WP Code Check
Recommended Approach
Example Output Format
Limitations & Edge Cases
Will Still Flag (False Positives)
Timeout >20 lines before call
Solution: Increase context window or refactor code
Timeout in class constant
Solution: Script marks as "Likely OK"
Timeout in method
Solution: Script marks as "Likely OK"
Will NOT Detect (True Negatives)
Recommendations for WP Code Check
Tier 1: Auto-Flag (High Confidence)
Tier 2: Warn (Medium Confidence)
Tier 3: Info (Low Confidence)
Final Grep Pattern for CI/CD
Conclusion
Best Practice for Reducing False Positives:
self::and$this->patterns (likely OK)Expected Accuracy:
For WP Code Check: Use the context-aware bash script provided. It's the best balance of accuracy vs. complexity for grep-based detection.