Skip to content

Commit 770663e

Browse files
authored
Workflows
1 parent 89e3eb7 commit 770663e

File tree

5 files changed

+65
-23
lines changed

5 files changed

+65
-23
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
9999
# Run the actual compatibility check
100100
vendor/bin/phpcs --standard=PHPCompatibilityWP --extensions=php --ignore=vendor/,node_modules/ --runtime-set testVersion 7.4-8.4 .
101-
101+
102102
- name: Fix text argument escaping issues
103103
run: |
104104
echo "Checking for text argument escaping issues..."
@@ -117,7 +117,13 @@ jobs:
117117
# Replace direct echo of strings with variables to use esc_html
118118
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
119119
120-
echo "Applied basic fixes to $FILE"
120+
# Also fix single quoted strings
121+
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
122+
123+
# Fix multi-line echo statements
124+
sed -i 's/echo \("\|\x27\)\(.*\)\$\([a-zA-Z0-9_]*\)\(.*\)\("\|\x27\) \. \("\|\x27\)\(.*\)\("\|\x27\);/if (function_exists('\''esc_html'\'')) { echo esc_html(\1\2$\3\4\5 . \6\7\8); } else { echo \1\2$\3\4\5 . \6\7\8; }/g' "$FILE" || true
125+
126+
echo "Applied escaping fixes to $FILE"
121127
done
122128
else
123129
echo "No obvious text argument escaping issues found."
@@ -155,5 +161,3 @@ jobs:
155161
# Commit and push changes
156162
git commit -m "Auto-fix code style issues with PHPCBF [standard: $STANDARD] [skip ci]" || true
157163
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"

phpcs.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WordPress Plugin Coding Standards">
3+
<description>WordPress Plugin Coding Standards for Simple WP Optimizer</description>
4+
5+
<!-- Include WordPress Core -->
6+
<rule ref="WordPress-Core">
7+
<!-- Exclude specific rules if needed -->
8+
</rule>
9+
10+
<!-- Include WordPress Security rules -->
11+
<rule ref="WordPress.Security.EscapeOutput">
12+
<properties>
13+
<property name="customEscapingFunctions" type="array">
14+
<element value="wp_kses_post" />
15+
<element value="esc_html" />
16+
<element value="esc_attr" />
17+
<element value="esc_url" />
18+
</property>
19+
</properties>
20+
</rule>
21+
22+
<!-- Include WordPress Sanitization rules -->
23+
<rule ref="WordPress.Security.ValidatedSanitizedInput" />
24+
25+
<!-- PHP compatibility checks -->
26+
<rule ref="PHPCompatibilityWP" />
27+
28+
<!-- Files to check -->
29+
<arg name="extensions" value="php" />
30+
<arg name="basepath" value="./" />
31+
<arg name="colors" />
32+
<arg value="sp" />
33+
34+
<!-- Paths to check -->
35+
<file>.</file>
36+
37+
<!-- Exclude directories -->
38+
<exclude-pattern>/vendor/*</exclude-pattern>
39+
<exclude-pattern>/node_modules/*</exclude-pattern>
40+
<exclude-pattern>/tests/bootstrap.php</exclude-pattern>
41+
</ruleset>

run-phpunit.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
}
6666

6767
// For PHP 8.3 and 8.4, use PHPUnit 10+ with specific settings
68-
if ($php_major_version == 8 && ($php_minor_version >= 3)) {
68+
if (8 === $php_major_version && ($php_minor_version >= 3)) {
6969
if (function_exists('esc_html')) {
7070
echo esc_html("Using PHP 8.3+ with PHPUnit requires special handling") . "\n";
7171
} else {
@@ -91,6 +91,7 @@
9191
}
9292
}
9393
}
94+
9495
// For PHP 8.0-8.2 (using PHPUnit 9.x typically)
9596
elseif ($php_minor_version >= 0 && $php_minor_version <= 2) {
9697
if (function_exists('esc_html')) {
@@ -130,7 +131,7 @@
130131
}
131132

132133
// Build the command
133-
$command = escapeshellcmd($phpunit_path);
134+
$command = escapeshellcmd($phpunit_path);
134135
$command .= ' ' . implode(' ', array_map('escapeshellarg', array_merge($default_args, $args)));
135136

136137
if (function_exists('esc_html')) {
@@ -145,4 +146,4 @@
145146
passthru($command, $return_var);
146147

147148
// Return the same exit code as PHPUnit
148-
exit($return_var);
149+
exit((int) $return_var);

simple-wp-optimizer.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,8 @@ function es_optimizer_render_checkbox_option($options, $option_name, $title, $de
269269
?>
270270
<tr valign="top">
271271
<th scope="row"><?php
272-
// Using esc_html_e for internationalization and secure output of titles
273-
// This properly escapes the output while also supporting translations
274-
esc_html_e($title, 'simple-wp-optimizer-enginescript');
272+
// Using esc_html for secure output of titles
273+
echo esc_html( $title );
275274
?></th>
276275
<td>
277276
<label>
@@ -286,9 +285,8 @@ function es_optimizer_render_checkbox_option($options, $option_name, $title, $de
286285
?>" value="1"
287286
<?php checked(1, isset($options[$option_name]) ? $options[$option_name] : 0); ?> />
288287
<?php
289-
// Using esc_html_e for internationalization and secure output of descriptions
290-
// This ensures the text is properly escaped while supporting translations
291-
esc_html_e($description, 'simple-wp-optimizer-enginescript');
288+
// Using esc_html for secure output of descriptions
289+
echo esc_html( $description );
292290
?>
293291
</label>
294292
</td>
@@ -313,15 +311,13 @@ function es_optimizer_render_textarea_option($options, $option_name, $title, $de
313311
?>
314312
<tr valign="top">
315313
<th scope="row"><?php
316-
// Using esc_html_e for internationalization and secure output of titles
317-
// This properly escapes the output while also supporting translations
318-
esc_html_e($title, 'simple-wp-optimizer-enginescript');
314+
// Using esc_html for secure output of titles
315+
echo esc_html( $title );
319316
?></th>
320317
<td>
321318
<p><small><?php
322-
// Using esc_html_e for internationalization and secure output of descriptions
323-
// This ensures the text is properly escaped while supporting translations
324-
esc_html_e($description, 'simple-wp-optimizer-enginescript');
319+
// Using esc_html for secure output of descriptions
320+
echo esc_html( $description );
325321
?></small></p>
326322
<textarea name="<?php
327323
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
@@ -475,7 +471,7 @@ function disable_emojis_tinymce($plugins) {
475471
* @return array Difference betwen the two arrays.
476472
*/
477473
function disable_emojis_remove_dns_prefetch($urls, $relation_type) {
478-
if ('dns-prefetch' == $relation_type) {
474+
if ('dns-prefetch' === $relation_type) {
479475
$emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/');
480476
$urls = array_diff($urls, array($emoji_svg_url));
481477
}
@@ -500,7 +496,7 @@ function remove_jquery_migrate($scripts) {
500496
}
501497

502498
if (!is_admin() && isset($scripts->registered['jquery'])) {
503-
$script = $scripts->registered['jquery'];
499+
$script = $scripts->registered['jquery'];
504500

505501
// Remove jquery-migrate from jquery dependencies
506502
if ($script->deps) {

tests/php8-compatibility.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
// Detect PHP version
12-
$php_version = phpversion();
12+
$php_version = phpversion();
1313
$php_major_version = (int)explode('.', $php_version)[0];
1414

1515
// Only apply fixes for PHP 8.x
@@ -18,7 +18,7 @@
1818

1919
// Check if we're running PHPUnit 7.x on PHP 8.x (problematic combination)
2020
if (class_exists('\PHPUnit\Runner\Version')) {
21-
$phpunit_version = \PHPUnit\Runner\Version::id();
21+
$phpunit_version = \PHPUnit\Runner\Version::id();
2222
$phpunit_major_version = (int)explode('.', $phpunit_version)[0];
2323

2424
// PHPUnit 7.x with PHP 8.x needs special handling

0 commit comments

Comments
 (0)