Skip to content

Commit 25b9638

Browse files
authored
Workflows
1 parent 717ee9d commit 25b9638

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

.github/workflows/wordpress-plugin-check.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,22 @@ jobs:
416416

417417
- name: Install WordPress Coding Standards
418418
run: |
419+
# Install WordPress Coding Standards globally
419420
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
421+
composer global require "squizlabs/php_codesniffer:*"
420422
composer global require "wp-coding-standards/wpcs:*"
421-
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
423+
composer global require "phpcsstandards/phpcsutils:*"
424+
composer global require "phpcsstandards/phpcsextra:*"
425+
426+
# Set the installed paths for PHPCS
427+
~/.composer/vendor/bin/phpcs --config-set installed_paths ~/.composer/vendor/wp-coding-standards/wpcs,~/.composer/vendor/phpcsstandards/phpcsutils,~/.composer/vendor/phpcsstandards/phpcsextra
428+
429+
# Verify installation
430+
~/.composer/vendor/bin/phpcs -i
422431
423432
- name: Run PHPCS
424433
run: |
425-
phpcs --standard=WordPress --extensions=php --ignore=vendor,tests,node_modules .
434+
~/.composer/vendor/bin/phpcs --standard=WordPress --extensions=php --ignore=vendor,tests,node_modules .
426435
427436
- name: Create issue on PHPCS failure
428437
if: ${{ failure() }}
@@ -530,7 +539,7 @@ jobs:
530539
EOF
531540
532541
- name: Run Psalm
533-
run: ./vendor/bin/psalm --output-format=github
542+
run: ./vendor/bin/psalm --show-info=true
534543

535544
- name: Create issue on Psalm failure
536545
if: ${{ failure() }}

simple-wp-optimizer.php

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ function es_optimizer_render_additional_options($options) {
266266
* - WordPress checked() function is used for checkbox state
267267
*
268268
* @param array $options Plugin options
269-
* @param string $option_name Option name
269+
* @param string $optionName Option name
270270
* @param string $title Option title
271271
* @param string $description Option description
272272
*/
273-
function es_optimizer_render_checkbox_option($options, $option_name, $title, $description) {
273+
function es_optimizer_render_checkbox_option($options, $optionName, $title, $description) {
274274
?>
275275
<tr valign="top">
276276
<th scope="row"><?php
@@ -283,12 +283,12 @@ function es_optimizer_render_checkbox_option($options, $option_name, $title, $de
283283
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
284284
/*
285285
* Using printf with esc_attr for attribute name which cannot be avoided.
286-
* The $option_name values are hardcoded strings from render functions, not user input.
286+
* The $optionName values are hardcoded strings from render functions, not user input.
287287
* This is a controlled environment where these values are defined within the plugin.
288288
*/
289-
printf('es_optimizer_options[%s]', esc_attr($option_name));
289+
printf('es_optimizer_options[%s]', esc_attr($optionName));
290290
?>" value="1"
291-
<?php checked(1, isset($options[$option_name]) ? $options[$option_name] : 0); ?> />
291+
<?php checked(1, isset($options[$optionName]) ? $options[$optionName] : 0); ?> />
292292
<?php
293293
// Using esc_html for secure output of descriptions
294294
echo esc_html( $description );
@@ -308,11 +308,11 @@ function es_optimizer_render_checkbox_option($options, $option_name, $title, $de
308308
* - Textarea content is escaped with esc_textarea()
309309
*
310310
* @param array $options Plugin options
311-
* @param string $option_name Option name
311+
* @param string $optionName Option name
312312
* @param string $title Option title
313313
* @param string $description Option description
314314
*/
315-
function es_optimizer_render_textarea_option($options, $option_name, $title, $description) {
315+
function es_optimizer_render_textarea_option($options, $optionName, $title, $description) {
316316
?>
317317
<tr valign="top">
318318
<th scope="row"><?php
@@ -328,19 +328,19 @@ function es_optimizer_render_textarea_option($options, $option_name, $title, $de
328328
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
329329
/*
330330
* Using printf with esc_attr for attribute name which cannot be avoided.
331-
* The $option_name values are hardcoded strings from render functions, not user input.
331+
* The $optionName values are hardcoded strings from render functions, not user input.
332332
* This is a controlled environment where these values are defined within the plugin.
333333
*/
334-
printf('es_optimizer_options[%s]', esc_attr($option_name));
334+
printf('es_optimizer_options[%s]', esc_attr($optionName));
335335
?>" rows="5" cols="50" class="large-text code"><?php
336-
if (isset($options[$option_name])) {
336+
if (isset($options[$optionName])) {
337337
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
338338
/*
339339
* Using printf with esc_textarea is the most appropriate approach.
340340
* esc_textarea already properly escapes content for use inside textarea elements.
341341
* This function is designed specifically for this purpose and ensures data is properly escaped.
342342
*/
343-
printf('%s', esc_textarea($options[$option_name]));
343+
printf('%s', esc_textarea($options[$optionName]));
344344
}
345345
?></textarea>
346346
</td>
@@ -379,7 +379,7 @@ function es_optimizer_validate_options($input) {
379379
// Validate and sanitize the DNS prefetch domains
380380
if (isset($input['dns_prefetch_domains'])) {
381381
$domains = explode("\n", trim($input['dns_prefetch_domains']));
382-
$sanitized_domains = array();
382+
$sanitizedDomains = array();
383383

384384
foreach ($domains as $domain) {
385385
$domain = trim($domain);
@@ -388,12 +388,12 @@ function es_optimizer_validate_options($input) {
388388
if (filter_var($domain, FILTER_VALIDATE_URL)) {
389389
// Security: Use esc_url_raw to sanitize URLs before storing in database
390390
// This prevents potential security issues with malformed URLs
391-
$sanitized_domains[] = esc_url_raw($domain);
391+
$sanitizedDomains[] = esc_url_raw($domain);
392392
}
393393
}
394394
}
395395

396-
$valid['dns_prefetch_domains'] = implode("\n", $sanitized_domains);
396+
$valid['dns_prefetch_domains'] = implode("\n", $sanitizedDomains);
397397
}
398398

399399
return $valid;
@@ -448,8 +448,8 @@ function es_optimizer_add_settings_link($links) {
448448
// The admin_url function is used to properly generate a URL within the WordPress admin area
449449
// Setting text is wrapped in translation function but doesn't need escaping here
450450
// as WordPress core handles this when rendering plugin links
451-
$settings_link = '<a href="' . admin_url('options-general.php?page=es-optimizer-settings') . '">' . __('Settings', 'Simple-WP-Optimizer') . '</a>';
452-
array_unshift($links, $settings_link);
451+
$settingsLink = '<a href="' . admin_url('options-general.php?page=es-optimizer-settings') . '">' . __('Settings', 'Simple-WP-Optimizer') . '</a>';
452+
array_unshift($links, $settingsLink);
453453
return $links;
454454
}
455455
$plugin = plugin_basename(__FILE__);
@@ -472,13 +472,13 @@ function disable_emojis_tinymce($plugins) {
472472
* Remove emoji CDN hostname from DNS prefetching hints.
473473
*
474474
* @param array $urls URLs to print for resource hints.
475-
* @param string $relation_type The relation type the URLs are printed for.
475+
* @param string $relationType The relation type the URLs are printed for.
476476
* @return array Difference betwen the two arrays.
477477
*/
478-
function disable_emojis_remove_dns_prefetch($urls, $relation_type) {
479-
if ('dns-prefetch' === $relation_type) {
480-
$emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/');
481-
$urls = array_diff($urls, array($emoji_svg_url));
478+
function disable_emojis_remove_dns_prefetch($urls, $relationType) {
479+
if ('dns-prefetch' === $relationType) {
480+
$emojiSvgUrl = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/');
481+
$urls = array_diff($urls, array($emojiSvgUrl));
482482
}
483483
return $urls;
484484
}
@@ -600,7 +600,7 @@ function add_dns_prefetch() {
600600

601601
// Output the prefetch links using WordPress core functions
602602
foreach ($domains as $domain) {
603-
$escaped_domain = esc_url($domain);
603+
$escapedDomain = esc_url($domain);
604604

605605
/*
606606
* Using wp_print_resource_hints with array of sanitized domains would be the ideal approach,
@@ -610,10 +610,11 @@ function add_dns_prefetch() {
610610
*/
611611
if (function_exists('esc_html')) {
612612
echo esc_html("\n");
613-
} else {
614-
echo "\n";
613+
wp_print_link_tag('dns-prefetch', $escapedDomain);
614+
return;
615615
}
616-
wp_print_link_tag('dns-prefetch', $escaped_domain);
616+
echo "\n";
617+
wp_print_link_tag('dns-prefetch', $escapedDomain);
617618
}
618619
}
619620
// Hook after wp_head and before other elements are added

0 commit comments

Comments
 (0)