Skip to content

Commit 89e3eb7

Browse files
authored
Workflows
1 parent a0930ed commit 89e3eb7

File tree

4 files changed

+85
-33
lines changed

4 files changed

+85
-33
lines changed

.github/workflows/php-code-quality.yml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,9 @@ jobs:
4141

4242
- name: Install dependencies
4343
run: |
44-
# First try and handle dependency conflicts
44+
# Install dependencies, always ignoring platform requirements for CI reliability
4545
composer config platform.php ${{ matrix.php-version }}
46-
composer install --prefer-dist --no-progress --no-suggest || {
47-
echo "Standard install failed, trying with --ignore-platform-reqs"
48-
composer install --prefer-dist --no-progress --no-suggest --ignore-platform-reqs
49-
}
46+
composer install --prefer-dist --no-progress --no-suggest --ignore-platform-reqs
5047
5148
# Verify installation was successful
5249
if [ ! -d "vendor" ]; then
@@ -106,25 +103,19 @@ jobs:
106103
run: |
107104
echo "Checking for text argument escaping issues..."
108105
109-
# Find PHP files with potential escaping issues
110-
FILES_WITH_ESCAPING_ISSUES=$(grep -r --include="*.php" -l "esc_html\s*(" --exclude-dir={vendor,node_modules,tests} . || echo "")
106+
# Find PHP files with potential escaping issues (echo with variables not wrapped in esc_html)
107+
FILES_WITH_ESCAPING_ISSUES=$(grep -r --include="*.php" -l 'echo ".*\$' --exclude-dir={vendor,node_modules,tests} . || echo "")
111108
112109
if [ -n "$FILES_WITH_ESCAPING_ISSUES" ]; then
113110
echo "Found potential escaping issues in the following files:"
114111
echo "$FILES_WITH_ESCAPING_ISSUES"
115112
116113
# Find problematic patterns and fix them
117114
for FILE in $FILES_WITH_ESCAPING_ISSUES; do
118-
echo "Checking $FILE for esc_html issues..."
115+
echo "Checking $FILE for escaping issues..."
119116
120-
# Replace direct variable escaping with proper string handling
121-
# Example: esc_html($variable) → esc_html('Static text') or properly concat strings
122-
123-
# This is a basic search/replace - more complex patterns might need manual fixes
124-
sed -i 's/esc_html(\s*\$[a-zA-Z0-9_]*\s*)/esc_html__( \0, "simple-wp-optimizer" )/g' "$FILE" || true
125-
126-
# Also check for other escaping functions
127-
sed -i 's/esc_attr(\s*\$[a-zA-Z0-9_]*\s*)/esc_attr__( \0, "simple-wp-optimizer" )/g' "$FILE" || true
117+
# Replace direct echo of strings with variables to use esc_html
118+
sed -i 's/echo "\(.*\)\$\([a-zA-Z0-9_]*\)\(.*\)";/if (function_exists('\''esc_html'\'')) { echo esc_html("\1$\2\3"); } else { echo "\1$\2\3"; }/g' "$FILE" || true
128119
129120
echo "Applied basic fixes to $FILE"
130121
done
@@ -164,3 +155,5 @@ jobs:
164155
# Commit and push changes
165156
git commit -m "Auto-fix code style issues with PHPCBF [standard: $STANDARD] [skip ci]" || true
166157
git push || echo "Failed to push changes, but workflow will continue"
158+
git commit -m "Auto-fix code style issues with PHPCBF [standard: $STANDARD] [skip ci]" || true
159+
git push || echo "Failed to push changes, but workflow will continue"

run-phpunit.php

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,39 @@
1515

1616
// Detect PHP version
1717
$php_version = phpversion();
18+
1819
$php_major_version = (int)explode('.', $php_version)[0];
1920
$php_minor_version = (int)explode('.', explode('.', $php_version)[1])[0];
2021

21-
echo "PHP Version: $php_version\n";
22+
if (function_exists('esc_html')) {
23+
echo esc_html("PHP Version: $php_version") . "\n";
24+
} else {
25+
echo "PHP Version: $php_version\n";
26+
}
2227

2328
// Define the path to the PHPUnit executable
2429
$phpunit_path = __DIR__ . '/vendor/bin/phpunit';
2530

2631
if (!file_exists($phpunit_path)) {
27-
echo "Error: PHPUnit not found at $phpunit_path\n";
28-
echo "Please run 'composer install' first.\n";
32+
if (function_exists('esc_html')) {
33+
echo esc_html("Error: PHPUnit not found at $phpunit_path") . "\n";
34+
echo esc_html("Please run 'composer install' first.") . "\n";
35+
} else {
36+
echo "Error: PHPUnit not found at $phpunit_path\n";
37+
echo "Please run 'composer install' first.\n";
38+
}
2939
exit(1);
3040
}
3141

3242
// Get the PHPUnit version
3343
$phpunit_version_output = shell_exec("$phpunit_path --version");
3444
preg_match('/PHPUnit\s+([0-9]+\.[0-9]+)/', $phpunit_version_output, $matches);
3545
$phpunit_version = isset($matches[1]) ? $matches[1] : 'unknown';
36-
echo "PHPUnit Version: $phpunit_version\n";
46+
if (function_exists('esc_html')) {
47+
echo esc_html("PHPUnit Version: $phpunit_version") . "\n";
48+
} else {
49+
echo "PHPUnit Version: $phpunit_version\n";
50+
}
3751

3852
// Build the command arguments
3953
$args = $_SERVER['argv'];
@@ -44,41 +58,73 @@
4458

4559
// PHP 8.x specific settings
4660
if ($php_major_version >= 8) {
47-
echo "Running in PHP 8.x compatibility mode\n";
61+
if (function_exists('esc_html')) {
62+
echo esc_html("Running in PHP 8.x compatibility mode") . "\n";
63+
} else {
64+
echo "Running in PHP 8.x compatibility mode\n";
65+
}
4866

4967
// For PHP 8.3 and 8.4, use PHPUnit 10+ with specific settings
5068
if ($php_major_version == 8 && ($php_minor_version >= 3)) {
51-
echo "Using PHP 8.3+ with PHPUnit requires special handling\n";
69+
if (function_exists('esc_html')) {
70+
echo esc_html("Using PHP 8.3+ with PHPUnit requires special handling") . "\n";
71+
} else {
72+
echo "Using PHP 8.3+ with PHPUnit requires special handling\n";
73+
}
5274

5375
// Add any PHP 8.3/8.4 specific flags
5476
$default_args[] = '--no-deprecations';
5577

5678
// For PHPUnit 10+
5779
if (version_compare($phpunit_version, '10.0', '>=')) {
58-
echo "Using PHPUnit 10+ with PHP 8.3+\n";
80+
if (function_exists('esc_html')) {
81+
echo esc_html("Using PHPUnit 10+ with PHP 8.3+") . "\n";
82+
} else {
83+
echo "Using PHPUnit 10+ with PHP 8.3+\n";
84+
}
5985
// No special settings needed for PHPUnit 10+
6086
} else {
61-
echo "Warning: Using older PHPUnit with PHP 8.3+, some features may not work correctly\n";
87+
if (function_exists('esc_html')) {
88+
echo esc_html("Warning: Using older PHPUnit with PHP 8.3+, some features may not work correctly") . "\n";
89+
} else {
90+
echo "Warning: Using older PHPUnit with PHP 8.3+, some features may not work correctly\n";
91+
}
6292
}
6393
}
6494
// For PHP 8.0-8.2 (using PHPUnit 9.x typically)
6595
elseif ($php_minor_version >= 0 && $php_minor_version <= 2) {
66-
echo "Using PHP 8.0-8.2 with appropriate PHPUnit version\n";
96+
if (function_exists('esc_html')) {
97+
echo esc_html("Using PHP 8.0-8.2 with appropriate PHPUnit version") . "\n";
98+
} else {
99+
echo "Using PHP 8.0-8.2 with appropriate PHPUnit version\n";
100+
}
67101

68102
// If using older PHPUnit with PHP 8.x
69103
if (version_compare($phpunit_version, '9.0', '<')) {
70-
echo "Using PHPUnit < 9.0 with PHP 8.x requires special handling\n";
104+
if (function_exists('esc_html')) {
105+
echo esc_html("Using PHPUnit < 9.0 with PHP 8.x requires special handling") . "\n";
106+
} else {
107+
echo "Using PHPUnit < 9.0 with PHP 8.x requires special handling\n";
108+
}
71109

72110
// Load the compatibility layer first
73111
if (file_exists(__DIR__ . '/tests/php8-compatibility.php')) {
74-
echo "Loading PHP 8.x compatibility layer\n";
112+
if (function_exists('esc_html')) {
113+
echo esc_html("Loading PHP 8.x compatibility layer") . "\n";
114+
} else {
115+
echo "Loading PHP 8.x compatibility layer\n";
116+
}
75117
require_once __DIR__ . '/tests/php8-compatibility.php';
76118
}
77119

78120
// Use custom error settings
79121
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED & ~E_STRICT);
80122
} else {
81-
echo "Using PHPUnit 9.x with PHP 8.0-8.2\n";
123+
if (function_exists('esc_html')) {
124+
echo esc_html("Using PHPUnit 9.x with PHP 8.0-8.2") . "\n";
125+
} else {
126+
echo "Using PHPUnit 9.x with PHP 8.0-8.2\n";
127+
}
82128
}
83129
}
84130
}
@@ -87,8 +133,13 @@
87133
$command = escapeshellcmd($phpunit_path);
88134
$command .= ' ' . implode(' ', array_map('escapeshellarg', array_merge($default_args, $args)));
89135

90-
echo "Running command: $command\n";
91-
echo "-----------------------------------------------------------\n";
136+
if (function_exists('esc_html')) {
137+
echo esc_html("Running command: $command") . "\n";
138+
echo esc_html("-----------------------------------------------------------") . "\n";
139+
} else {
140+
echo "Running command: $command\n";
141+
echo "-----------------------------------------------------------\n";
142+
}
92143

93144
// Execute PHPUnit with the arguments
94145
passthru($command, $return_var);

simple-wp-optimizer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,11 @@ function add_dns_prefetch() {
607607
* WordPress core doesn't have a direct function for outputting single dns-prefetch tags,
608608
* so we need to construct it ourselves.
609609
*/
610-
echo "\n";
610+
if (function_exists('esc_html')) {
611+
echo esc_html("\n");
612+
} else {
613+
echo "\n";
614+
}
611615
wp_print_link_tag('dns-prefetch', $escaped_domain);
612616
}
613617
}

tests/bootstrap.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// Load PHP 8.x compatibility helper first
99
if (file_exists(__DIR__ . '/php8-compatibility.php')) {
10-
require_once __DIR__ . '/php8-compatibility.php';
10+
require_once __DIR__ . '/php8-compatibility.php';
1111
}
1212

1313
$_tests_dir = getenv( 'WP_TESTS_DIR' );
@@ -17,7 +17,11 @@
1717
}
1818

1919
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
20-
echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL;
20+
if (function_exists('esc_html')) {
21+
echo esc_html("Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?") . PHP_EOL;
22+
} else {
23+
echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL;
24+
}
2125
exit( 1 );
2226
}
2327

0 commit comments

Comments
 (0)